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

Karl Rupp rupp at mcs.anl.gov
Mon Jan 21 15:28:24 CST 2013


Hi,

as some of you already noticed, there's progress on the PETSc style 
front. I'm now mostly done with adding simple checks not requiring a 
full-fledged compiler for it. Instead, they are simple find/grep/python 
calls and fairly accurate. A daily HTML report is currently available 
here (click on numbers for details):
   http://krupp.iue.tuwien.ac.at/petsc-style/

One thing is fairly fuzzy, though. The style guide requests
   if (...) single_line_here
instead of
   if (...)
     single_line_here
So, in the source tree we find various one-liner versions:
   if (...) first_statement;
   if (...) { first_statement; }
   if (...) {first_statement;}
   if (...) { one_statement; second_statement; }
   if (...) {one_statement; second_statement;}
   if (...) {one_statement;second_statement;}
with the latter often being used with CHKERRQ. On the other hand, the 
style guide says
  'The closing bracket } should always be on its own line.'
which contradicts all uses except
   if (...) first_statement;

@all, particularly Barry:
What should be the unified guideline(s) in such cases (if/for/while)?

Best regards,
Karli



More information about the petsc-dev mailing list