Re: Code Complete 2 is now available!

From: Richard Potthoff (richard_potthoff_at_compuserve.com)
Date: 03/18/04


Date: Wed, 17 Mar 2004 20:40:08 -0500

There is no reason to indent the statements of a block again if "begin" and
"end" are already indented.

I normally indent 2 characters for the statement blocks, and 1 character for
"else", "except", etc.:

procedure SomeFunction;
    var
        condition1: boolean; {description1}
        condition2: boolean; {description2}
    begin
    statement1;
    if condition1 then
        begin
        statement2;
        statement3;
        end {if condition1 then}
      else
        statement4;
    statement5;
    statement6;
    repeat
        statement7;
        statement8;
        until condition;
    statement9;
    end; {procedure SomeFunction}

I sometimes use "begin" and "end" as formatting elements, even when it is
not syntactically required, e.g.:

if condition1 then
    begin
    if condition2 then
        statement1
      else
        statement2
    end {if condition1 then}
  else
    begin
    statement3;
    end; {if condition1 else}
statement4;

The result is a nice "blocky" structure.

    Richard

"Tom Reiertsen" <tom@reiertsen.com> wrote in message
news:40560c78@newsgroups.borland.com...
> "Bear" <dogbear@163.net> wrote in message
> news:4053b99d$1@newsgroups.borland.com...
> > Manuscript for Code Complete 2 is now available! (pdf format)
> > It is here : http://www.stevemcconnell.com/cc2/cc.htm
> > but it will NOT be available soon !
> >
> > Code Complete 2 will be published in June 2004.
> >
>
> I have the original book and will probably buy the new one too, however,
> just the other day while I was reading the old one I discovered the
> following in the Code Styles chapter:
>
> "Avoid unindented begin-end pairs"
>
> I've always written Delphi code like this:
>
> procedure SomeFunction;
> begin
> Blabla..
> end;
>
> However, according to Steve McConnel this is bad. What do you guys think?
>
> You can all look at the examples given at around line 674 in this chapter
> (now in Java instead of Pascal, yuech!):
>
> http://www.stevemcconnell.com/cc2/31-LayoutAndStyle.pdf
>
> Tom.
>
>



Relevant Pages

  • Re: how could I indent numbers in Excel?
    ... You can use alt-enters to force new lines in a cell. ... If your list is in separate cells, you could put the number of characters to ... indent in a helper column and use another helper column for display: ...
    (microsoft.public.excel.misc)
  • Indentation for Structure, automated
    ... its logical structure, with one unit for each structure level and generally ... Using TAB for the indent unit is alas common, ... Those who like} characters to be alone on a line and aligned with the ... TP/BP/Delphi/jscr/&c, FAQ items, links. ...
    (comp.lang.javascript)
  • Re: Format Confusion
    ... Microsoft MVP (Word) ... I wish those indent ... but I cannot figure out why the indent markers on the ruler ... I might suggest showing all characters. ...
    (microsoft.public.word.newusers)
  • Re: Format Confusion
    ... I wish those indent ... but I cannot figure out why the indent markers on the ruler ... When I apply a style to the problem paragraph, ... I might suggest showing all characters. ...
    (microsoft.public.word.newusers)