Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Language mavens: Is there a programming with "if then else ENDIF" syntax?

 

 

First page Previous page 1 2 Next page Last page  View All Python python RSS feed   Index | Next | Previous | View Threaded


steve.ferg.bitbucket at gmail

Nov 16, 2009, 8:54 AM

Post #1 of 45 (896 views)
Permalink
Language mavens: Is there a programming with "if then else ENDIF" syntax?

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?

Is there any particular reason why this might be a *bad* language-
design idea?
--
http://mail.python.org/mailman/listinfo/python-list


robin at reportlab

Nov 16, 2009, 9:03 AM

Post #2 of 45 (869 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

Steve Ferg wrote:
.........
>
> 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?
.......

modern sh seems to use this with "fi" as endif eg

~:
$ if true; then
> echo true
> elif false; then
> echo false
> else
> echo hostile logic
> fi
true
~:
$

--
Robin Becker

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


james.harris.1 at googlemail

Nov 16, 2009, 9:09 AM

Post #3 of 45 (869 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

On 16 Nov, 16:54, Steve Ferg <steve.ferg.bitbuc...@gmail.com> wrote:
> 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?
>
> Is there any particular reason why this might be a *bad* language-
> design idea?

There are some. For example, Ada uses similar. See

http://en.wikipedia.org/wiki/Ada_%28programming_language%29#Control_structures

These other newsgroups may be of interest:

comp.programming
comp.lang.misc

The latter is used by people designing programming languages where you
can find knowledgeable comments aplenty.

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


acherry at btinternet

Nov 16, 2009, 9:16 AM

Post #4 of 45 (869 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

Steve Ferg <steve.ferg.bitbucket [at] gmail> wrote in
news:ff92db5b-9cb0-4a72-b339-2c5ac02fbad0 [at] p36g2000vbn
ups.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?
>
> Is there any particular reason why this might be a *bad*
> language- design idea?

I believe MATLAB has similar if syntax - please correct me if I'm
wrong.

From

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/if.html

"The if function can be used alone or with the else and elseif
functions. When using elseif and/or else within an if statement,
the general form of the statement is"

if expression1
statements1
elseif expression2
statements2
else
statements3
end


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


python at mrabarnett

Nov 16, 2009, 9:39 AM

Post #5 of 45 (869 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

Steve Ferg wrote:
> 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?
>
> Is there any particular reason why this might be a *bad* language-
> design idea?

Ada and Turing have:

if <condition> then
do stuff
elsif <condition> then
do stuff
else
do stuff
end if

Comal has:

if <condition> then
do stuff
elif <condition> then
do stuff
else
do stuff
end if

Modula-2 has:

if <condition> then
do stuff
elsif <condition> then
do stuff
else
do stuff
end
--
http://mail.python.org/mailman/listinfo/python-list


robin at reportlab

Nov 16, 2009, 9:42 AM

Post #6 of 45 (869 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

Robin Becker wrote:
.......
> modern sh seems to use this with "fi" as endif eg
>
> ~:
> $ if true; then
> > echo true
> > elif false; then
> > echo false
> > else
> > echo hostile logic
> > fi
> true
> ~:
> $
>

I meant to say that since sh uses this construct it cannot be too bad as a
language construct since the world is built with sh and bash and similar.

Of course that's a bad argument since there's more cobol than everything else
put together (allegedly).
--
Robin Becker
--
http://mail.python.org/mailman/listinfo/python-list


robin at reportlab

Nov 16, 2009, 9:42 AM

Post #7 of 45 (869 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

Robin Becker wrote:
.......
> modern sh seems to use this with "fi" as endif eg
>
> ~:
> $ if true; then
> > echo true
> > elif false; then
> > echo false
> > else
> > echo hostile logic
> > fi
> true
> ~:
> $
>

I meant to say that since sh uses this construct it cannot be too bad as a
language construct since the world is built with sh and bash and similar.

Of course that's a bad argument since there's more cobol than everything else
put together (allegedly).
--
Robin Becker

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


