beagle3 2 days ago

It is not an optimization ; it changes program semantics - converts programs that will run out of stack eventually regardless of the amount of available memory (and raise exceptions an the process, for example, which a program might rely on. Either way, semantics are changed)

It should only be called Tail Call Elimination.

  • dragonwriter 2 days ago

    By that standard, any optimization that changes scaling in any dimension changes semantics, which, well, I’m not saying its wrong, but I would say it is exactly what people looking for optimization want.

    • beagle3 2 days ago

      I disagree.

      An optimization that speeds a program by x2 has the same effect as running on a faster CPU. An optimization that packs things tighter into memory has the same effect as using more memory.

      Program semantics are usually referred to as “all output given all input, for any input configuration” but ignoring memory use or CPU time, provided they are both finite (but not limited).

      TCE easily converts a program that will halt, regardless of available memory, to one that will never halt, regardless of available memory. That’s a big change in both theoretical and practical semantics.

      I probably won’t argue that a change that reduces an O(n^5) space/time requirement to an O(1) requirement is a change in semantics, even though it practically is a huge change. But TCE changes a most basic property of a finite memory Turing machine (halts or not).

      We don’t have infinite memory Turing machines.

      edited: Turing machine -> finite memory Turing machine.

      • coldtea 2 days ago

        >I probably won’t argue that a change that reduces an O(n^5) space/time requirement to an O(1) requirement is a change in semantics, even though it practically is a huge change

        Space/time requirements aren't language semantics though, are they?

    • dataflow 2 days ago

      > By that standard, any optimization that changes scaling in any dimension changes semantics

      That doesn't follow. This isn't like going from driving a car to flying an airplane. It's like going from driving a car to just teleporting instantly. (Except it's about space rather than time.)

      It's a difference in degree (optimization), yes, but by a factor of infinity (O(n) overhead to 0 overhead). At that point it's not unreasonable to consider it a difference in kind (semantics).

      • tomsmeding 2 days ago

        Modern C compilers are able to transform something like this:

        for (int i = 0; i < n; i++) a += i;

        To:

        a += n * (n+1) / 2;

        Is this an optimisation or a change in program semantics? I've never heard anyone call it anything slse than an optimisation.

    • rat87 a day ago

      The important thing is whether theres a garuntee of it happening in particular circumstance or not. Like with python referencing counting theoretically finalizers should be called after you lose all references to a file (assuming no cycles) but you cant rely on it.

      Python dicts were in insert sort order for 3.6 but this only became a garuntee as opposed to an implementation choice that could be changed at anyvtime with python3.7

  • flakes 2 days ago

    > converts programs that will run out of stack eventually regardless of the amount of available memory (and raise exceptions an the process, for example, which a program might rely on

    https://xkcd.com/1172/

rpcope1 2 days ago

That's probably one of the more frustrating things about Python. Each release it gets all sorts of questionable new syntax (including the very strange pattern matching "feature" that kind of sucks compared to something like Erlang or Scala), but we never get real useful quality of life improvements for basic functional programming like TCO or multi line lambdas

  • throwaway81523 2 days ago

    Python has always been unashamedly imperative, with some functional features entering by slipping through the cracks. The pattern matching thing seemed ok to me when I tried it, but I haven't used it except briefly, since I'm still mostly on Python 3.9. Interestingly, Python has been losing users to Rust. I don't entirely understand that, other than everyone saying how Rust's tooling is so much better.

    • flakes 2 days ago

      > Python has been losing users to Rust. I don't entirely understand that, other than everyone saying how Rust's tooling is so much better.

      Not to rust, but to Go and C++ for myself. The biggest motivating factor is deployment ease. It is so difficult to offer a nice client install process when large virtual environments are involved. Static executables solve so many painpoints for me in this arena. Rust would probably shine here as well.

      If its for some internal bespoke process, I do enjoy using Python. For tooling shipped to client environments, I now tend to steer clear of it.

      • sieve 2 days ago

        > For tooling shipped to client environments, I now tend to steer clear of it.

        A guy on r/WritingWithAI is building a new writing assistant tool using python and pyQt. He is not a SE by trade. Even so, the installation instructions are:

        - Install Python from the Windows app store

        - Windows + R -> cmd -> pip install ...

        - Then run python main.py

        This is fine for technical people. Not regular folks.

        For most people, these incantations to be typed as-is in a black window mean nothing and it is a terrible way of delivering a piece of software to the end-user.

      • pjmlp 2 days ago

        As someone that always kept a foot on C++ land, dispite mostly working on managed languages, I would that by C++17 (moreso now in C++23), dispite all its quirks and warts, C++ has become good enough that I can write Python like code with it.

        Maybe it is only a thing to those of us already damaged with C++, and with enough years experience using it, but there are still plenty of such folks around to matter, specially to GPU vendors, and compiler writers.

    • mikepurvis 2 days ago

      I'm largely still a Python user, but when I've used it, rust overall gross way more thoughtfully and consistently designed— both in the core language features and in the stdlib.

      Python's thirty years of evolution really shows at this point.

    • coldtea 2 days ago

      >Python has been losing users to Rust

      Not really.

  • dragonwriter 2 days ago

    > we never get real useful quality of life improvements for basic functional programming like TCO or multi line lambdas

    A lambda can be as big of an expression as you want, including spanning multiple lines; it can't (because it is an expression) include statements, which is only different than lambdas in most functional languages in that Python actually has statements.

    • kqr 2 days ago

      > most functional languages

      Most popular functional languages I can think of except maybe Haskell has statements!

  • pinoy420 2 days ago

    The choice of “unique” verbs is weird too. Case match. Try except?

    • maleldil 2 days ago

      `match/case` looks absolutely fine to me. What's the problem?

      `try/except` is definitely weird, though.

  • jgalt212 2 days ago

    The utility value of multi-line lambdas is real, but the readability of these is terrible. And Python prizes readability. So you know where this initiative will end up.

    • saagarjha 2 days ago

      Nothing more readable than a triply-nested list comprehension on an object that exists only to vend its __getattr__ for some unholy DSL

      • pinoy420 2 days ago

        Annoying. Because it “compiles” to less optimal code than writing it explicitly.

    • vrighter 2 days ago

      I personally find python to be highly UNreadable, especially with all of its syntax and braindead scoping rules

ehsankia 2 days ago

Guido is no longer BDFL though, it's the steering committee that decides.

  • thunkingdeep 2 days ago

    Ah, you’re correct. My comment was mainly meant as a tongue in cheek remark to point out that this definition of tailcall is wholly separate from Python function objects and merely an implementation detail.

  • riffraff 2 days ago

    the steering committee seems way less conservative than Guido, right?

    Looking at python from the outside a lot of changes since GvR stepped down seem like stuff he'd not have been fond of.

    • kqr 2 days ago

      I think this is a change longer in the making than that. Back when I started working with Python in the mid--late 2000s, the Zen was holy and it seemed very unlikely to ever see multiple ways to do "one thing".

      The Python community has since matured and realised that what they previously thought of as "one thing" were actually multiple different things with small nuances and it makes sense to support several of them for different use cases.

      • guappa 2 days ago

        One way to do the things. That's why there's 5000 ways to install a module.

      • riffraff 2 days ago

        You may be right. I checked and found the introduction of the ternary expression, which I found to be wildly "unpythonic", was back in 2006. Time flies.

    • pansa2 2 days ago

      Any examples? The biggest change since Guido stepped down has been the addition of pattern matching, which he was strongly in favour of.

      Moreover, Guido is in favour of ongoing addition of major new features (like pattern matching), worrying that without them Python would become a “legacy language”:

      https://discuss.python.org/t/pep-8012-frequently-asked-quest...

      • riffraff 2 days ago

        I was thinking of the walrus operator, various f-string changes, relenting on the "GIL removal must not cost performance" stance (although"covered" by other improvements), things like that.

        I don't follow python closely so it may 100% be stuff that GvR endorsed too, or I'm mixing up the timelines. It just feels to me that python is changing much faster than it did in the 2.x days.

      • pinoy420 2 days ago

        Pattern matching seems like a cool feature that was added just because it was cool. I think the syntax is really odd too - apparently to “be pythonic”. I really see no use for it other than to “look smart”. The fact that case match (switch case is a much better description) is expanded to practically a huge if else is disturbing. Similarly the walrus operator. Other than an answer to “what is a new feature of python that you like” interview trivia question, really, who has actually used it?