April 05, 2007

D Programming Language

D is a yet another object-oriented system programming language developed by Walter Bright of Digital Mars. After C and C++ in the field of system programming the next entry is D. D language has been designed from the practical knowledge of how C++ was used to solve different real life problems. It uses many C++ concepts but discards some concepts and have been influenced by concepts used in other programming languages, such as Java,C# and Eiffel.

The D language inherits many of the C++ features. The most highlighting feature is automatic memory management ( know as garbage collection ) . Another major change is C++'s multiple inheritance is replaced by Java style single inheritance, interfaces and mixins. Other changes are first class arrays, associative arrays, dynamic arrays and more. A comparison of D with languages like C++,Java and C# will help you get more details on features. Unlike newer languages like Java and C#, D is not a interpreted language and needs no runtime. Upon compiling the source code you get the executable file that runs without a runtime like JVM or .Net framework!

D language is a very new language. Its version 1.0 was released only on January 2, 2007 and is still under development. There are mainly two implementations of the complier available:
  1. DMD Compiler : the Digital Mars D compiler, the official D compiler by Walter Bright.
  2. GDC : GDC is a D language front end for the GNU Compiler Collection
I downloaded the DMD compiler and had a taste of D. I just downloaded the complier from the Digital Mars web site and extracted it. Upon extracting you will find six folders that contain the complier, library files, html and man documents, sample programs and source code of the DMD compiler. To get started I added the complier's path to my windows environment variable PATH and simply opened a notepad. With some help from the D language's wiki site.Here is my Hello world program in D :

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

To compile dmd . The file extension for D's source file is "*.d". I also tried changing the extension and compiling the code but it simple gave me an error! Thus I moved on to my next program. This time I made a program that is object oriented. There is the code:

import std.stdio;

class Test {
private int number;
private char[] name;

public:

//constructor
this(int n, char[] c) {
number = n;
name = c;
}

int getNumber() {
return number;
}

char[] getName() {
return name;
}

}

void main(char[][] args) {
writefln("A simple application:");

Test obj = new Test(142,"abdel");

writefln("Number: %d",obj.getNumber());
writefln("Name: %s",obj.getName());
}

One thing you can see here is that, D like C++ allows the programmer to follow the procedure oriented and is not a strict object oriented language like Java or C#. Another interesting concept I found is
D provides direct access to C runtime library functions and operating system API functions. You will find integration with SWT, GTK+ and much more. Ah, before I end you can find IDE plugins to many popular IDEs.

So is D language worth it when we have C, C++ for system and embedded programming? How will the programmer community take this language and to what extend will it change the programming world? But I don't know D is yet made a impression and many people are yet to know about it! What's your opinion?

No comments :