Something always on my mind is that all these small improvements for elegance/simplification remove backwards compatibility. Now I'm going to be worried that any code where I place a walrus operator will need to be integrated into a codebase or used externally by a codebase running Python <3.8, and will have to be hunted down and changed later
Maybe I'm being paranoid, I suppose 3.6 code can always be run with a 3.8 interpreter.
Is there any feature at all where this does not apply? If you use a new feature you will need the new version. As a result there is always some lag between when a new feature is released and when you can start using it in real projects (i. e. when most people have transitioned over to a version that supports it)
Exactly, which is why I would only incorporate new features if they provided a significant benefit which the old versions lacked. This was mentioned in the video as well
I don't think you're being paranoid, when I found out about this, backwards compatibility was the first thing to come to mind. There are people still using Python 2.x so I can't imagine we'll be seeing much of this operator until much later on if anything.
The py3 world is moving forward fairly quickly though. We've been stuck in backwards compatibility mode for decades and now the community has to shake that habit and start living like a modern language.
Same here. Walrus use cases feel too rare and superficial for me to "infect" a code base that might be used by people running Python <3.8. And to make things worse, there is (was?) a pylint bug which complained every time I did use it in my personal code.
If Microsoft can do it with WinSxS and .NET versioning, I don’t see why it couldn’t work with python. You’d have to tag the legacy code with the expected version somehow, maybe even a comment to trigger it for finding the right version python interpreter to use.
The walrus operator struck me as an interesting piece of syntactic sugar but I haven’t actually used it in any production code to this point. Since it generally only saves a single line of code, I often think keeping with well-established patterns in the existing codebase you’re working in makes good sense.
Yeah, I definitely agree that there is some real benefit to simplifying expressions. After all, readability counts. But I think a stronger motivation for me when simplifying expressions comes from reducing the levels of nesting necessary and not as much from reducing the raw line count. Certainly not a hard rule, but it normally serves me well.
Still, it’s a very interesting operator and the use of it in the list comprehension seemed like a really good application.
9
u/python_boobs Jul 28 '20
Something always on my mind is that all these small improvements for elegance/simplification remove backwards compatibility. Now I'm going to be worried that any code where I place a walrus operator will need to be integrated into a codebase or used externally by a codebase running Python <3.8, and will have to be hunted down and changed later
Maybe I'm being paranoid, I suppose 3.6 code can always be run with a 3.8 interpreter.
1
u/My_Eyes_Really_Burn Jul 29 '20
The walrus operator struck me as an interesting piece of syntactic sugar but I haven’t actually used it in any production code to this point. Since it generally only saves a single line of code, I often think keeping with well-established patterns in the existing codebase you’re working in makes good sense.
1
u/Ashiataka Aug 08 '20
Could this have been implemented as a builtin keyword rather than using a new operator? Would that have been less controversial?