5 ms·
> 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 f
by ebg13 7y 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 7y 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 7y 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 7y 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 7y 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 7y 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 7y 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?