Live data from Hacker News

Python's pre-declared constants are kinda weird

sebsite.pw

191–200 of 234 posts

Re: Python's pre-declared constants are kinda weird

#191
post #152

Earlier quoted context omitted.

Haskell, Lean, and Agda too. But even if Python were the only one, it wouldn't be weird to someone for whom this was their first programming language. It would just seem the way programming languages are. There's nothing intrinsically weird about indentation being significant. It's quite visibly part of the code you write and read.

> There's nothing intrinsically weird about indentation being significant. It's quite visibly part of the code you write and read. The idea is fine, I guess, although I certainly don't care for it. Where it gets most nasty is that whitespace that looks the same (in your editor) might not be equal and will cause you pain.

> Where it gets most nasty is that whitespace that looks the same (in your editor) might not be equal and will cause you pain.

First off, what editor could I end up using in 2026 that makes this a realistic problem? Even the most basic editors I know of have options to convert tabs to spaces automatically (and any responsible teacher will tell the student to indent with spaces), and to continue the previous line's indentation automatically.

Second, modern Python is stricter about this, and also gives clear error messages.

Re: Python's pre-declared constants are kinda weird

#192
post #5

Earlier quoted context omitted.

It is 30+ years old with all the baggage you would expect. It’s very much a product of its time.

Python 3(000) was an opportunity to fix all the things, so in a sense, the modern Python is less than 20 years old.

They didn't fix nearly enough, and then everyone complained about too much being fixed, and acted like twelve years wasn't enough time to adapt.

Re: Python's pre-declared constants are kinda weird

#193

Earlier quoted context omitted.

> I think that this is a capture problem not a variable problem. The closure should always do the right thing and capture the value of all variables (not just ones inside the loop), instead of capturing the reference to the variables. Now your "lalanthran closures" can't mutate the world because they work exclusively with copies not references, if they try to mutate something then whatever they're touching was just a…

> Now your "lalanthran closures" can't mutate the world because they work exclusively with copies not references, if they try to mutate something then whatever they're touching was just a copy not the real thing. That is true. I still don't like the idea of "Here is a general rule. It applies everywhere but $HERE." Whether that general rule is "All captures are by value" or "All captures are by reference", the rule s…

> the rule should not have exceptions based on context in the code.

But the rules didn't and still don't have any such exceptions.

> A better tradeoff would be to have the general rule (whatever it is) apply everywhere, along with syntax for capturing (or not, depending what the default is)

This "solution" is how it works in C++. We can thus castigate the programmer for writing the wrong runes in their captures list and never for a moment doubt that we got it right when we introduced so very many footguns...

Tony Hoare's observation applies "One way is to make the program so simple, there are obviously no errors. The other is to make it so complicated, there are no obvious errors."

> An alternative viewpoint is that many languages have immutable variables and they seem to be getting along just fine without needing mutation on variables, shared or otherwise.

Sure, and one of the astonishing things in C# or Go before they fixed this is that you can indeed have immutable variables which change, even though that's silly - the language can decide that you mustn't change Goose, but it doesn't need to obey its own rules because it will change it for each loop iteration.

Re: Python's pre-declared constants are kinda weird

#194
post #72
post #48

Earlier quoted context omitted.

I can understand that "advanced" python programs may be difficult to understand for beginners (lots of implicit/hidden behaviors, possibility to change basically everything one should expect, etc). But to _learn_ programming, I really, really don't see how using Haskell would be simpler than Python. Perhaps if you have a specific background (e.g., math), but else python is almost pseudo code already. You'll really ha…

Haskell’s hard to interpret error messages alone disqualify it from being a beginner language. Python: errors based on incorrect indentation (many beginners don’t use nice IDEs), or don’t understand the meaning of the hints) and scope (don’t forget your “global” if you’re hacking in PyGame) are challenges.

> many beginners don’t use nice IDEs

Starting with 3.13, even the REPL is a sufficiently nice IDE to avoid any careless indentation errors from poor formatting (as opposed to ones caused by actually not understanding how many levels of indentation the current line of code should have).

Re: Python's pre-declared constants are kinda weird

#195
post #173
post #168

Earlier quoted context omitted.

Show me a language that old without lots of cruft. The worst thing you can find is the standard library, which is just an unsolvable problem.

That's my point. PHP is still an old language with lots of "baggage", just like python is an old language with lots of "baggage".

Just like C# has baggage. Or R has. Or Go, to some extent. This is a non-sequitur.

Re: Python's pre-declared constants are kinda weird

#196
post #138

Earlier quoted context omitted.

Pattern matching? Nice, I'd managed to miss that one completely, as well as the fact that Python had introduced dictionary-merging (according to a quick search, Python 3.9 introduced the | (pipe) operator for dict unions). I did know about the others you mentioned, but couldn't call them to mind when writing my comment. But reading through a Python script that I had Claude Code write for me taught me another one: app…

Yes, that's a Path object from pathlib. It has been around for while but likely still qualifies, site says from 3.4.

You are both focusing on Python improving in any way but the person you're responding to said "improve in any meaningful way, or to learn anything from their peers"

Which I will say is overstated but I can see where they are coming from even when you bring into scope things like types, async, etc.

First types. This is what the type hints in Python allow you to do:

  def foo(x: int) -> int:
      return x

  foo("hello")
We can say that this is great Python has type hints, but at the same time the lesson they learned is wrong because the feature to have isn't type hints but actually enforcing them so the above code cannot be written. In my eye, this is an anti-feature.

