Coding Standards

Jonathan M Davis jmdavisProg at gmx.com
Thu Jul 14 18:33:07 PDT 2011


On 2011-07-14 16:11, bearophile wrote:
> Mark Chu-Carroll is a first class programmer and more. He's leaving Google
> and writes about what's good in it. Here he explains in a very simple way
> why coding standards are good:
> http://scientopia.org/blogs/goodmath/2011/07/14/stuff-everyone-should-do-p
> art-2-coding-standards/
> 
> He talks just about the coding standards of one firm, so he forgets to talk
> about a related but in my opinion equally important point. If I take a
> look at Delphi code, C code, C++ code, I see everything, every coding
> style, naming convention, and many other differences, that make me harder
> to read and understand their code.
> 
> If I take a look at Python code written by ten different people I see much
> more uniformity. This uniformity is part of the Python culture, its PEP8
> http://www.python.org/dev/peps/pep-0008/ ) is a coding standard that
> instead of being just Google-wide is language-wide. This allows me to
> understand Python code in less time, to copy and use functions, classes,
> modules, packages and libraries written by other people and use them in my
> code (in C# the situation is intermediate. I see more uniformity compared
> to C++ code, but less than Python code).
> 
> Go language even comes with a source code formatter that is used often to
> format code. I think they have learnt well that Google lesson :-)
> 
> Even Scala seems about to do something similar:
> http://drdobbs.com/article/print?articleId=231001802&siteSectionName=

We have a basic coding standard up on the site (which does need some 
updating), but it primarily covers stuff like naming conventions. There is _no 
way_ that you're going to get even the Phobos developers to completely agree 
on a coding standard if you want to start requiring stuff like whether there 
are spaces around parens or not. About the only requirement that we have along 
those lines is that braces should be on their own line (aside from stuff like 
lambdas). There was enough arguing over line length limit (we finall settled 
on a hard limit of 120 with a soft limit of 80). No one wants to be forced to 
format their code in a certain way. Phobos is reasonably uniform as far as 
general formatting goes, but even it has a fair bit of variance in the exact 
formatting.

I keep meaning to update the standard online to match what we're actually 
doing in Phobos (and include separately the small number of items which are 
specific to Phobos but would not be a general standard - e.g. the line length 
limit). And D could should generally follow that, but it's primarily a naming 
standard, not a formatting standard.

Personally, I do _not_ want to see any kind of official coding standard which 
tries to regulate formatting. Invariably, it comes down to personal 
preference, and no one can agree. Python manages such uniformity at least in 
part because the language rules with regards to whitespace are inflexible 
enough that you _can't_ do it any other way. D is not that inflexible, and I 
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.

- Jonathan M Davis


More information about the Digitalmars-d mailing list