4 ms·
The walrus operator does not feel like Python to me. I'm not a big fan of these types of one liner statements where one line is doing more than one thing. It
by jasonrhaas 7y ago
The walrus operator does not feel like Python to me. I'm not a big fan of these types of one liner statements where one line is doing more than one thing.
It violates the philosophies of Python and UNIX where one function, or one line, should preferably only do one thing, and do it well.
I get the idea behind the :=, but I do think it's an unnecessary addition to Python.
- andrewf 7y agoThis has never felt like a Pythonic principle to me. Python has always seemed like a high-level language that enables dense code. Look at the docs for list comprehensions! https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions https://docs.python.org/2/tutorial/datastructures.html#list-... A lot of folks see Go as a Python successor which surprises me because I don't think the languages favor the same things at all. Maybe my perspective is weird.
- jstimpfle 7y agoI support your view, but want to make you aware that early unix did favour a little cleverness to reduce line counts (and even character counts). C's normal assignment operator does what python's walrus does, for example. Or look at pre/post increment/decrement operators. Or look at languages like sed, or bc, they try to be terse over anything else.
- coldtea 7y ago>It violates the philosophies of Python and UNIX where one function, or one line, should preferably only do one thing, and do it well. Python never had that philosophy... You might confused it with "there should be one, and preferably only one, obvious way to do anything".
- fatbird 7y agoThe unix philosophy of simplicity was on a per tool basis, not function or line of code. The walrus operator is Python version of what we can do now in C or in JS, doing plain assignment in an expression while evaluating it for truthiness. And more often than not, the point of that single-purposeness in Unix is so you can chain a bunch of piped commands that result in a perl-like spaghetti command that's three terminal widths long.