· Overview · D for Win32 · Win32 DLLs in D · C .h to D Modules · FAQ · Style Guide · Example: wc · Future · D Change Log · Tech Tips · Rationale · Exception Safety · Templates Revisited · Warnings · Glossary · Acknowledgements Tools · DMD D Compiler · GDC D Compiler · Linker · Profiler · Code Coverage · DMD Script Shell Community · News · Forum · Announcements · Learn · D links Archives · digitalmars.D · digitalmars.D.dtl · digitalmars.D.announce · digitalmars.D.dwt · digitalmars.D.learn · digitalmars.D.bugs · D.gnu · Old D |
The D StyleThe D Style is a set of style conventions for writing D programs. The D Style is not enforced by the compiler, it is purely cosmetic and a matter of choice. Adhering to the D Style, however, will make it easier for others to work with your D code and easier for you to work with others' D code. The D Style can form the starting point for a D project style guide customized for your project team.White Space
Comments
Naming Conventions
Meaningless Type AliasesThings like:alias void VOID; alias int INT; alias int* pint;should be avoided. Declaration StyleSince in D the declarations are left-associative, left justify them:int[] x, y; // makes it clear that x and y are the same type int** p, q; // makes it clear that p and q are the same typeto emphasize their relationship. Do not use the C style: int []x, y; // confusing since y is also an int[] int **p, q; // confusing since q is also an int** Operator OverloadingOperator overloading is a powerful tool to extend the basic types supported by the language. But being powerful, it has great potential for creating obfuscated code. In particular, the existing D operators have conventional meanings, such as '+' means 'add' and '<<' means 'shift left'. Overloading operator '+' with a meaning different from 'add' is arbitrarily confusing and should be avoided.Hungarian NotationJust say no. |