Language mavens: Is there a programming with "if then else ENDIF" syntax?
Dotan Cohen
dotancohen at gmail.com
Wed Nov 18 02:33:38 EST 2009
2009/11/16 Steve Ferg <steve.ferg.bitbucket at gmail.com>:
> This is a question for the language mavens that I know hang out here.
> It is not Python related, except that recent comparisons of Python to
> Google's new Go language brought it to mind.
>
> NOTE that this is *not* a suggestion to change Python. I like Python
> just the way it is. I'm just curious about language design.
>
> For a long time I've wondered why languages still use blocks
> (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements.
>
> I've often thought that a language with this kind of block-free syntax
> would be nice and intuitive:
>
> if <condition> then
> do stuff
> elif <condition> then
> do stuff
> else
> do stuff
> endif
>
> Note that you do not need block delimiters.
>
> Obviously, you could make a more Pythonesque syntax by using a colon
> rather then "then" for the condition terminator. You could make it
> more PL/I-like by using "do", etc.
>
> You can write shell scripts using if ... fi, but other than that I
> don't recall a language with this kind of syntax.
>
> Does anybody know a language with this kind of syntax for
> ifThenElseEndif?
>
PHP has exactly this:
if (condition) {
// stuff
} elseif (otherContition) {
// otherStuff
} elseif (yetAnotherCondition) {
// yetOtherStuff
}
Furthermore, PHP has the switch statement:
http://php.net/manual/en/control-structures.switch.php
switch ($i) {
case 0:
echo "i equals 0";
break;
case 1:
echo "i equals 1";
break;
case 2:
echo "i equals 2";
break;
}
The break commands end the switch, and they can be removed to have
multiple matches perform multiple functions.
> Is there any particular reason why this might be a *bad* language-
> design idea?
It is about as far from OO as one could get. Whether or not that is
"bad" depends on the use case.
--
Dotan Cohen
http://what-is-what.com
http://gibberish.co.il
More information about the Python-list
mailing list