checking if a list is empty

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed May 11 11:50:45 EDT 2011


On Wed, 11 May 2011 15:05:45 +0100, Hans Georg Schaathun wrote:

> My concern was with the reader and not the writer.
> 
> What could elif mean other than else: if?

It could mean "Oh, the author has made a stupid typo, I better fix it."

It could mean "What does the elif command do?"

The first time I read Python code, I had literally no idea what to make 
of elif. It seemed so obvious to me that any language would let you write 
"else if ..." (on a single line) that I just assumed that elif must be 
some other construct, and I had no idea what it was. It never even 
crossed my mind that it could be "else if" rammed together into one word.

I soon learned better though.

Once you start dumbing down your code for readers who don't know your 
language, it's a race to the bottom. There's very little you can write 
that *somebody* won't misunderstand.



> if x could, for instance,  mean "if x is defined".

Yes it could, if you're programming in Perl. But we're not.

When I write a sentence in English, and I use the word "gift" to mean a 
thing which is given, I don't worry that German or Swedish readers will 
think I'm talking about poison. If I use "preservative", I mean something 
which preserves, and if Italian and Spanish readers mistake it for a 
condom, that's their problem, not mine. Writing code is no different. 
When I'm coding in Python, I use Python rules and meanings, not some 
other language.

Why should I code according to what some hypothetical Python dummy 
*might* think the code will do, instead of what the code *actually* does?



-- 
Steven



More information about the Python-list mailing list