"Steve Ferg" <steve.ferg.bitbuc...@gmail.com> wrote in message news:ff92db5b-9cb0-4a72-b339-2c5ac02fb...@p36g2000vbn.googlegroups.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?

I think Algol 68 was responsible for a lot of this syntax, but there must be huge numbers of languages using that those forms now, apart from C-family languages which evolved their own syntax (and even in C, the preprocessor uses #if, #elif, #endif).

Some syntaxes insist on ugly begin...end blocks, but the bracketing introduced by Algol68 (maybe even earlier) showed that these are redundant:

if s then s [elsif s]* [else s] fi

where s is any sequence of statements. The statements after the 'then' are delimited by an elsif, else or fi (endif) keyword.

The endif (or fi) is necessary to show where the final statement sequence ends, and fixes the dangling-else problem. (And Algol68 also allowed this short form:

 (a | b | c)

which is just if a then b else c fi, although it gets a bit hairy with elsif in there too..)

I've often thought that a language with this kind of block-free syntax
would be nice and intuitive: ...

You're not the first to think that.. I use these forms in my own language designs for that reason. And when people write pseudo-code, it always seems to look like this, then they go and implement it in some god-forsaken syntax like C++...

...For some reason I can't quite understand, this sort of clear syntax seems to be looked down on by 'real' programmers, who perhaps think code like this can't be taken seriously.


--
Bartc
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to