The D Programming Language

Familiarize yourself with the powerful compiled and managed language D.

Exceptions

As a rule, D uses exceptions for error handling as opposed to error codes. D uses the try-catch-finally model
for exceptions, which allows cleanup code to be inserted conveniently in the finally block. For those cases when
the finally block is insufficient, scope statements come in quite handy.

Classes

Like any object-oriented language, D has the ability to create object classes. One major difference is the
lack of a virtual keyword, unlike with C++. This is handled automatically by the compiler. D uses a
single-inheritance paradigm, relying on interfaces and mixins, which are discussed later to fill in the gaps.
Classes are passed by reference rather than by value, so the programmer doesn't have to worry about treating it
like a pointer. Furthermore, there is no -> or :: operator; the . is used in all situations to access members of
structs and classes. All classes derive from Object, the root of the inheritance hierarchy:

class MyClass {
int i;
char[] str;
void doSomething() { ... };
}

Classes can have defined properties by having multiple functions with the same name:

Classes can be declared inside other classes or functions, and they have access to the variables in that
scope. They also can overload operators, such as comparison, to make working with them more obvious, as in
C++.

Classes can have invariants, which are contracts that are checked at the end of constructors, before
destructors and before public members, but removed when compiling for release:

In D, there is no inline keyword—the compiler decides which functions to inline, so the programmer
doesn't even have to worry about it. Functions can be overloaded—that is to say, two functions with the same
name can take different parameters, but the compiler is smart enough to know which one you're talking about:

Lazy parameters are computed only when they are needed. For example, let's say you called a function like
this:

log("Log: error at "~toString(i)~" file not found.");

Notice that every time you call it, the strings are concatenated and passed to the function. The lazy storage
class means that the strings are put together only if they are called upon, increasing performance and efficiency.
Nested functions in D allow the nesting of functions within other functions:

void main()
{
void func()
{
..
}
}

Nested functions have read/write access to the variables of the enclosing function:

Why makes gc pure compiling (whatever that means) no longer true ? GC is done by the runtime and has nothing to do with compiling. D is a "pure compiling" language (as pure as you can get - there is nothing more pure than compiling into platform dependent native code). And why is a language badly designed just because it has the option to use garbage collection (in D you can manage memory by yourself and turn garbage collection completely off, if you want to) ?

Using ~ for concatenating arrays and not + makes sense because your not adding strings like you are adding numbers. But that might be just a matter of taste.

But if these two things are the only criterions for you to decide if a language is good or bad designed, you should better not become a language designer.

As always this is a matter of taste and personal preference. But C++ had to be designed to be backward compatible to C, so some things could not be as clean designed as they should be and make the language more complicated and error prone.

Trending Topics

Upcoming Webinar

Getting Started with DevOps - Including New Data on IT Performance from Puppet Labs 2015 State of DevOps Report

August 27, 2015
12:00 PM CDT

DevOps represents a profound change from the way most IT departments have traditionally worked: from siloed teams and high-anxiety releases to everyone collaborating on uneventful and more frequent releases of higher-quality code. It doesn't matter how large or small an organization is, or even whether it's historically slow moving or risk averse — there are ways to adopt DevOps sanely, and get measurable results in just weeks.