Second async, this is also the wrong lesson to have learned from other languages. Adding async/await is a bandaid over the problem that the synchronous imperative model clashes with asynchronous distributed semantics. The async/await keyword are a way to try to bridge between the two, but it creates a "function coloring" problem that all these languages which added async/await have.

The lesson Python should have learned is to not add these keywords and go back to its glue language root, allowing actually natively asynchronous languages to coordinate asynchronous processes, while Python code handles the synchronous core. Python doesn't have to be everything, the wrong lesson was to try to be the one language to rule them all.

You also brought up the packaging improvements, which I feel were the wrong lesson learned. The problem with the Python packaging ecosystem is well known since it's been expressed in the XKCD comic. The lesson from other languages is: one blessed compiler toolchain integrated into the packaging story makes for a better user experience. This is the npm, cargo lesson. For Python to really learn it, uv or equivalent would be the blessed way of managing Python projects. Instead it's still a very fragmented landscape with many competing solutions, which goes against Python's own zen.

Moving on to pattern matching, again I feel the wrong lesson was learned. Pattern matching is a feature from the functional paradigm that in my opinion became more popular with developers when they became exposed to it in Rust, and so Python joined in and added the feature as well. But the reason it's such a nice feature in Rust is because it will refuse to compile any code that does not do exhaustive matching on all variants. This is great because it catches problems early and forces you to consider the non happy path where things can error. So pattern matching alone isn't the feature it's pattern matching PLUS structured Enums and exhaustive patterns.

So in Python you can do this:

  x = 3

  match x:
      case 1:
          print("one")
      case 2:
          print("two")

  print("done")
Output will be "done" rather than an error on the match, which is what should happen if they had learned the right lesson, because without exhaustive matching this is no better than an if or switch. Again I consider this an anti-feature -- better to not have at all if it doesn't work as expected.

Anyway, I'm not trying to say Python is bad, I'm just saying I get where the other poster is coming from when they say Python has refused to learn the right lessons. Although I would not agree they haven't improved a lot over 15 years.

Re: Python's pre-declared constants are kinda weird

#197
post #32

Earlier quoted context omitted.

Misery is trying to retrofit "bool", True/False, and nil/null to a language. C had to do that. Python had to do that. Getting those wrong is one of the classic language design mistakes. It seems like treating "True" as a value that equates to 1 will work, but then the special cases get you. Like being able to perform arithmetic on True. Common language design boners: - Not building in strings. That's now in the past.…

You list a few absences but absences aren't the end of the world, I say it's worse when designers make a booboo where the language semantics are wrong. In C++ there are so many of these it's not sporting but a recurring example from the garbage collected languages would be the for-each loop mistake. Several times now†, people make a language where the way a for-each loop (for each Goose in Geese ...) works is that th…

[deleted]

Re: Python's pre-declared constants are kinda weird

#198

Python is awful. There are so many one offs in libraries, none agree on a style, it’s slow, and it’s way too easy to do the wrong thing. I often work with data scientists and have to productionize their jupyter notebooks which is pure suboptimal hell. I guess it must be a good easy learning curve for research/scratchpad

Python is a language for "consenting adults". It doesn't try to prevent you from doing awful things so you can do great things. People who can't program well are given plenty of rope to hang themselves. It shares that with Perl and Ruby. That said, I find it the nicest, cleanest option of the three. I still wouldn't use it for large and complex projects. I really like it for stuff where one might otherwise use shells…

If that's the case maybe we should stop teaching it to kids?

Re: Python's pre-declared constants are kinda weird

#199

Python is just such a weird language in general despite its popularity that I honestly cannot recommend anyone who starts programming to choose Python as their first language, contrary to popular sentiments. I mean, I was one of the first person to start using Python when I was in grad school almost a decade ago when everybody else in my field was still using Matlab for their lab code, for the simply reason that Nump…

> and then you'll have to deal with all of its weirdness: significant whitespace By "weirdness" here you apparently mean not having to worry about matching up curly braces, and getting what you want automatically just for indenting your code the way you're supposed to indent it anyway... ? > truthiness Which is different from how it works in other similar languages, how exactly? > duck typing Which is weird, how exac…

> Which is different from how it works in other similar languages, how exactly?

They are contrasting with languages where true is true and 1 is 1; but true is not 1, and 1 is not true.

> Which is weird, how exactly?

Sometimes if it looks like a duck and quacks like a duck it can still not be a duck.

> You can go a lot further than five minutes in Python without having to worry about threads at all

Unless you specifically want to do multithreading.

> the worst thing the GIL does is deny you the multi-core processing you thought you were going to get.

That is the worst thing because I wanted that multi-core processing, that's the whole reason I wanted to do multithreading.

Re: Python's pre-declared constants are kinda weird

#200
post #53

Earlier quoted context omitted.

I don't. I have no interest in trying to assign a value to something that's built-in and not meant to be written to. Like who fucking cares that the boolean constants are actually weird little structure that sometimes let you mess with them and other times your edits are ignored? Maybe this is helpful for writing an entry for an obfuscated code challenge but I'm not doing weird shit like that with the code I expect t…

Please. Such a charged response wasn’t justified at all. Different people are curious about different things. You ask “who fucking cares?”. The answer? You don’t, and the person you’re replying to does.

You're right, I was feeling a little salty
Post reply on HN