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 ShickOpens in a new tab. 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 GitHubOpens in a new tab.. 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 WikipediaOpens in a new tab., 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;
    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 compilerOpens in a new tab..

Alternatively, we can download our own D compilerOpens in a new tab. from the official website. Then, we’ll want to get a copy of Hello World in DOpens in a new tab.. 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 ShickOpens in a new tab. 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.

Sample Programs in Every Language (44 Articles)—Series Navigation

For 100 Days of Code, I’ve decided to implement a few sample programs in as many languages as possible. Each implementation details a brief history of the language and a description of the code.

The plan for the series is to explore the major general-purpose language like Java, Python, C, C++, and C#. From there, we’ll take a look at some sample programs in web development languages like Ruby, PHP, and JavaScript. As we continue, we’ll cover proprietary languages like Swift and Objective-C. Eventually, we’ll start to tackle less popular languages like Rust, x86, and Verilog. Finally, we’ll play around with some of the esoteric languages like Brainf*ck and LOLCODE.

Who knows? Maybe the Sample Programs in Every Language series will become so popular it’ll never end. To help this series grow, consider sharing it on social media with your friends. Or, if you have a language you want to see, drop your suggestion in the comments.

Jeremy Grifski

Jeremy grew up in a small town where he enjoyed playing soccer and video games, practicing taekwondo, and trading Pokémon cards. Once out of the nest, he pursued a Bachelors in Computer Engineering with a minor in Game Design. After college, he spent about two years writing software for a major engineering company. Then, he earned a master's in Computer Science and Engineering. Today, he pursues a PhD in Engineering Education in order to ultimately land a teaching gig. In his spare time, Jeremy enjoys spending time with his wife, playing Overwatch and Phantasy Star Online 2, practicing trombone, watching Penguins hockey, and traveling the world.

Recent Posts