[OT] Auto code reformating / one coding style enforcment.

Regan Heath regan at netwin.co.nz
Tue Aug 15 00:30:43 PDT 2006


On Mon, 14 Aug 2006 18:23:27 -0700, Sean Kelly <sean at f4.ca> wrote:
> Regan Heath wrote:
>>  Oh, and for those who want to align text on seperate lines remember  
>> the golden rule; "hard tabs first, spaces following" and you'll have no  
>> problems. Regardless of the viewers tab width the lines will align.  
>> (ignoring non fixed-width fonts, for which no solution involving  
>> spaces/tabs will work).
>
> What about:
>
>      int x,
>          y,
>          z;
>
>      if( x == y ||
>          y == z )
>      {
>          func( x,
>                y,
>                z );
>      }

No problem. The above is formatted like so:

<t>int<s>x,<cr>
<t><s><s><s><s>y,<cr>
<t><s><s><s><s>z;<cr>
<cr>
<t>if(<s>x<s>==<s>y<s>||<cr>
<t><s><s><s><s>y<s>==<s>z<s>)
..etc..

you get the idea. where: <t> = tab, <s> = space

The rule "hard tabs first, spaces following" implies you cannot mix tabs  
and spaces, meaning, your line starts with tabs (denoting the left hand  
margin) then has characters or spaces but never another tab, therefore  
<t><s><t> or <s><t><s> is illegal.

In short, use tabs to indent the left hand margin only, and spaces for  
everything else.

> Changing tab widths can totally mess up this sort of thing if tabs were  
> involved in the creation of any of the involved lines. Things get even  
> worse if some lines were indented with spaces and others with tabs. I'll  
> admit that none if this is a problem for solo projects, but in a group  
> it can be a disaster.  And maybe you can enforce indenting rules to this  
> level of detail, but I can't :-)

I'll agree, trying to get a bunch of people to actually use the same  
formatting, or even to format their code consistently is nearly  
impossible..  in my ideal world I would have an editor which  
auto-formatted code that I was reading (regardless of the on-disk,  
in-file, actual format..) now that would be nice.

Regan



More information about the Digitalmars-d mailing list