Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Comparison
To D, or not to D.
William Nerdspeare
This table is a quick and rough list of various features of D that can be used to compare with other languages. While many capabilities are available with standard libraries, this table is for features built in to the core language itself. Rationale.
Feature | D | ||||
---|---|---|---|---|---|
Garbage Collection | Yes | ||||
Functions | |||||
Function delegates | Yes | ||||
Function overloading | Yes | ||||
Out function parameters | Yes | ||||
Nested functions | Yes | ||||
Function literals | Yes | ||||
Closures | Yes | ||||
Typesafe variadic arguments | Yes | ||||
Lazy function argument evaluation | Yes | ||||
Compile time function evaluation | Yes | ||||
Uniform Function Call Syntax | Yes | ||||
User Defined Attributes | Yes | ||||
Arrays | |||||
Lightweight arrays | Yes | ||||
Resizeable arrays | Yes | ||||
Built-in strings | Yes | ||||
Array slicing | Yes | ||||
Array bounds checking | Yes | ||||
Array literals | Yes | ||||
Associative arrays | Yes | ||||
String switches | Yes | ||||
Aliases | Yes | ||||
OOP | |||||
Object Oriented | Yes | ||||
Multiple Inheritance | No | ||||
Interfaces | Yes | ||||
Operator overloading | Yes | ||||
Modules | Yes | ||||
Dynamic class loading | No | ||||
Nested classes | Yes | ||||
Inner (adaptor) classes | Yes | ||||
Covariant return types | Yes | ||||
Properties | Yes | ||||
Performance | |||||
Inline assembler | Yes | ||||
Direct access to hardware | Yes | ||||
Lightweight objects | Yes | ||||
Explicit memory allocation control | Yes | ||||
Independent of VM | Yes | ||||
Direct native code gen | Yes | ||||
Generic Programming | |||||
Class Templates | Yes | ||||
Function Templates | Yes | ||||
Implicit Function Template Instantiation | Yes | ||||
Partial and Explicit Specialization | Yes | ||||
Value Template Parameters | Yes | ||||
Template Template Parameters | Yes | ||||
Variadic Template Parameters | Yes | ||||
Template Constraints | Yes | ||||
Mixins | Yes | ||||
static if | Yes | ||||
is expressions | Yes | ||||
typeof | Yes | ||||
foreach | Yes | ||||
Implicit Type Inference | Yes | ||||
Reliability | |||||
Contract Programming | Yes | ||||
Unit testing | Yes | ||||
Static construction order | Yes | ||||
Guaranteed initialization | Yes | ||||
RAII (automatic destructors) | Yes | ||||
Exception handling | Yes | ||||
Scope guards | Yes | ||||
try-catch-finally blocks | Yes | ||||
Thread synchronization primitives | Yes | ||||
Compatibility | |||||
C-style syntax | Yes | ||||
Enumerated types | Yes | ||||
Support all C types | Yes | ||||
80 bit floating point | Yes | ||||
Complex and Imaginary | Yes | ||||
Direct access to C | Yes | ||||
Use existing debuggers | Yes | ||||
Struct member alignment control | Yes | ||||
Generates standard object files | Yes | ||||
Macro text preprocessor | No | ||||
Other | |||||
Conditional compilation | Yes | ||||
Unicode source text | Yes | ||||
Documentation comments | Yes |
Notes
- Object Oriented
- This means support for classes, member functions, inheritance, and virtual function dispatch.
- Inline assembler
- Many C and C++ compilers support an inline assembler, but this is not a standard part of the language, and implementations vary widely in syntax and quality.
- Interfaces
- Support in C++ for interfaces is weak enough that an IDL (Interface Description Language) was invented to compensate.
- Modules
- Many correctly argue that C++ doesn't really have modules. But C++ namespaces coupled with header files share many features with modules.
- Garbage Collection
- The Hans-Boehm garbage collector can be successfully used with C and C++, but it is not a standard part of the language.
- Implicit Type Inference
- This refers to the ability to pick up the type of a declaration from its initializer.
- Contract Programming
- The Digital Mars C++ compiler supports Contract Programming as an extension. Compare some C++ techniques for doing Contract Programming with D.
- Resizeable arrays
- Part of the standard library for C++ implements resizeable arrays, however, they are not part of the core language. A conforming freestanding implementation of C++ (C++98 17.4.1.3) does not need to provide these libraries.
- Built-in Strings
- Part of the standard library for C++ implements strings, however, they are not part of the core language. A conforming freestanding implementation of C++ (C++98 17.4.1.3) does not need to provide these libraries.
- Use existing debuggers
- By this is meant using common debuggers that can operate using debug data in common formats embedded in the executable. A specialized debugger useful only with that language is not required.
- Struct member alignment control
- Although many C/C++ compilers contain pragmas to specify
struct alignment, these are nonstandard and incompatible from
compiler to compiler.
The C# standard ECMA-334 25.5.8 says only this about struct member alignment: "The order in which members are packed into a struct is unspecified. For alignment purposes, there may be unnamed padding at the beginning of a struct, within a struct, and at the end of the struct. The contents of the bits used as padding are indeterminate." Therefore, although Microsoft may have extensions to support specific member alignment, they are not an official part of standard C#. - Support all C types
- C99 adds many new types not supported by C++.
- 80 bit floating point
- While the standards for C and C++ specify long doubles, few compilers (besides Digital Mars C/C++) actually implement 80 bit (or longer) floating point types.
- Mixins
- Mixins have many different meanings in different programming languages. D mixins mean taking an arbitrary sequence of declarations and inserting (mixing) them into the current scope. Mixins can be done at the global, class, struct, or local level.
- C++ Mixins
- C++ mixins refer to a couple different techniques. The first is analogous to D's interface classes. The second is to create a template of the form:
- Static If
- The C and C++ preprocessor directive #if would appear to be equivalent to the D static if. But there are major and crucial differences - the #if does not have access to any of the constants, types, or symbols of the program. It can only access preprocessor macros. See this example.
- Is Expressions
- Is expressions enable conditional compilation based on the characteristics of a type. This is done after a fashion in C++ using template parameter pattern matching. See this example for a comparison of the different approaches.
- Inner (adaptor) classes
- A nested class is one whose definition is within the scope of another class. An inner class is a nested class that can also reference the members and fields of the lexically enclosing class; one can think of it as if it contained a 'this' pointer to the enclosing class.
- Documentation comments
- Documentation comments refer to a standardized way to produce documentation from the source code file using specialized comments.
template <class Base> class Mixin : public Base
{
... mixin body ...
}
D mixins are different.