Hacker News new | ask | show | jobs
by jasonrhaas 2535 days 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.

4 comments

This 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-...

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.

I 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.
The 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.
> while evaluating it for truthiness

no, it evaluates to the left side's value after assignment

Well, yes, that's right: the return value of an assignment expression is the left side's value, which is what makes the assignment/evaluation work.
>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".