[petsc-dev] Style Guide: How to format single-line if/for/while-blocks?

Karl Rupp rupp at mcs.anl.gov
Mon Jan 21 19:05:06 CST 2013


Hi,

>     As you say, technically only the first one is correct. So for example
>
>     if (y < 12)  y += 93;
>     if (y < 12) SETERRQ();             note that if (y < 12) {SETERRQ();} is wrong since the {} are not needed.
>
>     Things like
>
>      if (y < 12) ierr = Something(); CHKERRQ(ierr);
>
> are just wrong source code (there should not be many of these, I fixed all the ones I found.

Fortunately I haven't come across any of these misuses (yet)...

>
>      Things like
>
>      if (y < 12) {ierr = Something(); CHKERRQ(ierr);}
>
> don't match the standard but …. am I being too picky? I believe the PETSc make uncrustify rule would move that to separate lines.

I expect that it's a lot easier to define a rule where '{' opens a new 
block on the next line rather than having a 'sometimes it's a single 
line'-type of exception.


>     Karl,
>
>       Since you are exploring this why not run the make uncrustify rule after your cleanups and see what it formats differently in all the source code. It would be good to converge to an "automatic" format quickly so people can go back to using their own styles when typing in code if they like.

Yes, I considered uncrustify as the third stage in my initial email. 
I'll try to achieve consistency asap and then fire a suitably configured 
uncrustify on it.

Best regards,
Karli




More information about the petsc-dev mailing list