🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3838

Re: "Canadian style" of indentation

#3838
From: mfinney
Date: Thu, 24 Aug 1995 04:40
56 lines
2394 bytes
In <41g464$6vv@ruby.ucc.nau.edu>, Bob Weaver <rpw@alpine.for.nau.edu> writes:
>func()
>  {
>  ...  /* braces at same indent level as contents */
>  }

I use that style exclusively.  The reason is that I have an indentation
rule, independent of language, that if B depends on A, then B is indented
exactly three spaces under A.  The value 3 is chosen because of a paper
that tested 0,2,4 and 8 and found that 2 or 4 was optimal.  If there is a
peak to the curve, it would be at three.  Also, 2 seems to be hard to
read and 4 marches across the page too fast.

But the reason for indenting {} with the code block is that they are PART
of the block, which is dependent upon some other syntatical component.

The above indentation rule, combined with the rule restricting one
statement per line, allowed me to alter a C compiler to NOT require
braces for control statements or semi-colons for the end of statements.

Therefore, I consider the braces to be "garbage" syntax, and putting them
on a separate line makes them easy to add/remove automatically.

The result of the above, is that there are exactly two patterns of
indentation in my code...

   control-syntax
      {
      statements;
      }

   control-syntax-0
         {
         statements-0;
         }
      control-syntax-i
         {
         statements-i;
         }
      control-syntax-n
         {
         statements-n;
         }

The first pattern is used for "if" (with no "else"), for", "while" and
"do" blocks (the final "while" is written at the same indentation as
the block that preceeds it, because like the block, it depends on the
"do".  The second pattern is used for the "if" (with an "else", or
chain of "else if" sub-blocks) and the "switch".

This dependency rule works quite well, and others have adopted it
for other languages, even including Smalltalk!  I have found it to
work for all procedural languages I have tried, including assembly.


Michael Lee Finney
Technical Details
Message-ID: <41gvsi$hfv@mujibur.inmind.com>
Path: arc1-ca.pugleaf.net!mujibur.inmind.com!usenet
References: <41g464$6vv@ruby.ucc.nau.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!mujibur.inmind.com!usenet
From: mfinney@inmind.com
Newsgroups: comp.std.c
Subject: Re: "Canadian style" of indentation
Date: 24 Aug 1995 04:40:50 GMT
Organization: In Mind, Inc.
Message-ID: <41gvsi$hfv@mujibur.inmind.com>
References: <41g464$6vv@ruby.ucc.nau.edu>
Reply-To: mfinney@inmind.com
NNTP-Posting-Host: finneyman.inmind.com
X-Newsreader: IBM NewsReader/2 v1.2