Everyone likes the D. Everyone.

By Cedric Mertig

Look at this cute one. You must like him!

Dlang for (Total but not only) Beginners #0

Whats D? Should I know about it?
D, also called Dlang or “the D Language” is a Programming Language created by Walter Bright and co-designed by Andrei Alexandrescu in 2001, and you should at least give it a chance.

It was created in 2001? Isn’t that a little too old for me to learn?

No, actually not. It is not quite uncommon for Languages to become more popular as they age. As an example take Python, now probably one of the most trendy languages ever. Python didn’t appear in a lot of people’s search requests for a long time:

Comparison of searches between Python and D. D could rise soon! (Data from https://trends.google.us, taken at 14.01.2019)

So what makes this Language special? Why shouldn’t I use, say, C++?

You are Free to use whatever Language you please. But keep in mind that D has some quite neat features: D is object-oriented like java and still makes memory access available like in the C-family. Arrays in D are dynamical as they represent objects. D is usable on both: Linux and Windows as 95% of the default libraries of the Language are globally usable. The other ones can be imported with just two calls. The compiler allows cross-compiling and interpreting the written code. And there is a lot more features of the compiles to cover, but we’ll get to that later…

Alright, I’m convinced, show me how to do it!

Awesome! Let’s start with installing an appropriate Editor first. There are quite a few IDEs and Editors available (here’s a list of good ones), but for now Atom fits our needs perfectly.

To use the default Compiler of D, dmd (It’s an abbreviation fro Digital Mars D compiler as Digital Mars is the name of the D-project), you need the GCC (Gnu Compiler Collection) if you are on a linux system.
To install dmd on linux, simply open your terminal (the shortcut for this is usually CTRL+ALT+T) and promt the following commands:

sudo apt-get install snap
sudo snap install dmd --classic

It might be the case that you don’t need to install snap. This will install snap and the classic dmd compiler. We will take care about the other compilers later. Please make sure you are the administrator of the system, or at least have the permission to install this. In case this is not your first time programming, you can use d-apt to install dmd.

This is what the output should look like after issuing the command.

Now open Atom and double click next to the “Welcome”-tab. Click “open a project” on the right side. Create a directory called “dlang_projects” or whatever you would like to call it, and select it. Then click “install a package” and prompt “dlang” in the window that popped up. Click “Install” on atom-dlang by ColdenCullen.

This is what your screen should look like now if you followed all the instructions.

Finally select D as grammar. You can pick a grammar at the bottom right, next to the Git and the Github buttons after selecting your “unnamed”-tab. You are now ready to write your first line of code in D! Let’s start with the classic: Hello World!

import std.stdio;
void main() {
writefln("Hello World!");
}

Save the program as you like by pressing CTRL+S. Open a Terminal and change directory to whatever you created earlier. Then run rdmd (compile and execute) on the script you created. Notice that this won’t generate an output binary as the dmd command does.

Success!

You can see all the commands for the dmd compiler here. Stay tuned for another ZeduHow-Tutorial on D! Don’t take Drugs.