Home > d programming language > Getting started with the D programming language

Getting started with the D programming language

Ignore all the people who tell you it can’t be done. Telling you it can’t be done means you’re on the right track.” (Walter Bright, creator of D)

New year, new language to learn :) I heard about D some years ago but I forgot about it. Last weekend I was browsing some computer books in the library when I found The D Programming Language by Andrei Alexandrescu. “Wow, I heard about it…” I read the preface and I decided to dive into it. So in the future I plan to make some posts about D.


D has two versions, D1 (which is old), and the new D2 (which is recommended for new projects). Visit the page http://www.digitalmars.com/d/download.html and download the package that is suitable for your platform. There is a .deb package for Ubuntu, a Windows installer, etc.

Hello, World!

To try D, let’s start with the classis example (hello.d):

import std.stdio;

int main()
    writeln("Hello, World!");
    return 0;

Compile it:

dmd hello.d

It will produce an executable (hello) that you can run with ./hello.

Hello, World! as a script

It is also possible to write “scripts” in D. Just add the shebang line to the beginning of the source:


import std.stdio;

int main()
    writeln("Hello, World!");
    return 0;

Notice that this time rdmd is used instead of dmd! Make the source file hello.d executable (chmod u+x hello.d) and launch it with ./hello.d. The source will be compiled and the produced binary file will be cached. If you launch hello.d again, the source won’t be compiled again unless you modified it.


Digital Mars D compiler
Based on the Digital Mars compiler suite. I showed its installation above.

Gnu D compiler
Based on the Gnu compiler collection.

sudo apt-get install gdc

LDC compiler
Based on the LLVM compiler.

sudo apt-get install ldc

LDC doesn’t support D2 or Phobos, but D1/Tango.


Recommended books

The author of D

Walter Bright is the guy who designed the D programming language. Check out his home page where you can learn more about D.

Here is an interview with him.


Opinions / Discussions


Categories: d programming language Tags:
  1. Mehdi
    January 18, 2011 at 15:00

    thanks for the news,
    i am really interested in your opinion on this language
    and most importantly, its efficiency for data mining algorithm!

    • January 18, 2011 at 15:18

      I tried to implement some data mining algorithms in C++ a year ago. It was a disaster… One thing became clear: C++ will never be my favourite language :) This D looks much better, I will read the book by Andrei. I hope D has an efficient bitvector implementation (like BitSet in Java), I’ll have to figure that out.

  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: