Introduction
D is a systems programming language designed as a practical alternative to C and C++. It retains compatibility with C ABIs and header files while adding modern features such as garbage collection, first-class functions, and compile-time evaluation. D has been in development since 2001 and is maintained by the D Language Foundation.
What D Does
- Compiles to efficient native code via DMD, LDC (LLVM), or GDC (GCC) backends
- Provides direct C and C++ ABI interoperability without wrappers
- Supports compile-time function execution (CTFE) for code generation
- Includes a standard library (Phobos) with ranges, algorithms, and concurrency
- Offers optional garbage collection with the ability to use manual memory management
Architecture Overview
D has three compiler implementations: DMD (reference compiler), LDC (LLVM-based for optimized output), and GDC (GCC-based). All produce native binaries. The language supports a unique range-based iteration model that underpins the standard library algorithms. CTFE allows arbitrary D code to execute at compile time, enabling powerful metaprogramming without separate tooling.
Self-Hosting & Configuration
- Install DMD or LDC via package managers, or use the
install.shscript from dlang.org - Manage projects and dependencies with
dub, the D package manager and build tool - Configure builds in
dub.jsonordub.sdlfiles - Cross-compile using LDC with target triple flags
- Use
rdmdfor script-like execution of single-file programs
Key Features
- Three compiler backends (DMD, LDC, GDC) for different optimization needs
- Compile-time function execution (CTFE) for zero-cost abstractions
- String mixins and template metaprogramming for code generation
- Ranges and algorithms for composable lazy data processing
- Direct
extern(C)andextern(C++)interop with existing codebases
Comparison with Similar Tools
- C++ — C++ has a larger ecosystem but more complexity; D simplifies many patterns while maintaining similar performance
- Rust — Rust enforces memory safety via borrow checking; D offers optional GC and a gentler learning curve
- Go — Go is simpler with built-in concurrency; D provides more low-level control and metaprogramming
- Nim — Nim compiles via C with Python-like syntax; D has C/C++ syntax familiarity and three mature compiler backends
- Zig — Zig is minimal with no hidden control flow; D is higher-level with GC, exceptions, and a rich standard library
FAQ
Q: Is D garbage collected? A: D includes an optional GC. You can disable it and use manual memory management or allocators for performance-critical code.
Q: Can D call C libraries directly?
A: Yes. D supports extern(C) declarations, and tools like dstep can auto-generate D bindings from C headers.
Q: Who uses D in production? A: Companies including eBay, Netflix, and Mercedes-Benz have used D for performance-sensitive backend systems and tooling.
Q: How does CTFE work? A: Any D function without side effects can be evaluated at compile time. The compiler literally runs the function during compilation and embeds the result in the binary.