Google C++ style guide

Jeremie Pelletier jeremiep at gmail.com
Sat Oct 3 21:32:51 PDT 2009


bearophile wrote:
> Jeremie Pelletier:
> 
>> I think these are more programming guidelines than language design rules.<
> 
> Yes, of course. But programming guidelines can give possible ideas to a language designer, because:
> - if everyone is encouraged to follow a certain idiom to avoid bugs, it may be good to let the language itself enforce the idiom (see D that disallows for(...); ).
> - if most similar guidelines suggest to not use a certain language feature, such feature may need a redesign, or maybe to be made "less nice" syntax-wise, so the syntax shows its usage is discouraged.
> - if in many guidelines suggest to do something in a standard way, to improve uniformity, it may be good to add such thing too to help spreading and transmission of code in the programmer community of that language. One of the causes of Python success is that it forces a very uniform coding style, and this helps people understand and modify each other code, this helps a little the creation of an ecosystem of reusable code. The compile-enforcing of syntax for class attributes in D can be one of such things.

I'm not sure if that's a good thing, different companies enforce 
different guidelines for different reasons, and then you have 
independent programmers with their own guidelines too.

As for less nice syntax, I'd hate to use __goto, __traits is already 
ugly enough that I always hide it behind a template with a nicer name 
and lets not even talk about __gshared showing its ugly self all over my 
C bindings :)

Maybe if the compiler had a -strict switch to enforce a certain 
guideline over code, we already have -safe for enforcements over memory 
usage! Such an enforcement would then be an awesome feature for D to 
have. I'm not against the idea, I'm against making it the only available 
option!

> I was talking about smarter function, that allocates on the heap if the requested size is too much large or if the stack is finishing :-) But of course fixed sized arrays are often enough.

Those smarts have some overhead to them to first check the allocation 
size and the remaining stack size, and finally call the appropriate 
allocator, that overhead would almost make such a smart function useless 
when compared to direct heap allocations.

> D template programming can become very unreadable, trust me :-)

Not anymore than any other bit of code :)

> Sometimes I avoid "i" for loops :-)

Sometimes I avoid "T" for templates :)

> Here I don't agree with you. Uniformity in such thing is important enough.

Again I believe such an enforcement should be behind a -strict switch, I 
agree with you that uniformity can be a great thing and I can only 
imagine the all good it does to the python community. However we're 
talking systems programming here, people want the choice between using 
the feature or not using it :)

Jeremie



More information about the Digitalmars-d mailing list