Skip to main content
Stack Overflow
  1. About
  2. For Teams

Timeline for answer to Python, why elif keyword? by Ben

Current License: CC BY-SA 3.0

Post Revisions

4 events
when toggle format what by license comment
Jul 31, 2024 at 6:44 comment added Ben @YuhaoHanHarry I've never worked on a realistic C-like compiler, but I have implemented a toy C interpreter. The else if syntax literally falls out of the grammar rules for if and else; requiring no effort in the grammar rules or the implementation. It actually takes additional work to block the "free" else if in order to implement it specifically. Production compilers may well have a reason to do that additional work, but the point is else if is implied by the syntax rules anyway, so languages with this syntax have a strong reason to use that over a dedicated keyword.
Jul 31, 2024 at 5:40 comment added YuhaoHanHarry "Languages with C-like syntax get else if for free without having to implement it at all". Are you a developer for one of this languages? If not, I believe this is a false and very misleading statement. They do have to implement it, by designing the parser to parse the statement in the desired way, let alone any error handling and optimization.
Sep 10, 2018 at 16:41 comment added abarnert For your first footnote: every C style guide ever written says "always uses braces for control structures" and then has a v1.1 where someone scribbled in "except else if". Every automated formatted or style checker has a v1.1 where the relatively simple parse tree grew an ugly special case for else if. Every "C but better" language starts it’s design requiring braces, then adds the exception, breaking its one-postcard syntax and trivial parser. (Or they just add an elif/elsif/elsei keyword.)
Oct 27, 2012 at 0:32 history answered Ben CC BY-SA 3.0

AltStyle によって変換されたページ (->オリジナル) /