POV-Ray : Newsgroups : povray.off-topic : code readability : Re: code readability Server Time
10 Oct 2024 07:53:22 EDT (-0400)
  Re: code readability  
From: Darren New
Date: 26 Jun 2008 14:29:26
Message: <4863e006$1@news.povray.org>
Halbert wrote:
> I, for one, find it much easier to read C++ code which is braced like this:
> Why doesn't the rest of the world understand that?

Different languages encourage different indentation schemes, based on 
the details of syntax.  I use different indenting for C and Pascal, for 
example.

I tend to prefer indenting where the things in one column are 
sequentially executed. So if I have an if, an assignment, and a while 
loop, I'll tend to want to indent things so there are only three lines 
in that column, rather than including all the noise words. E.g.,

void codestuff() {
   int i;
   if (i == j) {
      do this thing;
      do that thing;
      }
   j += 1;
   while (j < 23) {
      do another;
      }
   }
void morecode() {
   }

Having things like switch (especially with fallthrus) and else sometimes 
messes up the patterns, depending on just how you manage it. I figure 
the fewer rules you need to learn to indent, the easier it is to learn it.

if (i == j) {
   stuff;
   morestuff;
} else if (yadda) {
   another stuff
   extra stuff;
} else {
   thing one
   thing two
   }


That looks kind of ugly, but it also stands out as matching "my" rules 
in many ways. Doing it as
if (i == j) {
   stuff
   }
else if (j == 3) {
   stuff
   }
else {
   thing
   }

looks nicer, and also kind of works out with the "things in the same 
column should be executed sequentially" rule. It also looks nicer when 
you have "begin" and "end" instead of { and }  :-)

-- 
Darren New / San Diego, CA, USA (PST)
  Helpful housekeeping hints:
   Check your feather pillows for holes
    before putting them in the washing machine.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.