18 ms·
As a developer who has primarily developed applications in Python for his entire professional career, I can't say I'm especially excited about any of the "headl
by CivBase 7y ago
As a developer who has primarily developed applications in Python for his entire professional career, I can't say I'm especially excited about any of the "headlining" features of 3.8.
The "walrus operator" will occasionally be useful, but I doubt I will find many effective uses for it. Same with the forced positional/keyword arguments and the "self-documenting" f-string expressions. Even when they have a use, it's usually just to save one line of code or a few extra characters.
The labeled breaks and continues proposed in PEP-3136 [0] also wouldn't be used very frequently, but they would at least eliminate multiple lines of code and reduce complexity.
PEP-3136 was rejected because "code so complicated to
require this feature is very rare". I can understand a stance like that. Over complicating a language with rarely-used features can definitely create problems. I just don't see why the three "headline" features I mentioned are any different.
[0]: https://www.python.org/dev/peps/pep-3136/ https://www.python.org/dev/peps/pep-3136/
- ageofwant 7y agoI take this as a positive sign of Python's maturity.
- smitty1e 7y ago. . .and the threat of Just Another Vict'ry Announcement (JAVA) as the need to add "sizzle" to the next version looms.
- chooseaname 7y agoRock and a hard place, no? Either you keep adding to a language and people keep using it, or you stop adding to a language and people call it a dead language and stop using it. Most devs don't understand that software can be done and still be useful.
- eru 7y agoWell, you could also try to remove from the language. Like how they removed the `print` keyword when going from Python 2 to Python 3. But removing is harder than adding.
- chooseaname 7y agoRight. Maybe I should have said, "... keep changing a language..."
- egdod 7y agoMature languages don’t introduce random new ugly syntax. I miss Guido already.
- seunosewa 7y agoActually, Guido approved the walrus operator. (In response to the justified backlash, instead of canceling the feature, he resigned as BDFL, which is not what anyone wanted)
- egdod 7y agoI stand corrected.
- coldtea 7y agoGuido fought to have the "random new ugly syntax" (which is anything bad) included.
- kolinko 7y agoI actually found an immense use for Walrus - used it to hack Python into doing pattern matching that is way more readable than without it: https://github.com/eveem-org/panoramix https://github.com/eveem-org/panoramix (source code for Eveem.org, which is arguably the best decompiler for Ethereum smart contracts out there. you can see a lot of pattern matching in pano/simplify.py , and I found no way to do it without extending the language/walrus while maintaining the readability)
- gizmo385 7y agoAfter a quick read through, I personally find this syntax much harder to read using operator overloads than it would have been using a series of comparison functions. Tilde is a very obtuse operator and I don't know that this really buys you anything. Feels like a case of preferring cleverness over readability/usability/maintainability.
- mark-r 7y agoExactly the road C++ tries to go down. How's that for a ringing endorsement?
- wolco 7y agoC++ is one of the most successful languages.
- nine_k 7y agoDespite its flaws, not due to them. Same can be said about e.g. Cobol.
- eru 7y agoDespite the flaws, and because of being in the right place at the right time. Cobol also was a good idea back in the day. And some of the ideas in Cobol we know recognize as bad _had_ to be tried to gain that recognition.
- peterwwillis 7y agoPerl devs have been using the walrus expression for decades, but we just called it "assigning a variable with local scope in an expression". $ perl $a = "foo"; if ( my $a = "bar" ) { print "$a\n" } print "$a\n" bar foo
- geofft 7y agoYup, C and many other languages also have it: if (ptr = strchr(address, ':')) port = atoi(ptr + 1);
- iso-8859-1 7y agoIt doesn't do scoping, so not really the same.
- gpderetta 7y agoit can in C++ (when specifying auto or a type). I thought it did in C as well, but apparently not.
- takeda 7y agoThe reason why assignment expressions initially were not allowed in Python and why they had to introduce "walrus" was because in languages that used single equal sign for assignment enable to easily make bugs by typing "=" instead of "==".
- deleted 7y ago
- thayne 7y agoThere have been many times when I've wished python had something like the walrus operator. In particular, without the walrus operator you can't write an if-elif chain of regex comparisons. The best way to that that I've been able to find is with a bunch of nested if-else statements.
- Sean1708 7y agoAnd working with queues/stacks is much more pleasant (which I seem to do a lot...).
- geofft 7y ago> The "walrus operator" will occasionally be useful, but I doubt I will find many effective uses for it. The primary one I want is if m := re.match(...): print(m.group(1)) and while s := network_service.read(): process(s) both of which are both clearer and less error-prone than their non-walrus variants. The other one that I would have found useful an hour ago is in interactive exploration with comprehensions. I frequently take a look at some data with [i for i in data if i[something].something...], and being able to quickly give a name to something in my conditional, as in {i: x for i in data if x := i[something]}, helps maintain the focus on data and not syntax. Obviously it will get rewritten to have clearer variable names, at the least, when it gets committed as real code, and almost certainly rewritten to be a normal non-comprehension for loop. Like comprehensions, I expect the walrus operator to be valuable when used occasionally, and annoying if overused. There's no real language-level solution to bad taste. In Python 3 you can now do [print(i) for i in...], and I occasionally do at the REPL, but you shouldn't do it in real code and that's not an argument against the language supporting comprehensions.
- drdaeman 7y agoComing from Perl, I used to want this badly, but then I thought that there's absolutely nothing wrong with m = re.match(...) if m is not None: pass Now, I wonder what you meant saying that single-line version is less error-prone, because I don't think so. I believe they're exactly the same in this regard, except for a bizarre case when someone would bastardize the code by putting some irrelevant lines between the assignment and the comparison, obfuscating the logic. Also, as I tend to use `if m is not None:` rather than just `if m:` (because I typically don't want to run all that subtle `__nonzero__` magic), it would - subjectively - look less pretty in the one-line version: `if (m := re.match(...)) is not None:`. Use in the generator expressions to create aliases/shortcuts and avoid repetition is great, though. I love this use case.
- 3PS 7y agoThe issue, in my opinion, is when you want something like this: while m := f(many, args): # do stuff with m Now, if you're writing this in Python 3.7, you often end up with some code duplication: m = f(many, args) while m: # do stuff with m m = f(many, args) # duplicate Or something like this: while True: m = f(many, args) if not m: break # do stuff with m Personally, I consider the last version to be the most elegant, but still something of an anti-pattern. So I welcome this new operator.
- paulddraper 7y ago> As a developer who has primarily developed applications in Python for his entire professional career, I can't say I'm especially excited about any of the "headlining" features of 3.8. Python is a fairly old, mature language. What features would you have been especially excited about?
- CivBase 7y agoThe f-strings from 3.6 are a (relatively) recent feature that I have absolutely loved. I'd go so far as to say they are my favorite feature introduced by Python 3. I'm also looking forward to PEP-554 [0], which allows for "subinterpreters" for running concurrent code without removing the GIL or incurring the overhead of subprocesses. [0] https://www.python.org/dev/peps/pep-0554/ https://www.python.org/dev/peps/pep-0554/
- enriquto 7y agof-strings are great. Much nicer than ".format". I hope in a next iteration of the language all strings will be f-strings by default, avoiding the need to prefix them by a silly "f".
- rolux 7y agoThat would of course be an absolute disaster, given that any user input could easily leak internal state and/or break your program.
- enriquto 7y agoI meant for inline strings (i.e., typed by the programmer). This is an inoffensive change. The only possible ``accident'' is when the programmer wants to write "{x}" instead of the value of x. This is such and exceptional case that it may be best treated by forcing to escape the curly brackets. If anything, user-input strings must be treated as tainted whatever the case.
- 7y ago
- emmelaich 7y agoAs someone who has used Python for over 10 years and C, Perl, etc for over 20, I've been craving the walrus operator forever. I love the walrus operator with a love that is unholy.
- m463 7y agoI wonder what you think of "for else" loops. (although I think "else" should have been a different keyword)
- dagw 7y agoNot OP, but I've probably used them 2 or 3 times in the past decade or so and each time it made for a nice solution to the problem I was facing.
- tripzilch 7y agoEvery time I come across a use case when the "for else" construct would be applicable, I decide against using it just because the "else" keyword is just very unintuitive to people not familiar with this rarely used construct ... so yeah, I too wish it was a different keyword :)
- m463 7y agomaybe we will get "The 3to4 tool will automatically adapt regretfully-named-keywords when converting your sources to Python 4."
- kccqzy 7y agoPEP-3136 was proposed and discussed more than 10 years ago in the 2->3 process. The python community was very different then. As an example, Python 3 was also the language that removed the function argument tuple packing, to which my reaction is basically WTF.
- heavenlyblue 7y agoIs WTF related to the point of efficiency or some esoteric semantics?
- Iv 7y agoNot all releases have to be ground breaking, especially in a mature and stable language. Cleaning up things, putting other things in place for major releases, that's commendable too. I did not follow all the conversation around the typing system but isn't the whole point of it to propose optimizations in the future? I find it exciting
- wodenokoto 7y ago> Same with the forced positional/keyword arguments I also thought, why bother at first until I learned this is already a feature in python, but only for c-functions. So of course it makes sense to level the playing field.
- trymas 7y agoIMHO walrus operator goes against the zen of python. https://www.python.org/dev/peps/pep-0572/#differences-between-assignment-expressions-and-assignment-statements https://www.python.org/dev/peps/pep-0572/#differences-betwee... https://www.python.org/dev/peps/pep-0572/#relative-precedence-of https://www.python.org/dev/peps/pep-0572/#relative-precedenc... Even examples of the spec shows how unintuitive and "unpythonic" this is. Explicit is better than implicit. IMHO adding features to the language to save 1 line of code for 10% of cases when you need it (I agree that there's occasional case when walrus will save you more than 1 line) is just bloat. I am not a big proponent of Go, because it has its own flaws, though language is indeed very simple and creators of the language try to leave it simple. IMO Python was very readable, super simple, intuitive and should stay that way, though recent releases show that Python is giving in for the feature bloat. EDIT: > Try to limit use of the walrus operator to clean cases that reduce complexity and improve readability. Facepalm.
- bouncing 7y agoI've been using Python since 1.5 and I feel like the language itself has been feature-complete for some time. In the 2.0 era, the big pain points were async and unicode; as demonstrated by, well, how painful Twisted's unicode was. ;) But now if our big paint point is assigning a variable to len(), then in two lines evaluating that variable and printing it out, Python is just trying to find stuff to add. I miss the size and simplicity of old Python. :/
- newen 7y agoYeah. I don't like this obsession that so many developers have with adding features without end. I think it's mostly so that they can have something to do; don't think about the bigger problems, just have something to do so that they can fill out their timesheets and submit it at the end of the week.
- tvelichkov 7y agoWell the zen of python also states: - Complex is better than complicated. Using the walrus operator makes the code more complex, but less complicated.
- afiori 7y agoIn my opinion it was a mistake to reject the labelled break PEP
- cutler 7y agoSo Python is finally waking-up to the advantage of everything being an expression as in Ruby and Clojure.
- thanatropism 7y ago> Over complicating a language with rarely-used features can definitely create problems. Agreed. There's a number of (full) languages that compile to the Python AST [0] (I'm especially fond of http://hylang.org http://hylang.org), but they're very different from Python. It would be interesting to see smaller variations of standard Python implemented in an interoperable way like these languages do. [0] https://github.com/vindarel/languages-that-compile-to-python https://github.com/vindarel/languages-that-compile-to-python
- madhadron 7y agoThe audit hooks are going to allow some really interesting things, especially around security controls on executing Python code. There is hope for sandboxed Python execution!