Coding Standards

Jonathan M Davis jmdavisProg at gmx.com
Fri Jul 15 00:53:27 PDT 2011


On Friday 15 July 2011 15:36:45 KennyTM~ wrote:
> On Jul 15, 11 10:07, bearophile wrote:
> > Jonathan M Davis:
> >> do not want to be forced to write code in someone else's style. As
> >> long as people don't do completely crazy stuff with formatting, it's
> >> generally easy enough to read code such that the formatting really
> >> shouldn't be an issue.
> > 
> > But Mark Chu-Carroll is very smart and expert, he's always worth
> > listening to.
> 
> http://en.wikipedia.org/wiki/Appeal_to_authority ;) A coding standard is
> good, but a it is often enforced only within one organization, not
> necessarily for the whole language.
> 
> Anyway, D has http://d-programming-language.org/dstyle.html, which is
> applied to Phobos, at least. I think it is already up-to-date, except
> the [80, 120] maximum line width and '{' on its own line rules? This has
> been discussed several times already.
> 
> (Speaking of which, druntime should also follow this style convention. I
> cringe when adopting my code to the original style
> (`f(<space>param<space>)`) of core.demangle.)
> 
> Let's make a bugzilla listing out all lacking (or over-restrictive)
> recommendations in dstyle.html.

It's mostly correct. The main items that needs to be removed are

* Op­er­a­tors are sep­a­rated by sin­gle spaces from their operands.

* Two blank lines sep­a­rat­ing func­tion bod­ies.

* One blank line sep­a­rat­ing vari­able de­c­la­ra­tions from state­ments in 
func­tion bod­ies.

These are not necessarily held to in Phobos, and I know that Andrei in 
particular doesn't like the "two blank lines separating function bodies," so 
we're not requiring any of these.

The brace on its own line and the line length limit need to be added as notes 
for Phobos, but I'm not sure that they really need to be put in the style 
guide as if we were recommending them for the language at large. Other than 
that, it might need a few minor tweaks (like making it clear that constants 
should generally be camelcased just like other variables), but glancing over 
it, I believe that it's essentially correct (except for what I mentioned 
above). I keep meaning to create a pull request for the fixes to it, but I 
haven't gotten around to it yet.

- Jonathan M Davis


More information about the Digitalmars-d mailing list