Hello World in D

Hello World in D Featured Image

Remember last time when when this project got its first GitHub contributor? Well, as it turns out, we were lucky enough to get another in the same week. Today, I’m thanking Trever Shick for their help with Hello World in D, a general-purpose programming language from 2001.

Table of Contents

D Background

If you haven’t heard of D, I’m hardly surprised. After all, it’s not exactly a popular language. In fact, it currently ranks 39th by popularity on GitHub. For reference, languages ahead of D include Visual Basic .NET (31st), Haskell (21st), Swift (18th), and C (8th). Meanwhile, D sits narrowly ahead of newer languages like Julia (43rd) and Elixir (45th).

That said, according to Wikipedia, D is still a pretty interesting language. As you can probably imagine, D is supposed to be an improvement on C++. Apparently, the designers weren’t a fan of the practical issues surrounding C++ (surprise, surprise!). As a result, D includes features like design by contract, garbage collection, associative arrays, array slicing, and lazy evaluation.

Perhaps the most interesting feature to me has to be the inline assembler. Apparently, developers can write assembly code directly in D source code:

void *pc;
asm
{
    pop  EBX         ;
    mov  pc[EBP], EBX ; 
}

By adding an asm block, developers can quickly tap into the hardware with assembly code. Now, I think that is a pretty cool programming language feature.

Hello World in D

At any rate, let’s get to the implementation of Hello World in D:

import std.stdio;

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

At this point, you may be questioning whether or not D is even a new language. After all, this Hello World implementation looks a lot like C/C++.

Well, then it should come as no surprise the solution is pretty much the same. We have basically three main parts: the import statement, the main function, and the print function.

Just like C/C++, the first thing we do is import our standard output library. In this case, D references std.stdio as opposed to stdio.h in C.

Up next, we have our usual main function. At this point in the series, we’re pretty use to this syntax.

Finally, we have our typical print function. In this case, we call writeln and pass a string to it.

How to Run the Solution

If we wanted to run our code snippet from above, we can leverage an online D compiler.

Alternatively, we can download our own D compiler from the official website. Then, we’ll want to get a copy of Hello World in D. After that, we can simply run the following:

rdmd hello-world.d

And, that’s it! The string “Hello, World!” should appear in the console.

Sample Programs in Every Language

As always, thanks for stopping by and a special thanks to Trever Shick for the code snippet.

If you enjoyed this article, don’t forget to give it a share. Every little bit helps grow the project. Also, consider sharing your favorite languages in the comments.

Up next, I’ll be continuing this trend of prioritizing the work of others. However, if I do get some free time, I’ll be sharing some of my own additions like Emojicode, ELENA, and Kitten.

Series Navigation← Hello World in Visual Basic .NETHello World in PicoLisp →
Advertisements

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.