why do well when you can just skate?

elif’s missing ‘e’

@aran384 complains on Twitter about Perl’s elsif, throwing up his hands with a “WTF?”. It’s the sort of facile complaint by the people who can’t think or don’t want to think.

In general, things are the way they are for a reason. It might not be a good reason, but there’s usually a reason. Thinking it’s just stupid is a bad starting point. That the sort of middle school thinking university is supposed to beat out of you.

There’s a problem in C, which doesn’t require braces around the body of an if for a single line:

That branch in the middle is two keywords, else followed immediately by an if. That leads a particular class of mistake where two unrelated branching bits can turn into one. Start with some code that you expect to always output two lines, one from each branch:

That compiles without a warning and now you only get one line of output! That one of the reasons that all such bodies in Perl require braces, but even then missing braces can make the two run together.

Thus, Larry made elsif, a single keyword. He could have made it elseif, but that would have had an i after and e and not in the “neighbor” and “weigh” way. This offended his linguistic training so he got rid of the e. At one conference he talked about this issue and said if you wanted the e you could make your own language.

Many things in Perl are like this, and we talk about these things in Learning Perl (sometimes in footnotes). Most odd things like this in Perl are a reaction to such problems. If you want to understand the language, you should ask “Why?”, sincerely, instead of “WTF?”, indignantly. But, that’s a critical thinking skill that you shouldn’t limit to Perl.