Syntax Basics and Program Structure
abstract alias align asm assert auto body bool break byte case cast catch char class const continue dchar debug default delegate deprecated do double else enum export extern false final finally float for foreach foreach_reverse function goto if immutable im…
3.1 Program Structure
C-like syntax: braces, semicolons, // and /* */ comments.
main can be void main(), int main(), or void main(string[] args).
module app; // optional module declaration (matches the file path)
import std.stdio; // import a module
import std.algorithm : map, filter; // selective import
import io = std.stdio; // renamed import
enum maxUsers = 100; // manifest constant
void main()
{
int x = 5;
writefln("x = %d", x);
}3.2 Comments
// single-line
/* multi-line */
/+ nesting /+ comments +/ allowed +/
/// documentation comment (Ddoc)
/** documentation block */
/++ nesting doc comment +/3.3 Identifiers and Naming Conventions (D Style)
Variables, functions, methods userName, readFile Types (structs, classes, enums, interfaces) Modules / packages PascalCase or single caps
3.4 Keywords (Selection)
abstract alias align asm assert auto body bool break byte case cast catch char class const continue dchar debug default delegate deprecated do double else enum export extern false final finally float for foreach foreach_reverse function goto if immutable import in inout int interface invariant is lazy long mixin module new nothrow null out override package pragma private protected public pure real ref return scope shared short static struct super switch synchronized template this throw true try typeid typeof ubyte uint ulong union unittest ushort version void wchar while with __FILE__ __LINE__ __traits __gshared