PLACE |
languages |
RPN in D |
The programming language D is a successor to C and C++. It can be viewed as a more practical, modern, and safe C, retaining the compactness and especially the performance of the latter. It is also an improvement on C++, redesigning many of its useful features, replacing or removing those of questionable value, and adding some that C++ lacks. D combines its C and C++ heritage with features from modern languages like Ruby, Java and C#.
Conceived in 1999, D was initially a creation of Walter Bright, who was the main developer of the first native C++ compiler, Zortech C++, which later became Symantec C++ and is now Digital Mars C++ (Digital Mars is Walter Bright's own company). The language is partly open source and still under development, currently (2010) with a stable version called D1 and one evolving in several new directions, named D2. The evolution of D is actively supported by suggestions and critique from its user community. D managed to attract a number of renowned and productive persons who actively colaborate with D's principal developer.
Although D's syntax is very much like C's, D does not aim at full backward compatibility with C. While this means that a C program is not necessarily a correct D program, the innovations of the latter language are well justified and make it more consistent and easy to use.
A notable difference of D from C and C++ is the absence of a preprocessor. A number of features are introduced in its place to provide the needed functionality in safer, more flexible and reliable ways.
Another difference is that D programs tend to make much less use of explicit pointers. The reasons for which pointers are needed in C, and partly in C++, are mostly eliminated by introducing more useful arrays, automatic memory management, output and input-output parameters and other features.
Also distinctive for D with respect to C/C++ is that it uses exceptions to signal errors in function evaluation, instead of passing error codes.
It is a design policy of D to provide certain useful datatypes, data structures, and operations directly into the language, instead of relegating them to library modules. This contributes to the practical expressiveness of the language.
Here are, in more detail, some of the important features that characterize D.
static if
statements executed at compile time. Also versioning based on debug conditions or different OSs.static assert
statements, executed at compile time, can be used to set conditions for statically correct composition of code. Violating a static assert aborts compilation.in
, out
, or inout
attributes, to designate how a parameter links to a corresponding actual argument, as in Ada or in C#.this
-pointer, respectively.finally
clause as in Java.byte
, int
, short
and long
for signed integers, and ubyte
, uint
etc. for their unsigned counterparts. Notably, the set of basic types includes complex numbers (instead of merely imitating such numbers through library functions). For example, since double
is a floating-point type, cdouble
is a complex type with real and imaginary parts each representable as a double. Complex constants are written as in mathematics, e.g. 2+3i
.char
, string handling in D is a direct consequence of improved array handling.foreach
loop statement for traversing collections: ordinary or associative arrays or user-defined class collections.char * p, q
means (unlike C/C++) that both p
and q
are pointers to char
, and int [3]*[5] a
declares a
as an array of five pointers to arrays of three int
s each. Other forms of declaration are also supported, though.typedef
is ‘strong’: the name it defines designates a new type. By contrast, the alias
declaration only introduces a new name for a type (and is thus equivalent to C's typedef
). alias
is also used for symbol aliasing.typeof
operator is used in declaration and type casting expressions to specify a type as derived for an expression, and thus to relate the type of one program object to that of another. For example, typeof(a+b)[typeof(*c)] d
declares d
as an associative array of type that of a+b
and key type that of *c
. The expression that is the argument of typeof
may be templated.new
or malloc
(and reclamation through delete
or free
) are also possible. Garbage collecting can be switched off for all or some of the program objects.+
is commutative and, once defined on types A
and B
, there is no need to define it on B
and A
, since b+a
is treated the same as a+b
; also, ==
is commutative and consistent with !=
, <
is consistent with >=
etc.D programs can call compiled C code directly and thus the wealth of existing C libraries is readily available to D. Moreover, D's standard runtime library Phobos implements, among all else, the C runtime library functions and OS API functions.
The home page of D.
• D language specification;
• Phobos runtime library specification;
• An overview of D;
• Programming in D for C Programmers;
• Programming in D for C++ Programmers;
• D vs Other Languages – a comparison table.
A wiki page for documenting D, Phobos and other libraries
Programming in D : a book on programming with D
boykobbatgmaildotcom