nobody at nowhere

Nov 16, 2009, 10:17 AM

Post #8 of 45 (853 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

On Mon, 16 Nov 2009 08:54:28 -0800, Steve Ferg wrote:

> 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.

> Does anybody know a language with this kind of syntax for
> ifThenElseEndif?

BBC BASIC V had if/then/else/endif (it didn't have elif).

"make" has if/else/else/endif (it doesn't have a dedicated elif, but
"else if ..." behaves like elif rather than starting a nested "if").

> Is there any particular reason why this might be a *bad* language-
> design idea?

Blocks can be useful for other reasons (e.g. limiting variable scope), so
if you already have them, you don't need to provide dedicated blocks
for control constructs.

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


python at mrabarnett

Nov 16, 2009, 10:37 AM

Post #9 of 45 (853 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

Nobody wrote:
> On Mon, 16 Nov 2009 08:54:28 -0800, Steve Ferg wrote:
>
>> 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.
>
>> Does anybody know a language with this kind of syntax for
>> ifThenElseEndif?
>
> BBC BASIC V had if/then/else/endif (it didn't have elif).
>
I forgot about that one. :-(

I used to do this in order if I wanted to avoid a lot of indentation:

CASE TRUE OF
WHEN <condition>
do something
WHEN <condition>
do something
OTHERWISE
do something
ENDCASE

> "make" has if/else/else/endif (it doesn't have a dedicated elif, but
> "else if ..." behaves like elif rather than starting a nested "if").
>
>> Is there any particular reason why this might be a *bad* language-
>> design idea?
>
> Blocks can be useful for other reasons (e.g. limiting variable scope), so
> if you already have them, you don't need to provide dedicated blocks
> for control constructs.
>

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


clp2 at rebertia

Nov 16, 2009, 11:20 AM

Post #10 of 45 (853 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

On Mon, Nov 16, 2009 at 8:54 AM, Steve Ferg
<steve.ferg.bitbucket [at] gmail> wrote:
> 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.
<snip>
> Does anybody know a language with this kind of syntax for
> ifThenElseEndif?

Ruby:

if count > 10
puts "Try again"
elsif tries == 3
puts "You lose"
else
puts "Enter a number"
end

Cheers,
Chris
--
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


rt8396 at gmail

Nov 16, 2009, 12:11 PM

Post #11 of 45 (852 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

On Nov 16, 10:54 am, Steve Ferg <steve.ferg.bitbuc...@gmail.com>
wrote:

> 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

WHY? Python's syntax is by far the most elegant of all, no need to
show the end of a block. Python is the smartest kid on the block. And
are you saying you would rather type "then" instead of ":" and "endif"
instead of "\n"?

No thanks!

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


falk at mauve

Nov 16, 2009, 12:40 PM

Post #12 of 45 (849 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

In article <ff92db5b-9cb0-4a72-b339-2c5ac02fbad0 [at] p36g2000vbn>,
Steve Ferg <steve.ferg.bitbucket [at] gmail> wrote:
>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.

"then", "else", and "endif" *are* the block delimiters

--
-Ed Falk, falk [at] despams
http://thespamdiaries.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


robert.kern at gmail

Nov 16, 2009, 12:51 PM

Post #13 of 45 (850 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

On 2009-11-16 14:40 PM, Edward A. Falk wrote:
> In article<ff92db5b-9cb0-4a72-b339-2c5ac02fbad0 [at] p36g2000vbn>,
> Steve Ferg<steve.ferg.bitbucket [at] gmail> wrote:
>> 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.
>
> "then", "else", and "endif" *are* the block delimiters

I think he meant that you don't need *extra* block delimiters or generic block
delimiters like {}.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

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


brownbar at gmail

Nov 16, 2009, 2:14 PM

Post #14 of 45 (850 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

On Nov 16, 10:54 am, Steve Ferg <steve.ferg.bitbuc...@gmail.com>
wrote:
> 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?
>
> Is there any particular reason why this might be a *bad* language-
> design idea?

Fortran95. You can even label the IF...END IF structure -- handy for
immense blocks.

This is not a criticism of Python (or of Fortran).
--
http://mail.python.org/mailman/listinfo/python-list


max at alcyone

Nov 16, 2009, 2:37 PM

Post #15 of 45 (847 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

r wrote:
> On Nov 16, 10:54 am, Steve Ferg <steve.ferg.bitbuc...@gmail.com>
> wrote:
>
>> 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
>
> WHY? Python's syntax is by far the most elegant of all, no need to
> show the end of a block. Python is the smartest kid on the block. And
> are you saying you would rather type "then" instead of ":" and "endif"
> instead of "\n"?
>
> No thanks!

You clipped out the part where he explicitly said it was not a
suggestion to change Python.

--
Erik Max Francis && max [at] alcyone && http://www.alcyone.com/max/
San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis
Mona Lisa / Come to discover / I am your daughter
-- Lamya
--
http://mail.python.org/mailman/listinfo/python-list


max at alcyone

Nov 16, 2009, 2:38 PM

Post #16 of 45 (847 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

Steve Ferg wrote:
> 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.

It's the same syntax, with `fi` written instead of `endif` -- not sure
why the difference in keyword is that big of a deal to you.

As others have pointed out, either way, there are quite a few languages
that use this type of syntax.

--
Erik Max Francis && max [at] alcyone && http://www.alcyone.com/max/
San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis
Mona Lisa / Come to discover / I am your daughter
-- Lamya
--
http://mail.python.org/mailman/listinfo/python-list


wuwei23 at gmail

Nov 16, 2009, 7:28 PM

Post #17 of 45 (841 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

Steve Ferg <steve.ferg.bitbuc...@gmail.com> wrote:
> Does anybody know a language with this kind of syntax for
> ifThenElseEndif?

VBScript.

> Is there any particular reason why this might be a *bad* language-
> design idea?

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


dickinsm at gmail

Nov 17, 2009, 2:15 AM

Post #18 of 45 (824 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

On Nov 16, 4:54 pm, Steve Ferg <steve.ferg.bitbuc...@gmail.com> wrote:
> 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.

GAP uses almost exactly this syntax, but with 'fi' instead of 'endif':

http://www.gap-system.org/Manuals/doc/htm/ref/CHAP004.htm#SECT016

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


sjmsoft at gmail

Nov 17, 2009, 7:29 AM

Post #19 of 45 (808 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

On Nov 16, 12:54 pm, Steve Ferg <steve.ferg.bitbuc...@gmail.com>
wrote:
<snip>
> Does anybody know a language with this kind of syntax for
> ifThenElseEndif?

Modern-day COBOL:

IF some-condition
do-something
ELSE
do-something-else
END-IF.

The period is also meaningful as a statement terminator in COBOL,
so it's not as clean as one might like.

I, too, like the Python way.

Cheers,
Steve J. Martin
--
http://mail.python.org/mailman/listinfo/python-list


pruebauno at latinmail

Nov 17, 2009, 9:39 AM

Post #20 of 45 (805 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

On Nov 16, 11:54 am, Steve Ferg <steve.ferg.bitbuc...@gmail.com>
wrote:
> 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?
>
> Is there any particular reason why this might be a *bad* language-
> design idea?

I personally like the "END X" syntax (not that I would want it for
Python mind you). It makes it easier to read programs backwards.
Foxpro used that syntax form extensively:

http://msdn.microsoft.com/en-us/library/b660264t%28VS.80%29.aspx

DO CASE ... ENDCASE
DO WHILE ... ENDDO
FOR EACH ... ENDFOR
FOR ... ENDFOR
IF ... ENDIF
PRINTJOB ... ENDPRINTJOB
SCAN ... ENDSCAN
TEXT ... ENDTEXT
WITH ... ENDWITH
--
http://mail.python.org/mailman/listinfo/python-list


steven.oldner at gmail

Nov 17, 2009, 11:27 AM

Post #21 of 45 (795 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

Along the COBOl line is ABAP, the 4gl language from SAP.

If today = 'Mon'.
message 'oh boy'.
elseif today = 'Wed'.
message 'Hump day'.
elseif today = 'Fri'.
message 'TGIF'.
else.
message 'get to work'.
endif.

The period is the statement teminator. Indentation and separte lines
are just to make it readable.

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


bigboss1964 at gmail

Nov 17, 2009, 4:03 PM

Post #22 of 45 (783 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

On Nov 16, 4:54 pm, Steve Ferg <steve.ferg.bitbuc...@gmail.com> wrote:
> 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?
>
> Is there any particular reason why this might be a *bad* language-
> design idea?


If you search Google, you will likely find some huge comparason of if
or flow control statements in general, in zillions of languages.


I personally like

if expr [then | { | do | :]
the code
[done | } | ]

As long as it starts with if and is immediately followed by expr, I
could care less about the rest, unless someone forgets to document
it ;-). Lisps cond is also sexy.
--
http://mail.python.org/mailman/listinfo/python-list


bartc at freeuk

Nov 17, 2009, 6:00 PM

Post #23 of 45 (780 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

"Steve Ferg" <steve.ferg.bitbucket [at] gmail> wrote in message
news:ff92db5b-9cb0-4a72-b339-2c5ac02fbad0 [at] p36g2000vbn
> 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


dotancohen at gmail

Nov 17, 2009, 11:33 PM

Post #24 of 45 (768 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

2009/11/16 Steve Ferg <steve.ferg.bitbucket [at] gmail>:
> 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
--
http://mail.python.org/mailman/listinfo/python-list


showell30 at yahoo

Nov 18, 2009, 1:15 AM

Post #25 of 45 (765 views)
Permalink
Re: Language mavens: Is there a programming with "if then else ENDIF" syntax? [In reply to]

On the topic of "switch" statements and even-more-concise-then-we-have-
already if/elif/else/end constructs, I have to say that Python does
occasionally force you to write code like the code below. Maybe
"force" is too strong a word, but Python lends itself to if/elif
blocks like below, which get the job done just fine, but which are not
syntactically pretty, due to the "(el){0,1}if kind ==" duplication.
There are often cases where if/elif statements are just a smell that
you do not know how to do dictionary lookups, but if you converted the
below code to use dictionary lookups, you would complicate the code
almost as much as you abstracted the code, if not more, unless I am
just being very naive. Anonymous methods would help to a certain
degree. I am not saying I want either anonymous methods or switch
statements, but the lack of either in a language leads to very
procedural looking code when you use number-of-lines-of-code as a
(possibly dubious) metric.

Maybe this excerpt can be golfed down to something simpler, I would
love to see it!

if kind == 'dict':
return dictionary_schema(ast)
elif kind == 'list':
method = dictionary_schema(ast)
return lambda lst: map(method, lst)
elif kind == 'attr':
return ((lambda obj: getattr(obj, ast.field)), ast.field)
elif kind == 'key':
return (lambda obj: obj.get(ast.field), ast.field)
elif kind == 'as':
method, old_name = schema(ast.parent)
return (method, ast.synonym)
elif kind == 'call':
method, old_name = schema(ast.parent)
def call(obj):
return method(obj)()
return (call, old_name)
elif kind == 'recurse':
expr = ast.expr
kind = expr.kind
method, field_name = schema(ast.parent)
if kind in ['attr', 'key']:
new_method, new_field_name = schema(expr)
field_name = new_field_name
elif kind in ['dict', 'list']:
new_method = schema(expr)
else:
raise Exception('unknown kind!')
def recurse(obj):
obj = method(obj)
return new_method(obj)
return (recurse, field_name)
else:
raise Exception('unknown kind!')
--
http://mail.python.org/mailman/listinfo/python-list

First page Previous page 1 2 Next page Last page  View All Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.