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

Sven R. Kunze srkunze at mail.de
Sat Oct 24 04:39:59 EDT 2015


On 23.10.2015 18:09, Nick Coghlan wrote:
> It's a big deal due to opportunity cost - any time that is spent on
> making a second spelling of "elif" possible is time not spent working
> on something that directly improves developer productivity (like
> format strings) or application correctness (like gradual typing
> support).

1) I may re-iterate. Such thinking is dangerous. It could mean 
standstill. It prevents thinking and progress. That is python-ideas; not 
python-controlling.

2) Is Python not an open-source project? Could not anybody contribute? 
To me that means, the sky is the limit.

3) Well, that the features you mentioned really do what they promise can 
be only be proved if they are implemented and used. So, we will see how 
they fare. Same, btw., would be for "else if". All of your and mine 
great thoughts are just that: thoughts, assumptions, arguments. Not facts.

> Time spent on frivolous changes also (justifiably) annoys
> users of the language given the large numbers of known problems we've
> yet to figure out how to find the time and resources to resolve.

Cf. above.

Okay, enough of resource-thinking. Back to topic.

>  From a learning perspective, remembering that "elif" is an
> abbreviation of "else if" in Python isn't any more complicated than
> remembering that "don't" is an abbreviation of "do not" in English.
> It's certainly easier to remember than what "def" or "class" means.

Let's remember that.

>  From a readability perspective, inserting an "se " in the middle of
> every elif clause doesn't really improve things:
>
>      if x == 1:
>          ...
>      elif x == 2:
>          ...
>      elif x == 3:
>          ...
>      else:
>          ...
>
> vs:
>
>      if x == 1:
>          ...
>      else if x == 2:
>          ...
>      else if x == 3:
>          ...
>      else:
>          ...
>
> It can actually be argued that it's *harder* to read, since the
> typical English phrasing for this kind of formulation is more along
> the lines of "X if case A, else Y if case B, else Z", which is the way
> conditional expressions are written.

I thought "elif" is an abbreviation of "else if" as is "don't" to "do 
not". So, why are you arguing with differing semantics when it comes to 
readability?

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." So, we got "if", ":", and "else", this is 
just all we need to learn.


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

Best,
Sven


More information about the Python-ideas mailing list