POV-Ray : Newsgroups : povray.unofficial.patches : MegaPov 0.4, macros trouble : Re: macros trouble Server Time
2 Sep 2024 18:20:00 EDT (-0400)
  Re: macros trouble  
From: Thomas Willhalm
Date: 3 Feb 2000 03:47:41
Message: <qqmsnza65aq.fsf_-_@schlatt.fmi.uni-konstanz.de>
"Jon A. Cruz" <jon### [at] geocitiescom> writes:

> 
> Could I bug you to try to always use braces, even for single line
> bodies?
> 
> {
>   if(Ch=='\n') {
>           ungetc ('\r', (FILE *) File->Data);
>   }
>   ungetc (Ch, (FILE *) File->Data);
> }
> 
> As opposed to some things that are just a matter of style ( e.g. where
> you decide to place them), always using braces even for single line
> bodies is a good idea that helps prevent problems. Sometimes it's
> possible to write logic incorrectly and miss it due to misleading
> indention, but braces would catch that. 

That's why I let EMACS do the indentation do for me. This results in
a correct indentation in the sense that it reflects the assignment of
lines to loops and if statements.

If you are used to this code styling (which is the case for me), you
won't forget the braces when you add a second line. If I'm urged
to make the braces, I would have added them like this:

{
  if(Ch=='\n') 
    { ungetc ('\r', (FILE *) File->Data); }

  ungetc (Ch, (FILE *) File->Data);
}

It is more compact and therefore clearer in my opinion.


> Also, there are times when what
> you thought was a simple function might actually change to be a
> multi-line macro... and if so, BOOM! 

Because of this, I add braces to my multi-line macros. (In C++ I don't
use multi-line macros at all.)

Thomas

-- 
http://thomas.willhalm.de/ (includes pgp key)


Post a reply to this message

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