Python's pre-declared constants are kinda weird

(sebsite.pw)

67 points | by rbanffy 1 hour ago

6 comments

  • zahlman 42 minutes ago
    Past: https://news.ycombinator.com/item?id=49284392 (with my comment), https://news.ycombinator.com/item?id=49250370 .

    Nice to see it get attention this time.

  • neillyons 8 minutes ago
    I remember reading that in early versions of Python there was no built in True and False. Each user would implement this themselves as

    True = 1

    False = 0

    then later these got added to the language. In Python 2 you could still reassign and swap them so that 'if False' was actually true!

    True, False = False, True

    Python 3 you could no longer reassign them.

  • nneonneo 12 minutes ago
    The __debug__ constant is really weird - any block of code guarded with `if __debug__:` will be entirely omitted from the bytecode under PYTHONOPTIMIZE=1. This and `assert` are the only two examples of real “conditional compilation” in Python. This is also the reason why you cannot assign to __debug__: doing so would make it possible to invalidate the compiler’s assumption about `if __debug__:` statements.
    • plant-ian 6 minutes ago
      I honestly have never even heard of this constant and I feel like I've been using python for a pretty long time. Although maybe my memory for some things just gets garbage collected if I don't use it enough. Does it actually get used that often in real world code? Seems like it might be kind of risky.
  • xg15 59 minutes ago
    Isn't "..." then also behaving like True, False and None, i.e. being a lexical token that rewolves to a hardwired value during parsing?
    • zahlman 29 minutes ago
      It is, but Ellipsis is just an ordinary pre-defined constant (with the same value).
  • jMyles 9 minutes ago
    I made a constant library for python which I liked some years ago. I wonder if any of my ideas made it in:

    https://github.com/nucypher/constantSorrow/blob/master/tests...

  • echelon 41 minutes ago
    I used to like Python in the 2010s when it felt like a breath of fresh air relative to PHP and Perl.

    Now it feels like a weird PHP itself that is slow, brittle, and dangerous to write code at scale in.

    The loose typing, potluck standard library, and horrible package manager (insofar as the community does not know how to package code) all feel so dated.

    • plant-ian 9 minutes ago
      I felt the same way about moving to Python versus PHP and Perl.

      I still really enjoy using python though. It's not really a fair comparison because I hadn't used PHP and Perl for as long but I just don't hit some mystifying issue every single session like I did with those languages when I'm using python. I honestly have never even read about that __debug__ constant. It's fun to hear about it but it's just not something that's comes up much.

    • datakan 36 minutes ago
      It is 30+ years old with all the baggage you would expect. It’s very much a product of its time.
      • 9dev 24 minutes ago
        It’s not like that cannot be changed. Look at PHP, which managed to evolve brilliantly over the last decade and gets tons of things right now.
      • randallsquared 12 minutes ago
        Python 3(000) was an opportunity to fix all the things, so in a sense, the modern Python is less than 20 years old.
    • KK7NIL 24 minutes ago
      Python certainly has some baggage, especially the typing system (which is still not finished, if you're looking at static typing and so is implemented differently by type checkers) and pip's safety, or lack thereof. But comparing it to PHP or Perl is rhetoric leading you one step too far.
      • fugigigjfn 12 minutes ago
        Comparing it with PHP is unfair… to PHP. The amount of hard work that the PHP community has done to advance and keep their language relevant is impressive and admirable, and Python is perhaps the most extreme counterexample there is.

        The Python community has spent the last 15 years refusing to improve in any meaningful way, or to learn anything from their peers. As someone who used to choose only jobs that would let me work with Python, I’ve gone through every phase of grief, and now just try to forget that it exists.

    • adamddev1 15 minutes ago
      I don't understand how people talk about how Python is "easy to learn for beginners" or "easy to understand." To me it's so hard to remember and follow all the weirdness. Racket / Scheme / I dare say even Haskell would just be so much simpler for learners.

      I'm with Conal Elliot when he said on Type Theory for All that it is sooo much harder to understand a program in Python.

    • irishcoffee 9 minutes ago
      I feel the same way. It was, back then “the second best language for everything, the first best at nothing”

      Can’t take credit for the quote, read it somewhere.

      The whole language changed when they kicked what’s-his-name out, and it’s a tool I almost never reach for anymore, whereas 15 years ago it was my Swiss Army knife.

    • slopinthebag 13 minutes ago
      Who cares tho. The agents deal with all of that, if you’re still looking at the code or caring about anything other than the loops and orbs you’re at the wrong level of abstraction. The important thing is the models have tons of python in their training data.
      • SCUSKU 8 minutes ago
        I've heard of orbs but what is it actually?