Last update March 23, 2010

D Tutorial /
Starting With D



To start developing in D there are several things to cover. These include choosing a version of D and run-time library based on your needs and desired libraries. A good starting point for learning the language is to start with D1.x and with Phobos (the default install from Digital Mars). As you learn the language you will be better positioned to choose Tango or D2.x. The specification is where you will find the most details on the language and decent explanations on features if you are familiar with C like languages.

Table of contents of this page
Selecting   
Version of D   
Run-time Library   
Installing a Compiler   
Useful Libraries/Tools   
Writing "Hello World"   
Related   

Selecting    

Version of D    

There are currently two versions of D. The stable D1.x and alpha D2.x. D2.x has very limited resources developed for it including IDEs and libraries. Unless you're planing to work on very small projects D1.x should be your chosen version. There is an incompatibility between the languages, for information on the differences read the D2.x changes.

Run-time Library    

If you have chosen to work with D1.x there is a choice of run-time libraries the standard library, Phobos, and Tango. These libraries are not compatible aside from using tangobos on top of Tango. Most libraries either support Tango or both there are few that only support Phobos. For this reason you will probably want to install Tango. For details about the situation and how it is resolved in D2.x visit the Standard Library page.

Installing a Compiler    

Once a version and run-time library has been chosen, the choice of compiler becomes straight forward. Read the Compilers page for more information and installation instructions.

Useful Libraries/Tools    

Now that your are set up with an environment to compile simple D programs. You can take a look at the libraries and development tools, but here are a few quick suggestions:

Writing "Hello World"    

D source code files are typically plain text files such as those that can be edited by Notepad in Windows. If you would like a fancier editor, there are several options listed at EditorSupport. But Notepad is enough.

So create this text file using your favorite editor (let's call it as nothing.d):

void main()
{
}

You might be wondering what it all means, so I'll break it down:

  • This is the main function of the program (hence the name "main").
  • The keyword "void" indicates that the function doesn't return a type.
  • The parentheses () indicate a parameter list. In this example, there are no parameters.
  • The braces {} indicate a block of statements. In this simplistic example, there aren't any statements.
So basically, this is an empty do-nothing program. But it'll compile as valid D because the syntax is correct.

For how to compile the program, read the documentation on your compiler of choice.

Now to get some output from the program. Since this will depend on if you are using Phobos or Tango, here are two examples:

Phobos:

import std.stdio;

void main()
{
    writefln("%s World", "Hello");
}

Tango:

import tango.io.Stdout;

void main()
{
    Stdout.format("{} World", "Hello").newline;
}

Related    


FrontPage | News | TestPage | MessageBoard | Search | Contributors | Folders | Index | Help | Preferences | Edit

Edit text of this page (date of last change: March 23, 2010 20:53 (diff))