Re: The Decline of C/C++, the rise of X

From: Gerry Quinn (gerryq_at_DELETETHISindigo.ie)
Date: 07/25/04


Date: Sun, 25 Jul 2004 10:33:09 +0100

In article <Xns95309CFDFD163jimmaureenrogers@127.0.0.1>,
jimmaureenrogers@att.net says...
> Gerry Quinn <gerryq@DELETETHISindigo.ie> wrote in
> news:MPG.1b6cbdcee30780d19897e5@news.indigo.ie:

> You can still achieve a very similar style with keywords:
>
> if blah
> then
> DoStuff();
> end if;

The point is that the keywords take up space on the line, while curly
brackets are very narrow. For me that makes the indentation structure
less obvious. Maybe it's just me.

> I see braces add to confusion in the following set of nested blocks:
>
> for (i = 0; i <= MAX; i++)
> {
> for(j = 0; j <= 1; j++)
> {
> if (blah)
> {
> DoSomething();
> }
> }
> }
>
> The last three lines are unlabled '}'. In this example things are
> not bad because you can see the beginning and end of all three blocks
> at one glance. The problem occurs when the opening braces and the
> closing braces are on separate pages of a printout, or do not fit in
> a single screen view.
 
> In those cases I prefer:
>
> Outer:
> for i in 0..Max
> loop
> Inner:
> for j in 0..i
> loop
> if blah
> then
> DoSomething();
> end if;
> end loop Inner;
> end loop Outer;
>
> This syntax clearly identifies the end of each block including a
> label identifying which block just ended. That information is
> available to the reader of the code no matter the size of the code
> blocks.

But that is a problem with a lack of end-loop comments, rather than a
difference between the keybords and brackets. If is true, of course,
that if you add end-loop comments you vitiate any visual advantage of
brackets.

I have to say that getting brackets wrong is usually a syntax error
rather than a bug. It can be mildly annoying, but in statically typed
languages at least, it doesn't normally get past compilation.

- Gerry Quinn



Relevant Pages

  • Re: Using symbolic references to invoke package methods - good or bad practice?
    ... sub blah ... 'temporay lists' but about a two-pass algorithm: ... the map runs one loop, ...
    (comp.lang.perl.misc)
  • Re: Perl gotchas
    ... ...blah blah ... element to be used in the loop, but many times I like to take advantage ... where use of the first style of for loops has bitten them. ... "Reply" at the bottom of the article headers. ...
    (comp.lang.perl.misc)
  • Re: Perl gotchas
    ... ...blah blah ... and there's an explicit 'lexicalization' of the list ... element to be used in the loop, but many times I like to take advantage ... lines into the loop, use an explicit iterator. ...
    (comp.lang.perl.misc)
  • Re: Looping to end of document
    ... BUT my loop continues to loop. ... one bookmark object never 'equals' another bookmark object ... occurrence of text between brackets with the expression ... Dim myRg As Range ...
    (microsoft.public.word.vba.general)
  • Re: Looping to end of document
    ... BUT my loop continues to loop. ... one bookmark object never 'equals' another bookmark object ... occurrence of text between brackets with the expression ... Dim myRg As Range ...
    (microsoft.public.word.vba.general)