D is a compiled systems programming language created by Walter Bright and first released through his company Digital Mars in December 2001. The short answer to why Walter Bright designed D as a better C++ is that he had spent years writing C++ compilers and knew exactly where the language hurt: slow builds, header files, a preprocessor, and template tricks that were powerful but painful to read.

Why Walter Bright designed D as a better C++

Bright's background is unusual. He wrote the strategy game Empire in the 1970s and later the Zortech C++ compiler, widely cited as the first C++ compiler to generate native code directly rather than translating to C. That experience gave him an insider's list of C++ problems. D started under the name Mars and kept C-style syntax so C and C++ programmers would feel at home, but it dropped the preprocessor, replaced headers with modules, added garbage collection by default and built testing straight into the language.

In 2007 Bright was joined by Andrei Alexandrescu, author of Modern C++ Design, who became co-designer of D2. His book The D Programming Language (2010) remains a standard reference.

Design and key features

D aims to be as fast as C++ while being as productive as a scripting language. Its most distinctive ideas are about doing work at compile time:

  • CTFE (compile-time function evaluation): ordinary functions can run inside the compiler.
  • static if, template constraints and string mixins for readable metaprogramming.
  • Ranges, Alexandrescu's replacement for C++ iterators, used throughout the Phobos standard library.
  • unittest blocks and contract programming (in, out, invariant).
  • scope(exit) and scope(failure) guards for clean resource handling.
  • Memory-safety attributes @safe, @trusted and @system, and @nogc for code that must avoid the garbage collector.
  • BetterC mode, which drops the runtime so D can replace C in embedded or kernel-style code.

D also links directly with C libraries and supports a useful subset of C++ interop. A newer feature called ImportC lets the D compiler compile C source files itself.

A short D example

The program below computes a value at compile time, builds a lazy range pipeline and uses a scope guard:

import std.stdio;
import std.algorithm : filter, map;
import std.range : iota;

int square(int x) { return x * x; }

// evaluated by the compiler, not at run time (CTFE)
enum int fixed = square(12);

void main()
{
    scope(exit) writeln("done");

    auto evens = iota(1, 11).filter!(n => n % 2 == 0).map!square;
    writeln(evens);   // [4, 16, 36, 64, 100]
    writeln(fixed);   // 144
}

D1, D2 and the compilers

D 1.0 was released in January 2007, and work on the incompatible D2 began the same year. The D1 era was marked by a split between two competing standard libraries, Phobos and Tango, which confused newcomers. D2 settled this with a shared runtime (druntime) and Phobos as the single standard library. Today "D" means D2.

CompilerBack endTypical use
DMDDigital Mars (Boost licensed since 2017)Reference compiler, fast builds
LDCLLVMOptimized release builds, many targets
GDCGCC (part of GCC since version 9, 2019)GNU toolchain integration

The language is now stewarded by the D Language Foundation, with DUB as its package manager and build tool.

Where D is used today

D never reached the mainstream, but it has loyal production users. Symmetry Investments is a major corporate sponsor and uses D heavily. Weka built its distributed file system in D. eBay's open-source tsv-utils command-line toolkit is written in D, and Netflix released a small neural-network library, Vectorflow, in D. Bright himself wrote a fast C preprocessor called warp in D for Facebook in 2014.

Influence and reception

D's biggest influence has been on ideas rather than market share. Features such as static if, compile-time evaluation and built-in unit tests showed up in D years before similar features were proposed or adopted in C++ and other languages. Vala and Genie list D among their influences.

Its main weaknesses have always been ecosystem size and the long-running debate about the garbage collector, which some systems programmers refuse to accept even when it can be avoided.

Should you learn D?

If you write C++ for a living and want to see how much cleaner native code can be, D is worth a weekend. It is also a good fit for command-line tools, data processing and fast prototypes that need to stay fast in production. Knowing why Walter Bright designed D as a better C++ helps you judge where it fits: it keeps C++'s performance and low-level control while removing much of the friction.

Frequently asked questions

Does D require a garbage collector?

D uses a garbage collector by default, but you are not forced to use it. You can mark functions @nogc, manage memory manually, or compile in BetterC mode, which removes the runtime entirely.

What is the difference between D1 and D2?

D1 was frozen after its 1.0 release in 2007, while D2 added immutability, purity, ranges and much more advanced metaprogramming. The two are not fully compatible, and all current development targets D2.

Which D compiler should a beginner use?

Most people start with DMD because it compiles very quickly and tracks the latest language features. For optimized release builds, LDC is usually the better choice.