5 ms·
I don't like the walrus operator.
by poooogles 6y ago
I don't like the walrus operator.
- KMnO4 6y agoI don’t either, but thankfully it’s not forced syntax. If you prefer “print x” to “print(x)” you’re OOL in 3.x.
- deleted 6y ago[deleted]
- ebg13 6y ago> If you prefer “print x” to “print(x)” you’re... ...wrong, and probably also mythical. There's no excuse for having it as a language directive rather than a function call. I don't believe that any human who's spent even a few seconds thinking about it actually prefers the former over the latter.
- jimmaswell 6y agoPython 2 was my first language and I've spent years stewing over this horrible change. I just don't bother much with python now. It's supposed to be a convenient, quick language for scripting. There was no good reason to force some academic consistency on the print call. It's extra keystrokes for no reason. It makes me sick every time I have to use the parentheses.
- daeken 6y agoI do. There's a huge advantage that print as a construct has: print >>fp, ... Yes, you can do the same thing with a kwarg on the print function, but it goes at the end of the line and ends up substantially messier in practice. This is the #1 reason that I still write Python 2 every single day; it makes a huge difference for code generation tasks.
- ptx 6y agoGood point about the old syntax putting the file at the start rather than the end, but if you have a lot of code like that you could just do this: p = partial(print, file=fp) p("foo") p("bar")
- daeken 6y agoUnfortunately, that only solves the case of printing strings with newlines, not the case where I might want to continue the line with a space instead, where I'd normally just add "," at the end and call it good. There are absolutely ways around their poor decision, but at the end of the day, the print function instead of statement is a bad fit for some use cases.
- ptx 6y agoWhile it's nice to get rid of the weird special-case syntax and to be able to call print in expressions, I do prefer the old print statement syntactically (even after several seconds of thought) because it's easier to type. Maybe in Python 4 we can have Nim's approach[1] (allowing both) and another decade of arguing about it. [1] https://nim-lang.org/docs/manual.html#procedures-command-invocation-syntax https://nim-lang.org/docs/manual.html#procedures-command-inv...
- RMPR 6y agoI can definitely see this working, but one thing that come up to me is how to manage multi-lines f-strings using that syntax?
- conradludgate 6y agoThen don't use it? I'm not sure why python 3 having assignment expressions in a non breaking way would bother you. I'm not a python dev btw. I've mostly used go/rust/swift where assignment expressions are a big thing so I am a bit biased
- qwerty456127 6y agoI believe that was a joke. I mean he can actually dislike the operator but I'm sure he knows he doesn't have to use it and it also isn't what makes Python 3 different from Python 2 - it just has been added (in 12 years since Python 3.0 release) and nobody uses it in production at the moment anyway.
- leadingthenet 6y agoI use it in prod.
- darkerside 6y agoThis is a bit unfair. If your language adopts a new feature, others on your team are likely to start using it even if you don't. You're allowed to feel a way about it. FTR, I could care less about the walrus operator.