[Tutor] Appropriate use of assignment expression

Alan Gauld alan.gauld at yahoo.co.uk
Sat Nov 20 12:01:07 EST 2021


On 20/11/2021 14:33, Richard Damon wrote:

>> Personally, I've been burned so many times with assignments
>> inside tests in C that I try my best to avoid it 

> One BIG thing to point out is that C leaves a lot of details about the 
> order things happen to up to the implementation, so this sort of 
> statement might not work there.

To be honest there are many features of Python and its
implementation of the walrus assignment that are tighter
than C so my fears are not really justified, it's just
painful experience making me wary. (And to be fair C++
has tightened up many of C's shortcomings in those
areas too)

> Personally, I tend to like to decompose into clearly defined functions 

Exactly, and that's what I tend to do in places where
many might use the walrus. It's more expressive, easier
to debug and extend.

The walrus is one of those 'nice to have' things that is
mainly used by those who think there are prizes for
writing the shortest code. It's just not true.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list