www.digitalmars.com [Home] [Search] [D]

Last update Feb 4, 2002


The D Style

The 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

General
Names formed by joining multiple works should have each word other than the first capitalized.
	int myFunc();
	
Module
Module names are all lower case.

C Modules
Modules that are interfaces to C functions go into the "c" package, for example:
	import c.stdio;
	
Module names should be all lower case.

Class, Struct, Union, Enum names
are capitalized.
	class Foo;
	class FooAndBar;
	
Function names
Function names are not capitalized.
	int done();
	int doneProcessing();
	
Const names
Are in all caps.
Enum member names
Are in all caps.

Meaningless Type Aliases

Things like:
	alias void VOID;
	alias int INT;
	alias int* pint;
	
should be avoided.

Declaration Style

Since 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 type
	
to 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**
	

Hungarian Notation

Just say no.
Copyright (c) 1999-2002 by Digital Mars, All Rights Reserved