The most controversial Python feature | Walrus operator

preview_player
Показать описание
The walrus operator := and assignment expressions, PEP 572, was opposed by majority of Python core developers, and led Guido van Rossum to step down from BDFL role.

LINKS:

OUTLINE:
0:00 - Walrus operator
1:26 - Use cases
3:33 - Criticisms
5:59 - Guido van Rossum
Рекомендации по теме
Комментарии
Автор

The walrus operator := and assignment expressions, PEP 572, was opposed by majority of Python core developers, and led Guido van Rossum to step down from BDFL role. Here's the outline for the video:
0:00 - Walrus operator
1:26 - Use cases
3:33 - Criticisms
5:59 - Guido van Rossum

lexfridman
Автор

I don't think for a second this was worth losing Guido for, projects like this are super hard to guide and this guy did it for decades.

wilsonmura
Автор

I guess people had to find something to fight about in a language that has no braces and standardized indentation...

wajideus
Автор

He sounds like he's 50% high and 50% given up on life.

SanchitSnehashish
Автор

Me as a C++ Dev: *overloads operator= to do whatever I feel like making it do*

Python Devs: *unintelligible, angry swearing*

keris
Автор

Who would win:

Decades long leader of one of the worlds most broadly utilized programming projects

One tusky boi :=

usd
Автор

Someone needs to make a "This := kills benevolent dictators." sticker.

yesterdaysguy
Автор

The := operator should not be criticized for its similarity to the = operator in C.

In C, the = operator is error prone because occasionally the == operator is mistyped as =. If the left side is assignable, it compiles--as it is valid syntax--hiding the error until run-time. When used properly, it still provides the same elegance you mention.

The := operator would not have this issue, since the == operator should not be mistyped as :=.

Derek
Автор

Funny how python has “There should only be one obvious way to do it” and Perl was “There is always more than one way to do it”

trkrjdo
Автор

Every time I hear about Python drama, I am reminded that I am too freakin' old for this crap. Have I been bitten by the = vs == typo, sure, all the time. Do I think it's worth implementing "walrus" syntax to avoid that error ? Sure, go right ahead and make my life easier. This doesn't even break legacy code, so it's a freebie in my book.

But do I think it should have been such a huge source of drama ? Hell no. If people are butthurt because this breaks away from C conventions, to those people I say "go use C then". A skilled programmer should use the best tools available to them, not lament the fact that a screwdriver is not a drill press. Python is supposed to be an easy and versatile scripting language, and this kind of syntactic sugar is one of the many ways in which it fulfills that mandate.

BillLambert
Автор

It can be useful for jupyter too where usually the last thing you want to do in a cell is both to assign a variable and show its value.

ZimoNitrome
Автор

I think it's still important to point out that after Guido stepped down as BDFL the core developers voted to create an elected steering council of I think 5 people to together take up his role in the future and Guido was voted as one of the members. The quote at the end makes it sound like he abandoned the core devs and left them in chaos ^^

I'm not up to date on the current situation but I believe the members are voted in for a fixed period of time or something and Guido said he won't be a member the next time (or he might already not be anymore) but it has been a while so I might be misremembering or this might be out of date info.

vader
Автор

Having no Python experience, this seems like a very useful operator. Java and C# have something similar that i abuse constantly.

snappybean
Автор

I think we will have to see how it ends up used in practice. My main concern is how it might impact readability. It's not something that should be sacrificed for brevity of the code.

Lethoras
Автор

I had never heard of that operator being called a "walrus operator" before. Hilarious!

AlonzoTG
Автор

The Walrus operator is mostly common in languages like Go Lang to initiate a variable, and then if you want to change the value of the variable later you use the equal sign

unlockwithjsr
Автор

The Universe can be described as a never-ending struggle between habit and novelty.

YouuRayy
Автор

Personally, I'm not sure how I feel about this. I may not code in Python, but I think lambda expressions in java would be somewhat comparable to this. Not in functionality, but in similarity to the effect on code. Whenever I find code written by a previous team on my project, they abused the shit out of lambda expressions, just to "reduce lines" of code. They had multiple nesting lambdas together. Sure it made it 'smaller', but it also made the code absolutely hell to read. A for loop would have been bigger, but has greater readability potential. But the main issue is that they didn't use lambdas very well. They didn't use the right tool for the job, and used it just for the sake of doing it.
So the walrus operator reminds me of this. I probably wouldn't use it, but I don't think it should be a problem that it exists in the code. Many who opposed it probably won't use it. Those who are knowledgeable will probably use it right. And those who don't use it right will pay the price.... hopefully.

I guess that's where some of the concern lies. When other devs have to clean up someone else's mess.

Side note: thanks Lex for showing this. I had seen/used this operator when making AutoHotKey scripts, but didn't know what it was called lol.

MetalMario
Автор

So this isn’t about The Life of Brian?

schinaro
Автор

He sounds so sad in this video. Like almost crying

michael