[Python-ideas] "else if" as equivalent for "elif"

Andrew Barnert abarnert at yahoo.com
Sun Oct 25 17:49:57 EDT 2015


On Oct 24, 2015, at 01:39, Sven R. Kunze <srkunze at mail.de> wrote:
> 
> I for one think it improves things (as does several other people on the list), that is why it is on the list. ;-)
> Why you may ask? Because it just reads like an English sentence: "If that condition, then (==colon) do this, else if another condition, then (==colon) do that, etc. etc."

Nobody has ever spoken a sentence in that form. Maybe with "otherwise", even more likely with no connective at all (which you'd spell with a semicolon), but never with "else". That's what's wrong with this whole argument: it's an attempt to make Python "more like English" in a way that's not actually like English.

> Something, I would be interested in is: what was the reason for introducing the non-English keyword "elif"? Parsing difficulties?

Think about the way "else if" works in C and its descendants and influencees: it's just an "else" clause whose body happens to be an "if" statement. By convention, you don't wrap the "if" statement in braces or indent it an extra level, but there's no syntactic reason not to do so. (And formatter tools need a special case to make them not do so.) In Python, indentation is not optional or conventional, it's syntactic. So the if would have to be indented under the else.

Either that, or it would have to work differently from the way it works in all those other languages. Of course that's possible, but that demolishes the other argument for this change: to make Python more like other languages, we'd make it misleadingly appear to be like all those other languages, when it actually works differently. Which would be a great way to confuse people coming to Python from Java, or alternating Python. C, and JS code in their work, etc.


More information about the Python-ideas mailing list