Install App Install App

Everything you need to know to get started with D

Find out why Facebook uses copious amounts of D to code some of its key features.

By Mithun Mohandas | Published 06 Jan 2016 18:03 IST
  • Find out why Facebook uses copious amounts of D to code some of its key features.

Everything you need to know to get started with D

D is a new programming language that is object-oriented, imperative, multi-paradigm system programming language. It started off as a re-engineered C++ though over the years it has been redesigned quite a bit to incorporate features of modern day programming languages like Java, Python, Ruby and C#. So you have the same performance as C++, is less verbose and is memory safe but it has the expressive power of modern languages as mentioned above. Work began on D in 1999 when Walter Bright started off with improving C++ which lacked a few paradigms like OOP(object oriented programming) and metaprogramming that were staple of modern programming languages. A functional language was created in 2001. However, in 2005 Walter Bright happened to meet Andrei Alexandrescu who was also working on his own programming language(Enki). Both of their languages had significant upgrades and it seemed as if they were solving each other’s problems.  So they started working together and by 2007, D1 or D version 1.0 was born. By this time the language had already been seeded into the community and they had a few modifications of their own to add to the mix.

Learn D tutorial
(L-R) The D creators - Walter Bright and Andrei Alexandrescu

Phobos which was D’s official runtime and standard library wasn’t well received and the community came up with Tango to replace it. Tango focused more on OOP and modularity. The existence of two libraries which were incompatible with each other early in the development cycle of a programming language would have spelled its doom but that was not the case. D2 was released six months after D1 and streamlined what could go into the main language and what couldn’t, thus bringing the community together. Tango was ported onto D2 sometime in 2012. Soon enough D1 was sent to the grave and D2 was all that remained and is now simply called as D. If one were to put forth how exactly D pans out, you could say it’s C++ done right.   

Programming in D1 felt as if you were programming using a low-level-oriented Python. The analogy might seem weird but you have speed and there is focus on the task at hand rather than fixating on the aspects of the language. D2 brought more features but it also bought more complexity that C++ has. Concurrency is a built-in feature for D2 and that is what makes D2 more popular among programmers. It is still developing and there are plenty of people dropping their preferred language for D.

Why do the D?

Let’s take a look at the programming paradigms for D. These are the related to the style or manner by which one goes about creating functions and programs. 
1. Imperative
This paradigm brings it in the same league as C. Functions, statements, data, and expressions work the same as they would in C. The differences include the ‘foreach’ loop that allows for creating loops over a collection and nested functions that have functions built within another function in such a manner that the internal function has access to the variables of the outer function.
2. Object-oriented
Object-oriented programming in D uses a single inheritance hierarchy. It does not have support multiple inheritance, however, it does make use of the interface which has been influenced from Java.
3. Metaprogramming
Metaprogramming is obtained by the combination of tuples, templates, string mixins and compile time function execution. 
4. Functional
Function literals(the ability to use an alternate syntax for defining a function), closures, recursively-immutable objects(state of which cannot be altered between iterations) and higher-order functions are supported in D.
5. Concurrent
Concurrency is when there can be multiple instances of the same computation process occurring simultaneously.
6. Memory safe programming
Functions can be marked with @safe so that they are checked by the compiler during compile time to make sure that they aren’t using any features which might lead to corruption of memory.

Learn D tutorial

The Significance

Every person that’s developing his/her programming language wishes to do something that has never been done before. D is by no means any different… or is it? Modern languages allow you to either write code fast or write fast code. Bringing the two approaches together has been a daunting task. And this is exactly what D has decided to tackle. So it’s been written for simplicity of programming while maintaining a high execution speed. Another thing that Andrei (one of the creators) boasts of is D’s modeling power. To elaborate, this means that programmers can easily replicate real world problems in D. So everything from a high volume transaction problem that banks face to automotive sensors and spark plugs can be replicated in D. So the simplicity allows the programmer to focus on the problem at hand rather than fiddle with all the constraints around approaching a problem.

Key adopters

Yup, the big blue actually employs Andrei Alexandrescu. Andrei, along with a team of programmers use Hack (another programming language) along with D to built some of the programs behind the world’s biggest social network. For example, the program that goes through Facebook’s code in order to find errors was created using D and the same goes for the preprocessor that generates the core code.

Sociomatic is an advertising agency that was recently acquired by Tesco for $200 million dollars and their entire operation has been created using D.

ABA Games
A lot of the games released by them make use of D1 which has been declared obsolete as of 2012.

Remedy Games
They are the guys behind Max Payne, Max Payne 2, Alan Wake, Alan Wake’s American Nightmare etc. and they have a massive codebase that is written in D.

Learn D tutorial

Lets get coding

So here’s how a simple program in D looks like. You may type this down in any text editor and rename the file so that it has the extension ‘.d’

import std.stdio;
void main() {

writeln(“Hello World!”);}

Save the program (let’s call it hello.d), then navigate to the folder in a command prompt window and type “dmd hello.d”. Your console should have a new line that says “Hello World!”.

Intrigued? Here’s where you can get more: 

For tutorials on 15 other hot programming languages go here.

Mithun Mohandas
Mithun Mohandas

Email Email Mithun Mohandas

Follow Us Facebook Logo Facebook Logo Facebook Logo

About Me: While not dishing out lethal doses of sarcasm, this curious creature can often be found tinkering with tech, playing 'vidya' games or exploring the darkest corners of the Internets. #PCMasterRace Read More

D D basics programming programming basics complete guide to D D programming language learn D D tutorials Protection Status