Getting Started

From D Wiki
Revision as of 18:05, 23 November 2012 by Shd (talk | contribs) (Running D code like a script)
Jump to: navigation, search

So, when you have enough reasons to try D, let's get your hands dirty.

Choosing a compiler

As you probably already know, D is a compiled language, so you have to make your first choice - a compiler. In fact, you have from what to choose - there are couple of them.

Every compiler has its own strenght and weaknesses as they differ in:

  • Installation procedure
  • Ease of building from source
  • License
  • Popularity

Whichever you will choose, you shouldn't have bigger problems with changing it. Options might differ, but most of code should be compatible with all of them (if you see any problem, just contact with maintainer).


Running D code like a script

After you got your compiler installed, you'll probably want to do some coding.

For small projects (and your first experiments with language won't be probably too big) it might be useful to merge compilation, and running your code into one phase.

Most (if not all) compiler packages, contain a tool that's named rdmd/gdmd/ldmd or similar. For instructional purposes we'll call it rdmd.

Just fill your file (i.e. main.d) with a sample application:

import std.stdio;
void main()
{
    writeln("Hello, world without explicit compilations!");
}

and type in your commandline

rdmd main.d

If you properly installed your compiler, you should see 'Hello, world!' on the terminal. Isn't that simple?

For more information about this tool you might look at http://dlang.org/rdmd.html or your compiler documentation.

You can use exactly the same command for building programs that are made of separate modules, just 'import' in your source code properly. The only limiting factor is compilation time, which should be fast in D.

When your programs go larger, you might consider using a build system