Community
Participate
Working Groups
The most natural way to write code that checks several conditions is a series of nested if-else statements, like this: if ( today == "Tuesday" ) fireworks(); else if ( itIsMealTime() ) eatLunch(); else if ( x > y + z ) fightMonster(); else readBook(); end end end I don't like the way the amount of indentation keeps increasing even though the conditions are logically at the same level. If you decide not to indent, you end up with this: if ( today == "Tuesday" ) fireworks(); else if ( itIsMealTime() ) eatLunch(); else if ( x > y + z ) fightMonster(); else readBook(); end end end The chain of end's in the last line is an abomination. We have a fairly clean way to handle this situation, using one form of our case statement: case when ( today == "Tuesday" ) fireworks(); when ( itIsMealTime() ) eatLunch(); when ( x > y + z ) fightMonster(); otherwise readBook(); end This is fine, but as I said before an 'if' statement is the most natural way to do it. I bet most EGL programmers (in EDT and RBD) wouldn't even think to use a case statement for this. My solution is to introduce a new 'elseif' keyword, which will allow people to write code like the following, which is very intuitive: if ( today == "Tuesday" ) fireworks(); elseif ( itIsMealTime() ) eatLunch(); elseif ( x > y + z ) fightMonster(); else readBook(); end Many languages have syntax like 'elseif', including Perl, Python, PHP, Visual Basic, and some Unix shell-scripting languages. It's even in the C pre-processor as #elseif. As a bonus, the form of case statement mentioned above would become redundant, so we could remove it. We'd keep the other kind of case, which is like a switch in Java or C. With only one form of case statement, EGL becomes a simpler language. We can tell people "the EGL case statement is like the switch statement in other languages." Easy! Finally, we might represent if-elseif's in the IRs as nested if-else-if's. That means the generators and debuggers wouldn't need to change.
By the way, some of the languages with syntax like 'elseif' spell it 'elsif' or 'elif'. I'm not opposed to 'elif' but I think 'elsif' would lead to lots of syntax errors as people accidentally include the second 'e'.