Why program in D

From D Wiki
Jump to: navigation, search

[Many] of D's improvements appear to be small, but the aggregate is large enough that once you write a project
in D, you'll find it pretty hard to go back to another language.
-- Walter Bright

Often, programming teams will resort to a hybrid approach, where they will mix Python and C++, trying to get
the productivity of Python and the performance of C++. The frequency of this approach indicates that there
is a large unmet need in the programming language department.

D intends to fill that need. It combines the ability to do low-level manipulation of the machine with the
latest technologies in building reliable, maintainable, portable, high-level code. D has moved well ahead of
any other language in its abilities to support and integrate multiple paradigms like imperative, OOP, and
generic programming.

-- Walter Bright

Should one choose C over D for maximum performance?

My answer is an emphatic no, and I bring as evidence the fact that warp is significantly faster than the
preprocessor in my own older Digital Mars C/C++ compiler tool chain, which was already the fastest on the
market, and on which I've spared no effort optimizing and tuning over months and years. Modern compiler
technology working in concert with D language fundamentals (white-box templates, simple object models) takes
high-level compositions of templated code and optimizes it down to code that is virtually indistinguishable
from what a C programmer would write for maximum efficiency.

The neato thing about D is that by separating the code into ranges and algorithms, it becomes easy to keep
trying different range implementations and different algorithms. I tried all sorts of things. Like breeding
racehorses, I kept the profile winners and culled the losers, step by step, through the code. That would have
been a lot more difficult to do in other languages.

-- Facebook's warp C/C++ preprocessor written by Walter Bright

The detailed overview of the language should give you the big picture.

Now if you are looking for reasons to start using D you are probably also looking for reasons not to use it. This was pointed out by Andrei Alexandrescu in The Case for D, "Trying to find quick reasons to avoid [learning a new language] is a survival instinct." And like any language there are reasons not to use D, but you might find that they don't apply to you or that the benefits are greater.

Videos - language

W. Bright: The D Programming Language (2012)

A. Alexandrescu: Three Unlikely Successful Features of D (2012)

A. Alexandrescu: Generic Programming Galore Using D (2012)

A. Alexandrescu: Three Cool Things About D - The Case for the D Programing Language (2010)

W. Bright: Metaprogramming in D (2009)


Videos - D users

Weka.io: Using D for implementing a large scale primary storage system (2016)

Quantum Break: AAA Gaming with Some D Code (2016)

Sociomantic: Real-Time Big Data in D (2014)

Large Hedge Fund: Using D in production in finance (2014)

EMSI: economic modelling at scale using D (2014)

Facebook: Experience Report - Using D at Facebook and Beyond(2014)


Here is a full list of videos relating to D. Here is a list of organisations using D

Articles

You will find in the main website more than a dozen articles discussing several design decisions for the language and its library. Don't forget to have a look there. A few examples

Until that journal's untimely demise, Walter Bright regularly wrote enlightening columns in Dr Dobb's. Many were directly related to D (access is free, but it may require registering if you read more than a couple articles/day).

A. Alexandrescu wrote several equally important articles :


You can find more articles in the articles section.

See also the official D blog and This Week in D, the summary of what is going on in the D community.


Application Developers

Each language has a preferred application domain. D has a high degree of versatility as a language - it does have a sweet spot in high performance desktop and server side applications, but it can nonetheless be used where a scripting language would be the traditional choice: it provides the performance of low-level languages (of the order of C++) with the safety and ease of expression reminiscent of languages like Java and Python.

In fact, nearly everywhere Java is suitable, D could replace it, bringing in more expressive power, better performance and better memory management. Although its current libraries are nowhere near as extensive as the Java libraries, most fundamental bricks are already here, and D has native interfacing to both C and C++, with library solutions for other languages such as Python,R and Lua. You may want to have a look at Phobos and Deimos libraries, as well as third-party libraries to make your own opinion on that matter. A very nice port of Java's SWT library has been created under the name DWT (with older but more complete documentation available at the legacy dsource site). There are also bindings for GTK, and a cross-platform idiomatic D GUI.


Embedded Developers

Being targeted at 32 bit and 64 bit machines, D is not designed for embedded development on small devices. However, with the advent of Android and iOS smartphones which embed powerful CPUs and large amounts of RAM, D may be suitable for such development. The GCC and LLVM compiler backends being able to target these devices, the community is making progress.

Find out more at StackOverflow:

Numerical programmers

D provides high precision floating point, NaN, and complex/imaginary numbers. There are also a number of mathematical and scientific libraries in development, e.g. SciD. Notably the Mir and Mir-GLAS projects provide an implementation of numerical libraries that offer performance comparable to Intel MKL, and better than Eigen and OpenBLAS without the use of assembler and implemented in a way that makes porting to new platforms very simple.


Script Fan

Since D provides type inference, high-level constructs, and fast compile-time it is a great language for writing scripts. The first line of the file is ignored if it begins with #! ('shebang') and combining this with rdmd which handles dependency resolution, D becomes a leader in native-code scripting languages.

    #!/usr/bin/env rdmd

    void main() {
        import std.stdio : writeln;
        writeln("Hello, World!");
    }

Scripts with library dependencies can also be written using a shebang with the dub package manager. The example below uses the async fiber-based framework vibe.d

    #!/usr/bin/env rdmd
    /+ dub.sdl:
        name "hello"
        version "~master"
        dependency "vibe-d" version="~master"
    +/
    import vibe.core.log;
    import vibe.mail.smtp;

    void main()
    {
        auto settings = new SMTPClientSettings("smtp.example.com", 25);
        settings.connectionType = SMTPConnectionType.startTLS;
        settings.authType = SMTPAuthType.plain;
        settings.username = "username";
        settings.password = "secret";

        auto mail = new Mail;
        mail.headers["From"] = "<user@isp.com>";
        mail.headers["To"] = "<recipient@domain.com>";
        mail.headers["Subject"] = "Testmail";
        mail.bodyText = "Hello, World!";
	
        logInfo("Sending mail...");
        sendMail(settings, mail);
        logInfo("done.");
    }

Language Lover

Walter, Andrei and the D community work to make D a practical language that combines native code efficiency and control with the modeling power, safety, and productivity found in high-level languages and those that stick strictly to a single paradigm. If you enjoy languages D is interesting in the way it combines many paradigms in a C-like syntax, and yet D is also a language used in production at scale in industry and academe.

Related