Hacker News new | ask | show | jobs
by tvelichkov 2441 days ago
Well the zen of python also states:

- Complex is better than complicated.

Using the walrus operator makes the code more complex, but less complicated.

2 comments

I vehemently disagree - these walrus vars are still in scope outside of the condition block. And on top of that, now there are special conditions for these walrus vars which are completely not obvious.

Reference: https://www.python.org/dev/peps/pep-0572/#scope-of-the-targe...

It also states one line before:

> Simple is better than complex.

I understand that nobody will force me to use this feature, but as I said before, even the spec and the write up tells how this feature is confusing and .. complex.

> It also states one line before

I know and I believe there is a purpose to be exactly after that line. Writing only simple code is not enough. If you write everything in a simple manner your code will most likely be complicated, that's exactly why you have next - complex is better than complicated.

I see this feature the same way as comprehensions, scary and complex at first, but once you learn it you would wish anyone would use it.