D / Phobos Style Guide

I just started looking at the source of phobos and it got clogged with several different styles and commented on the code.

The style guide on the web page is very small, and I only found broken links since 2006 and another one since 2004.

Is there a newer, more complete guide?

PS: Originally asked in the D.learn newsgroup, but since I had no answers, I thought I could try it here, although it might be a shot in the dark

+6
coding-style d phobos
source share
2 answers

Whatever guidance is outdated and should no longer exist. I donโ€™t believe that there is any D-style guide that is considered valid, and I donโ€™t think that Walter Bright, Andrei Alexandrescu, etc. They want him to be like that. Also, as far as I remember, in C ++ Standards Code: 101 Rules, Recommendations and Recommendations , Herb Sutter and Andrei said that style guides are a bad idea (or at least they were really specific), but I would have to pull out a book to say exactly what they said. Therefore, I rather doubt that Phobos (who is headed by Andrey) will have some kind of leadership style; Of course I donโ€™t know anything. There might be some recommendations for formatting the code that comes with Phobos (for example, to make your code look like the rest of the module or something similar), but someone like Andrei or one of the other Phobos developers will have to answer this . Of course, with about 15 different developers working on Phobos, you will definitely get several different styles in your code if there is no forced style guide.

So, I don't think that there really is any recommended coding style for D or Phobos. As far as I understand, the main people behind D do not particularly relate to the style guide, and they certainly did not push one. So now, in fact, there is not one, and I do not expect that in the future there will be one.

EDIT: Well, I went and looked exactly what Herb Sutter and Anderi Alexandrescu said in C ++. Coding Standards: 101 Rules, Guidelines and Best Practices . Itโ€™s not entirely that they are against coding standards to the extent that they contradict particularly restrictive ones that provide personal tastes or outdated practices. I am not going to bring all this here (this is a good book, and you should raise it anyway), but here are some key points.

  • Do not indicate how much indentation, but indent to show the structure.
  • Do not apply a specific line length, but keep the line length readable.
  • Do not rewrite the names, but agree with them.
  • Do not predefine comment styles (unless the tools extract specific styles into the documentation), but write useful comments.

Some examples they gave were that

  • The placement of the brackets should not matter, but it should be consistent and readable.
  • In tabbed spaces, they don't seem to care about what the coding standard says about this.
  • They are against the Hungarian notation in C ++, but believe that it can be useful in languages โ€‹โ€‹that are less safe for the language.
  • They are completely opposed to the fact that there is one return statement in the function.

Despite this, they believe that formatting should be consistent in the source file. Obviously, Phobos does not necessarily adhere to this at the moment, but Andrei simply raised some of the conventions that were usually held in the newsgroup and looked, perhaps, at the execution of some of them (the actual entry is archived here ).

However, while Phobos is open source and anyone is free to submit patches, remember that this is an API intended for public consumption. Only Phobos developers should look at the code (at least if the documents are properly completed) - of course, they are the only ones who will work on it directly - so there is no need for a public coding standard, even if they use them. It looks like they can use more consistency and that they can work on it, but everything that is going to be done for third parties makes it more readable. No one else should know what the standard really is (although if you looked at enough code following the standard, you could find at least more or less what the standard said).

As for D in general, there are certain conventions that are considered good practice (for example, usually using auto instead of specifying a type, if you really shouldn't specify a type), but just like in C ++, you can code with any desired coding style, and D developers are not dictatorial enough to try to apply the style to the entire D community.

+5
source share

Everything has changed so much that I think I should answer this question again. You can see the current D style guide here , and now it is updated. It has several formatting rules (for example, without tabs and each indentation level is 4 spaces), but almost all rules are in naming conventions (for example, type names should use PascalCase, while variables and functions should use camelCase). So, the focus is on how the API should look, not how to format the code. And, as I detailed in my previous answer, it will never be possible for Phobos developers to try to establish an official formatting style for D in general. As is, there are many D programmers who donโ€™t even follow the naming conventions in the official style guide.

It is possible that in the future, a more restrictive formatting guide will be created on Phobos itself (it was discussed, but never made) to make it easier for subordinates to understand what style they should follow, and to avoid arguments for formatting the code (which becomes a problem , since we switched to github, and the number of senders has increased significantly), but at the moment this primarily comes down to the fact that the code inside the module is formatted sequentially. But again, even if stricter formatting rules were established for Phobos, this would be specific to Phobos, and not to the D community as a whole. And there are too many different opinions on how code should be formatted for the standard community formatting standard that has ever worked.

+3
source share

All Articles