5 ms·
Somehow, Go managed to not break old code and also fix the problem. I think this is a good case of Python not fixing things, given that a fix exists that solve
by sneak 3y ago
Somehow, Go managed to not break old code and also fix the problem.
I think this is a good case of Python not fixing things, given that a fix exists that solves both problems.
- pcl 3y ago> To ensure backwards compatibility with existing code, the new semantics will only apply in packages contained in modules that declare go 1.22 or later in their go.mod files.
- nerdponx 3y agoRight, and Go has the luxury of being a compiler that generates reasonably portable binaries, while Python requires the presence of an interpreter on the system at run time.
- josephg 3y agoThe same trick would work with python just as well. There’s nothing about Python’s status as an interpreter which would stop them from adding a python semantic version somewhere in each python program - either in a comment at the top of each source file or in an adjacent config file. The comment could specify the version of python’s semantics to use, which would allow people to opt in to new syntax (or opt out of changes which may break the code in the future). Eg # py 3.4
- Cthulhu_ 3y agoYeah, it would just mean that the interpreter - just like the Go compiler - would need to have the equivalent of "if version > 3.4 do this, else do that". Which is fine for a while, but I can imagine it adds a lot of complexity and edge cases to the interpreter / compiler. Which makes me think that a Go 2.0 or Python 4 will mainly be about removing branches and edge cases from the compiler more than making backwards-incompatible language changes.
- josephg 3y agoThis is the direction multiple languages are moving in. Go and Rust both have something like this. (In Rust they're called "editions"). I think its inevitable that compilers get larger over time. I hope most of the time they aren't too onerous to maintain - there aren't that many spec breaking changes between versions. But if need be, I could also imagine the compiler eventually deprecating old versions if it becomes too much of an issue. Arguably C & C++ compilers do the same thing via -std=c99 and similar flags at compile time. Anyway, nothing about this is special or different with python. I bet the transition to python 3 would have been much smoother if scripts could have opted in (or opted out) of the new syntax without breaking compatibility.
- lloeki 3y ago> Python requires the presence of an interpreter on the system at run time. A runtime interpreter does not prevent Perl to do similar things via `use 5.13` Python has `from future` with similar abilities, it would absolutely be possible to do the same as Perl and Go and fix what needs to be fixed without breaking old code. One could design a `import 3.22` and `from 3.22 import unbroken_for` and achieve the same thing.
- IshKebab 3y agoPython could very easily have a similar mechanism. Hell even CMake manages to do this right, and they got "if" wrong. The Python devs sometimes seem stubbornly attached to bugs. Another one: to reliably get Python 3 on Linux and Mac you have to run `python3`. But on Windows there's no `python3.exe`. Will they add one? Hell no. It might confuse people or something. Except... if you install Python from the Microsoft Store it does have `python3.exe`.
- wrboyce 3y agoI’ve not run “python3” in years on my Mac, and I’m almost certain I never type it into Linux machines either; either I’m losing my mind, or there are some ludicrous takes in this thread.
- rat9988 3y agoYou are surely losing your mind then. Python3 isn't something esoteric.
- wrboyce 3y agoEntirely possible, but my point was I just type “python” and Python 3 happens. Do modern OS even come with Python 2 anymore? I’m not claiming any mystery about Python, just disputing how the modern version is invoked.
- erik_seaberg 3y ago13.5.2 has /usr/bin/python3 (it’s 3.9.6) but not python2 or just python. Not sure when they changed, and YMMV with Homebrew.
- lmm 3y ago> I just type “python” and Python 3 happens. That was the old way. Python now recommends against installing Python3 in a way that does that, and most modern *nix don't.
- 3y ago
- wrboyce 3y agoBy letting you specify a language version requirement? Not exactly backwards compatible (because it is explicitly not, as per the article). Python doesn’t make breaking changes in non-major versions, so as mentioned by the upthread comment the appropriate place for this change would be in Python 4. Given the above, I’m really not sure what point you think you’re making in that final paragraph.
- carbotaniuman 3y agoThis seems weird to given the number of breakages and standard library changes I seem to run into every version.
- wrboyce 3y agoReally? I find that surprising. I don’t write as much code as I used to but I’ve been writing Python for a long time and the only standard library breakages that come to mind were during the infamous 2 -> 3 days. What sort of problems are have you faced upgrading minor versions?
- orbisvicis 3y agoThe docs are full of remarks like "removed in 3.0 and reintroduced in 3.4" or "deprecated in 3.10", etc. A big one is the removal of the loop parameter in asyncio, but a lot of asyncio internals are (still?) undergoing significant changes, as getting the shutdown behavior correct is surprisingly difficult. Personally it's never cause me any issues - I'm always on board with the changes.
- nerdponx 3y agoAsyncio was explicitly marked as provisional for years and most of the incompatible changes happened during that time. Same goes for typing. The rest of the language is very very stable.
- nayuki 3y agoOne of the few that I remember is fractions.gcd() -> math.gcd(). See https://docs.python.org/3.0/library/fractions.html#fractions.gcd https://docs.python.org/3.0/library/fractions.html#fractions... , https://docs.python.org/3.5/library/fractions.html#fractions.gcd https://docs.python.org/3.5/library/fractions.html#fractions... , https://docs.python.org/3.9/library/fractions.html https://docs.python.org/3.9/library/fractions.html (gone), https://docs.python.org/3.5/library/math.html#math.gcd https://docs.python.org/3.5/library/math.html#math.gcd
- kazinator 3y agoIf the change /doesn't/ break old code, it's also poorly justified. It means code doesn't care about the issue being addressed. The feature is only justified if it changes existing code, such that bugs you didn't even know about are fixed. I.e. people read about the issue, investigate their code bases and go, oh hey, we actually have a latent bug here which the change will fix.
- esrauch 3y agoNew code written today will use the new version and have the correct behavior from day 1. Old code that is maintained will eventually be upgraded, which yes does come with work sometimes where you realize your code works on version X but not version X+10 and you do a combination of tests and reading patch notes to see what changed.
- kazinator 3y agoThere is no "correct" behavior here; either one is a valid choice that can be documented and that programs can rely on and exploit. Code doesn't care about when it's written, only what you run it on, and with what compatibility options. E.g. one possibility is that ten-year-old code that wrongly assumed the opposite behavior, and has a bug, will start to work correctly on the altered implementation.
- jjnoakes 3y agoThere's a second motivation in my opinion. Code might work today without the change, but it could be because the author originally wrote buggy code, caught it in testing, and had to waste time tracking it down and understanding nuances that don't need to be there. Once they figured that out, they implemented an ugly workaround (adding an extra function parameter to a goroutine or shadowing the loop variable with n := n). Good language designers want to avoid both wasting developer's time and requiring ugly workarounds. Making a change that does both, especially if it doesn't break old code, is great imo.
- kazinator 3y ago
- baq 3y agoPython probably could change this with a from __future__ import, i.e. in the same way.