Exceptional coding style

Jonathan M Davis jmdavisProg at gmx.com
Fri Jan 18 01:58:52 PST 2013


On Friday, January 18, 2013 10:45:46 dennis luehring wrote:
> Am 18.01.2013 10:29, schrieb Jonathan M Davis:
> > Formatting can have a huge effect on code legibility. There are plenty of
> > cases where slight formatting changes don't make that big a difference,
> > but some really can (e.g. where the braces go), and many small
> > differences can add up. For instance, I've known folks who used lots and
> > lots of parens (generally not relying on operator precedence at all), and
> > that made the code_much_  harder to read. Or having too much or too
> > little whitespace can have a large effect on how the code looks and how
> > easy it is to read. It's a_highly_  subjective issue, but I think that
> > it's misguided to think that code formatting doesn't matter. True, the
> > semantics matter more (if nothing else, semantics matter to the compiler,
> > whereas formatting doesn't), but it still matters quite a bit.
> don't get me wrong - coding style is very very important
> 
> but without an forced formatting standard you got following problems:
> 
> -many different coding styles in each company, sometimes even on
> deparment-level, every project
> ->hard for project jumpers, always a need for everyone to define a standard
> 
> coding style itself: _highly_ subjective emotional thing mostly hard to
> discuss in any way
> ->a forced standard could de-emotionalize the them a little bit
> 
> -permanent reformatting when integrating foreign code
> 
> a forced coding style could help to define a better base standard that
> many will just use because of its existence
> 
> etc...

I've worked at places with strict coding standards which included formatting 
rules (in some cases, having to use autoformatters), and I've worked at places 
where strict coding standards were not used, and I've always found the places 
without strict coding standards to be far more pleasant. Things like APIs 
should have standards (e.g. functions are always camelCased, and types are 
PascalCased), but in general, I'm against formatting standards. For the most 
part, keeping files reasonably internally consistent should be enough. About 
the only formatting rules that I think should be strictly adhered to in 
general are bracing rules and spaces vs tabs, and I'm _very_ opinionated about 
those, but it's just plain more pleasant to leave the others to the individual 
developers with the caveat that code within a file should be reasonably 
consistent. And for the most part, that's what we've been doing with Phobos.

- Jonathan M Davis


More information about the Digitalmars-d mailing list