trinity-devel@lists.pearsoncomputing.net

Message: previous - next
Month: January 2015

Re: [trinity-devel] Codebase formatting discussion

From: Slávek Banko <slavek.banko@...>
Date: Sat, 17 Jan 2015 15:30:10 +0100
First of all: I was in earlier days very busy, so I did not manage to follow 
and respond to the debate on coding style. Now I will try gradually respond 
to individual discussed cases.


On Friday 09 of January 2015 23:33:01 Timothy Pearson wrote:
> Ah, OK, that is a valid complaint. �The case style shown above is fine and
> we'll go with that.
>
> My only remaining question then is should we also be forcing whitespace
> between each case block for legibility, something like this?
>
> do_something();
> switch(foo) �{
> � � case bar:
> � � � � a=1;
> � � � � break;
>
> � � case baz: {
> � � � � a=2;
> � � � � ...long case block...
> � � � � c=4;
> � � � � break;
> � � }
>
> � � case asd:
> � � � � a=3;
> � � � � break;
>
> � � default:
> � � � � a=0;
> }
> do_something_else();

Here I would like to advocate for the previously mentioned principle braces 
even where they are not required. By this I mean that each 'case' consider as 
block => each case should to have brackets, including 'default':

do_something();
switch(foo)  {
    case bar: {
        a=1;
        break;
    }

    case baz: {
        a=2;
        ...long case block...
        c=4;
        break;
    }

    case asd: {
        a=3;
        break;
    }

    default: {
        a=0;
    }
}
do_something_else();

The advantage is that regardless of the size of the 'case' is easily traceable 
beginning of the block => editor can be used to trace paired brackets. With 
this would also not need white space between each 'case'. By the way, I wont 
give white space anyway. :)

-- 
Sl�vek