| Thread overview | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
July 14, 2011 Coding Standards | ||||
|---|---|---|---|---|
| ||||
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-part-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= Bye, bearophile | ||||
July 14, 2011 Re: Coding Standards | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | I'm fine with any coding standard. As long as it tells everyone else to follow my lead :) | |||
July 15, 2011 Re: Coding Standards | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Thu, Jul 14, 2011 at 6:11 PM, bearophile <bearophileHUGS@lycos.com> 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-part-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=
>
> Bye,
> bearophile
>
I definitely agree. I like the uniformity in Python code, and I wish we had coding standards for D. Maybe we could formalize one?
| |||
July 15, 2011 Re: Coding Standards | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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
| |||
July 15, 2011 Re: Coding Standards | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On 7/14/2011 6:33 PM, Jonathan M Davis wrote: > Personally, I do _not_ want to see any kind of official coding standard which > tries to regulate formatting. http://digitalmars.com/d/2.0/dstyle.html The idea of the current D style guide is not to force anything on anyone, it's more of a default to fill in the vacuum when people look for a style guide, who'd prefer to use an existing one rather than invent one. | |||
July 15, 2011 Re: Coding Standards | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | 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. The Scala coding standard: http://davetron5000.github.com/scala-style/index.html I presume other D programmers share your opinion. But not using a standard with a bit more energy will be one of the faults of D. Bye, bearophile | |||
July 15, 2011 Re: Coding Standards | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Thursday 14 July 2011 22:07:03 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.
>
> The Scala coding standard: http://davetron5000.github.com/scala-style/index.html
>
> I presume other D programmers share your opinion. But not using a standard with a bit more energy will be one of the faults of D.
Being forced to code to someone else's standard is highly unpleasant. I've worked with places that had strict standards and those which didn't. It's always been more pleasant to code without a strict standard. Sure, some code might be somewhat harder to read, because it uses a style that I'm not used to, but as long as the programmer wasn't totally crazy, it's still readable, and the pain of having to read their code is _far_ smaller than the pain of having to conform to a standard that goes against how I want to code. I program for a living, and I want programming to be pleasant. Having to format code to a particular coding standard is _not_ pleasant.
Sure, Mark Chu-Caroll may be a smart guy, but i don't agree with him. He's talking about his personal experience and what he found to work for him. That's fine. That's what works for him. It's _not_ what I want to deal with.
- Jonathan M Davis
| |||
July 15, 2011 Re: Coding Standards | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter Bright Attachments:
| On Thu, 2011-07-14 at 18:56 -0700, Walter Bright wrote: > On 7/14/2011 6:33 PM, Jonathan M Davis wrote: > > Personally, I do _not_ want to see any kind of official coding standard which tries to regulate formatting. > > http://digitalmars.com/d/2.0/dstyle.html > > The idea of the current D style guide is not to force anything on anyone, it's more of a default to fill in the vacuum when people look for a style guide, who'd prefer to use an existing one rather than invent one. Which is exactly what PEP-8 is for Python -- it is the default style guide that people can fall back on if there is no agreed style for a given project by the people working on that project. The power of a sensible default is strong. But as someone said in another post, Python is special compared to the curly bracket languages due to the block formatting rules. -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel@russel.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder | |||
July 15, 2011 Re: Coding Standards | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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. > The Scala coding standard: > http://davetron5000.github.com/scala-style/index.html > > I presume other D programmers share your opinion. But not using a standard with a bit more energy will be one of the faults of D. > > Bye, > bearophile | |||
July 15, 2011 Re: Coding Standards | ||||
|---|---|---|---|---|
| ||||
Posted in reply to KennyTM~ | 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
* Operators are separated by single spaces from their operands.
* Two blank lines separating function bodies.
* One blank line separating variable declarations from statements in function bodies.
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
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply