Contrary to common belief, I think that D is a perfect first language to learn by a complete beginner of native programming. D has its roots in C/C++ realm, but its syntax is clean, modern and friendly. D doesn’t require deep knowledge of computer architecture to start writing programs. One of the strongest parts of D is in that it’s equally fit for both low level (C-like) and high level (scripting-like) programming.

Many beginners however find it easier to start with C++ because of readily available tools and IDEs like Visual Studio. D doesn’t have a standard IDE, and this can be a barrier for newcomers who just want to create a simple “Hello, World” project. So I wrote this simple five step guide which should help them.

Step 1. Install the compiler

Step 2. Create a new project

dub init

DUB is a standard package manager and build system for D. Nowadays you don’t have to call the compiler directly, it is highly recommended to work with DUB. It already comes with the compiler distribution, so you don’t have to install it separately.

“dub init” will initialize a template project, prompting you for a minimal information about it. You can leave package recipe format as a default option (json). Then type in a name of your project, description, author’s name, license, copyright and a list of dependencies. All of these fields are actually optional, so don’t worry if you are not sure about them, you can specify them later by editing dub.json.

Now do

dub build

And DUB will compile your application. If you run it in terminal, you should see

Edit source/app.d to start your project.

Which points us to the next step, configuring an editor to work with the source code.

Step 3. Install Atom and ide-dlang

Now, with Atom and ide-dlang installed, open your project:

File → Open Project Folder

…and you are ready to edit your source/app.d:

import std.stdio;void main()
{
writeln("Edit source/app.d to start your project.");
}

Step 4. Create a build configuration

{
"cmd": "dub",
"args": ["run"],
"cwd": "{PROJECT_PATH}"
}

Now you can build and run the project by pressing F9. The output will be forwarded to Atom’s built-in console.

Atom with D tools

Step 5. Add dependencies

dub add dlib

dlib is a collection of general-purpose code for such tasks as image processing and geometric transformations. In the code below I used it to load a PNG image and print its width:

import std.stdio;
import dlib;
void main()
{
auto img = loadPNG("image.png");
writeln(img.width);
}
Decoding PNG with dlib

What next?

3D game engine developer