|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 ifstatements executed at compile time. Also versioning based on debug conditions or different OSs.
static assertstatements, executed at compile time, can be used to set conditions for statically correct composition of code. Violating a static assert aborts compilation.
inoutattributes, to designate how a parameter links to a corresponding actual argument, as in Ada or in C#.
finallyclause as in Java.
longfor signed integers, and
uintetc. 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
doubleis a floating-point type,
cdoubleis a complex type with real and imaginary parts each representable as a double. Complex constants are written as in mathematics, e.g.
char, string handling in D is a direct consequence of improved array handling.
foreachloop statement for traversing collections: ordinary or associative arrays or user-defined class collections.
char * p, qmeans (unlike C/C++) that both
qare pointers to
int * adeclares
aas an array of five pointers to arrays of three
ints each. Other forms of declaration are also supported, though.
typedefis ‘strong’: the name it defines designates a new type. By contrast, the
aliasdeclaration only introduces a new name for a type (and is thus equivalent to C's
aliasis also used for symbol aliasing.
typeofoperator 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,
das an associative array of type that of
a+band key type that of
*c. The expression that is the argument of
typeofmay be templated.
malloc(and reclamation through
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
B, there is no need to define it on
b+ais treated the same as
==is commutative and consistent with
<is consistent with
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. As a way of introduction to the language coming from C or C++, the following links may be of particular interest:
• 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
Wiki4D: a wiki page for D
An open source community for the D Programming Language
A ‘windowless’ GUI Framework for D