Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Zimbu goals - comprehension
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Bram Moolenaar  
View profile  
 More options Oct 31 2009, 9:32 am
From: Bram Moolenaar <B...@Moolenaar.net>
Date: Sat, 31 Oct 2009 14:32:44 +0100
Local: Sat, Oct 31 2009 9:32 am
Subject: Re: Zimbu goals - comprehension

Igor V. Burago wrote:
> I have two little suggestions about "one line IF" and loop labels.

> First, possible replacement for obscure
> > ? c == File.eof BREAK
>     WHEN c == File.eof BREAK
> (May be with delimiter symbol (';', ':', '?', or something else)
> between condition and statement?)
> + easy to parse
> + clear to read
> + does not reverse order of condition and statement
> - shorter than IF only for one or two symbols

Thanks, that is a good idea.  To see it in context:

        WHILE TRUE
           c = getChar()
           WHEN c == File.eof BREAK
           WHEN c == 0 CONTINUE
           handle(c)
        }

I would restrict this to using a statement that is a keyword.  Trying to
do something else, an assignment for example, goes into the direction of
code that is hard to read and easy to make mistakes:

           WHEN c == File.eof && fooOk blah = this & that

Adding a ";" in there won't help much.

> By the way, in my opinion BREAK_IF is not an elegant solution.
> And it's not a general one.

At the moment, considering the remarks, I would rather stick with with a
normal IF.  It's three lines, but avoids that the programmer has to make
a choice.  And the choice is not always obvious.  Being a bit verbose is
not that much of a problem:

        WHILE TRUE
           c = getChar()
           IF c == File.eof
             BREAK
           }
           IF c == 0
             CONTINUE
           }
           handle(c)
        }

> Second, I think that
>     label:WHILE cond
>         stats
>     }
> is not good at the point that '}' is no longer exactly under the
> loop keyword ('WHILE' in this example).  So while 'WHILE.label' is
> a little difficult to read smoothly I personally would prefer this
> over 'label:WHILE'.

I agree that having WHILE at the start of the line makes a larger piece
of code easier to read.

> Let me suggest another variant of loop labels.
>     WHILE cond : label
>         stats
>         WHEN notOk BREAK label
>     }
> After that, of course, it's possible to ask
>     IF label.breakUsed
> as it was suggested earlier.
> And I think that no delimiters is needed between BREAK and label.
> + '}' is always right under loop keyword
> + label is not between keyword and condition (that makes loop header
> less readable)

Putting the label after the condition will make it difficult to find
when using a long condition:

         WHILE sadfasdf == asdfasdf.asdf.asdf()
             && asdfasdfdsf > asdf.asdf.asd.fasdf() : label

Besides, there is a grammer conflict with the ternary operator "cond ?
one : two".  That could be solved by using something else instead of the
colon.

Anyway, I think the label should be close to the WHILE.

I have been using the ".something" notation in other places:

        FUNC.abstract RetType funcy(ArgType arg)
        FUNC.default RetType funcy(ArgType arg)

I'm not sure if, for consistency, the same syntax should be used for the
loop label, or we should intentionally do it differently, so that it's
clear a different mechanism is being used.  Let's look at a few
examples.

Using a slash:

         WHILE/loop  asdfsdf == asdf.asdf.asdf()
           FOR i IN myList
             IF bad(i)
               BREAK/loop
             }
             IF last(i)
               CONTINUE/loop
             }
             merge(i)
           }
         }
         IF loop.breakUsed
           foundBad()
         ELSE
           writeResult()
         }

Using a dot:

         WHILE.loop  asdfsdf == asdf.asdf.asdf()
           FOR i IN myList
             IF bad(i)
               BREAK.loop
             }
             IF last(i)
               CONTINUE.loop
             }
             merge(i)
           }
         }
         IF loop.breakUsed
           foundBad()
         ELSE
           writeResult()
         }

I tend to prefer WHILE/loop.

--
ARTHUR: Charge!
   [They all charge with swords drawn towards the RABBIT.  A tremendous twenty
   second fight with Peckinpahish shots and borrowing heavily also on the
   Kung Fu and karate-type films ensues, in which some four KNIGHTS are
   comprehensively killed.]
ARTHUR: Run away!  Run away!
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- B...@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.