Hello World in the D Programming Language

Hello World in the D Programming Language

By TechCogs | Programming and Coding | 22 Feb 2020


Whenever someone starts learning a programming language it's become customary for their first program to be a Hello World program, a program that simply prints the phrase, "Hello, World!" to the terminal or console.

Today we'll take a look at the standard Hello World program in D.  It's fairly simple.  In your IDE of choice simply write:

import std.stdio;

void main() {
writeln("Hello, World!");
}

Let's quickly go over what's going on here.

If you're familiar with C / C++ or Java the basic structure should look pretty familiar.  D is the next iteration of programming language after C++.  Just like C++ was an evolution and improvement on C, D is an evolution and improvement on C++.

The first line "import std.stdio;" brings in the code and functionality from the basic input and output library of D.  This is similar to #include statements from C / C++ and import statements from other programming languages.

The line "void main()" is the main function of the program and is where program execution will begin once the program is compiled and run.  The "void" keyword denotes the function doesn't need to specify a return type.  Although with main, even when it's marked as void it always returns a 0 when the program exits unless something else is specified, which is how the program signals that it ran and exited successfully.  If these concepts are unfamiliar, that's okay, don't worry about it.  Just know that "void" is the return type of the main function and in general needs to be included when writing it.

Then "writeln" calls the writeln function that's part of the std.stdio library.  It takes the text you give it and prints it to the terminal or console and places a new line after it.

And that's it.  As long as you have the D compiler installed you can compile the above code and you will have created your first traditional Hello World D program.

How do you rate this article?

7


TechCogs
TechCogs

I work with Linux, technology, computers, and science.


Programming and Coding
Programming and Coding

The wonderful world of software engineering and software creation, centered around languages like D, Java, Python, Dart, and C++.

Publish0x

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.