www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Whats the most common formatting style for dlang?

reply =?UTF-8?Q?Christian_K=c3=b6stlin?= <christian.koestlin gmail.com> writes:
Until now I formatted my toy-programs how I like it. Checking up on
dfmt I saw that these deviate from the default settings of dfmt.
Does dfmt's default settings reflect the most common style for dlang?
Actually I really like all languages, that take out the whole discussion
about formatting (like go and to a certain degree python).
Jul 19
next sibling parent Seb <seb wilzba.ch> writes:
On Wednesday, 19 July 2017 at 20:19:52 UTC, Christian Köstlin 
wrote:
 Until now I formatted my toy-programs how I like it. Checking 
 up on
 dfmt I saw that these deviate from the default settings of dfmt.
 Does dfmt's default settings reflect the most common style for 
 dlang?
 Actually I really like all languages, that take out the whole 
 discussion
 about formatting (like go and to a certain degree python).
We have a DStyle: http://dlang.org/dstyle.html dfmt supports multiple formatting options,of course, but by default it uses the DStyle ;-)
Jul 19
prev sibling parent Jonathan M Davis via Digitalmars-d-learn writes:
On Wednesday, July 19, 2017 10:19:52 PM MDT Christian Köstlin via 
Digitalmars-d-learn wrote:
 Until now I formatted my toy-programs how I like it. Checking up on
 dfmt I saw that these deviate from the default settings of dfmt.
 Does dfmt's default settings reflect the most common style for dlang?
 Actually I really like all languages, that take out the whole discussion
 about formatting (like go and to a certain degree python).
There really is no common formatting style for dlang. Format your code however you like. What really matters is the naming conventinos in the APIs (e.g. camelCase for function names and PascalCase for type names), because those affect anyone else useing the libraries that you release. Formatting is internal to your project. The only place that there's any "official" style guidelines for formatting are for the official source code such as Phobos, and what is done there is often not what's done in other projects - particularly since Andrei has gotten a lot pickier about formatting in the last couple of years and exactly how the Phobos source code should look, and what he wants often doesn't makch up with what someone else likes to do in their projects. The official style guide is here: http://dlang.org/dstyle.html but historically, it's mostly been about naming conventions, and the only formatting stuff in the non-Phobos portion has to do with using spaces instead of tabs and indenting by 4 spaces for columns - but plenty of projects don't even follow that. The latter portion of that page has additional requirements for Phobos that include stuff like requiring a single space between if and (, bit those are really only intended for official stuff like Phobos. You can follow those rules if you wish, and you may find some projects that do as well, but largely, D is like C++ in that most folks format their code however they like. There is no official or common style that eveyone follows. The most common bracing styles are BSD-Allman and K&R, but you'll find plenty of both, and while I'd guess that fewer projects use tabs than those that do, you'll find both. And you're _definitely_ not going to find agreement across projects if you're going to get so precise in the formatting as to care whether there's a space after the if or not. Code formatting is simply not the sort of area where programmers like to agree - especially when you get picky about exactly what whitespace goes where rather than just having a few simple rules like how much to indent by and what the bracing style is. So, format your code however you'd like, and if you don't want to think about it, use dfmt. But if you're looking for formatting rules that most everyone uses, you're out of luck. - Jonathan M Davis
Jul 19