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

Barry Smith bsmith at mcs.anl.gov
Mon Jan 21 21:35:15 CST 2013


On Jan 21, 2013, at 9:28 PM, Sean Farley <sean.michael.farley at gmail.com> wrote:

> On Mon, Jan 21, 2013 at 9:26 PM, Satish Balay <balay at mcs.anl.gov> wrote:
>> On Mon, 21 Jan 2013, Matthew Knepley wrote:
>> 
>>> On Mon, Jan 21, 2013 at 7:18 PM, Jed Brown <jedbrown at mcs.anl.gov> wrote:
>>> 
>>>> 
>>>> On Mon, Jan 21, 2013 at 7:05 PM, Karl Rupp <rupp at mcs.anl.gov> wrote:
>>>> 
>>>>>     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.
>>>> 
>>>> 
>>>> Yes, though
>>>> 
>>>> if (y < 12) {
>>>>  ierr = Something();CHKERRQ(ierr);
>>>> }
>>>> 
>>>> takes three times as many lines. I don't care much either way, but it's
>>>> nice to not waste vertical space.
>>> 
>>> I agree here.
>> 
>> I've prefered the 1 liners as well.
> 
> So, am I the only one that like the uniformity of the three-liner?

   Yes you are.

    There is often a trade off between uniformity  and having extra lines that stretch the code onto more screens. I like uniformity but also like somewhat condensed code, though not to the extreme. For example we could do 

      if (xxx) {
         something;
         somethingelse;}
      else {
         yet another thing;}

(python like) but I am so damn use to the } on its own line I don't want to use this condensed form.

  Barry







More information about the petsc-dev mailing list