Last update April 20, 2012

D Tutorial /
Starting With D



Difference (previous author) (Change, Edit, normal page display)

Added: 0a1,2
Newsflash If you are under Windows, there is a video of this Quickstarter here !


Changed: 3c5,9
== Selecting =
=== 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.

Changed: 5,6c11
=== Version of D =
There are currently two maintained versions D1.x and D2.x. There is an incompatibility between the languages, for information on the differences read the D2.x changes. The version 1 compiler will no longer be maintained after Dec 31, 2012 and it is recommended new projects develop with the latest version.
It is recommended that new projects be developed with the latest version.

Changed: 12,17c17,19
Now that you're are set up with an environment to compile simple D programs. You can take a look at the libraries, Editors, and development tools, but here are a few quick suggestions:

* Library GUI: DWT
* Development Tool IDE: DDT
* Development Tool IDE: VisualD
* Development Tool IDE: Mono-D
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.

Changed: 20c22,26
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 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.

Changed: 22,25c28,29
So create this text file using your favorite editor (let's call it as nothing.d):
[[code]void main()
{
}]
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.

Changed: 27,31c31
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.
*With Phobos(if you're using D 1.x or D2.x):

Changed: 33c33,37
So basically, this is an empty do-nothing program. But it'll compile as valid D because the syntax is correct.
import std.stdio;
void main()
{
writefln("%s World!", "Hello");
}

Changed: 35c39
For how to compile the program, read the documentation on your compiler of choice.
*With Tango (only if you're still using D 1.x):

Changed: 37c41,45
Now to get some output from the program. Since this will depend on if you are using Phobos or Tango, here are two examples:
import tango.io.Stdout;
void main()
{
Stdout.format("{} World!", "Hello").newline;
}

Changed: 39,40c47
Phobos:
[[code]import std.stdio;
Save the file "hello.d".

Changed: 42,45c49,53
void main()
{
writefln("%s World", "Hello");
}]
== 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

Changed: 47,48c55,59
Tango:
[[code]import tango.io.Stdout;
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

Changed: 50,53c61,62
void main()
{
Stdout.format("{} World", "Hello").newline;
}]
If you saw "Hello, world !", congratulations, your first D program is running !
You can now proceed to the Tutorials.

Added: 54a64,65
Nota Bene: if something goes wrong under windows, visit
this page.

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))