DLang Notes and Examples
← prev | next →     Top-level ToC     /quickstart.html     (printable version)

1 Implementations

There are three main implemenations of D:

DMD
Official reference compiler. Lightning fast compilation.
GDC
GCC-based (uses DMD front-end).
LDC
LLVM-based (uses DMD front-end)

As DMD is now (as of 2017-04-07) free software (boost license), I default to using it unless I have reason to use one of the other implementations.

2 Install DMD

On Debian, for the latest version, you can manually download D and install the dmd .deb file:

dpkg -i dmd_2.076.1-0_amd64.deb

(Searching around with apt-cache, I wasn’t able to find dmd in the standard repository, though did find ldc and gdc.)

3 Editor/IDE Support

Lots of editors support D. Geany in nice.

On Emacs do M-x package-list-packages and install d-mode. After that, to get 4-space indents, add this to your ~/.emacs file:

(add-hook 'd-mode-hook
          (lambda ()
            (setq c-basic-offset 4)
            (setq tab-width 4)))

4 Running

4.1 Scripts

For simple script-like programs, you can create a foo.d file:

#!/usr/bin/env rdmd

import std.stdio : writeln;

void main() {
    writeln("hi");
}

then chmod +x foo.d, and ./foo.d to run it.

rdmd will have dmd compile that first, and then run it. Oh yes, dmd is fast.

4.2 Typical Projects

For more typical projects, see Typical Project Structure.