Last update April 20, 2012

D Tutorial /
Starting With D



Newsflash If you are under Windows, there is a video of this Quickstarter here !

Table of contents of this page
Which version of D ? Use D2 !   
Installing a Compiler   
Useful Libraries/Tools   
Writing "Hello World"   
Compiling and Running   
Related   

Which version of D ? Use D2 !    

There are currently two maintained versions D1.x and D2.x. The official version is D2, D1 is still provided but it's deprecated and will no longer be maintained after Dec 31, 2012.

The languages are now very different, and D2 programs will very likely not compile with a D1 compiler. For information on the differences read the D2.x changes.

It is recommended that new projects be developed with the latest version.

Installing a Compiler    

Read the Compilers page for more information and installation instructions.

Useful Libraries/Tools    

Now that you're are set up with an environment to compile simple D programs. D source code files are typically plain text files such as those that can be edited by Notepad in Windows. However, we recommend highly to install a proper programming editor. There are many of them listed at Editors and most are available for free. We'll assume you are using a text editor listed in the "Editors" section.

Writing "Hello World"    

So create this text file using your favorite editor and save it as "hello.d":

  void main(){}

This is an empty do-nothing program. But it'll compile as valid D because the syntax is correct.

Now let's change it to get some output from the program. If you are still using D1.x (we recommend to use D2.x instead), you will have to choose between the Phobos and the Tango standard library. If you are using D2.x, you will use Phobos by default.

  • With Phobos(if you're using D 1.x or D2.x):
  import std.stdio;
  void main()
  {
    writefln("%s World!", "Hello");
  }

  • With Tango (only if you're still using D 1.x):
  import tango.io.Stdout;
  void main()
  {
    Stdout.format("{} World!", "Hello").newline;
  }

Save the file "hello.d".

Compiling and Running    

To compile, all you have to do is type in the command prompt, under Unix variants(Linux, Mac, etc):
  rdmd hello.d
Or under windows:
  rdmd.exe hello.d 

This will create an executable named hello under Linux/Mac, or hello.exe under Windows. Run it by typing in the command prompt:
  ./hello
or (Windows)
  hello.exe

If you saw "Hello, world !", congratulations, your first D program is running ! You can now proceed to the Tutorials.

Nota Bene: if something goes wrong under windows, visit this page.

Related    


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

Edit text of this page (date of last change: April 20, 2012 21:22 (diff))