Add this blog to Del.icio.us, Digg or Furl | Create Watchlist for this blog

Programming in D - getting startet

I am programming in C/C++ for more then 15 years now. I took a look at JAVA, programmed some applications for 5 years now. But I am not so enthusiastic with JAVA, I find it kind of childish - it never stepped out of that web application area (in my opinion). No question, JAVA is bad for system programming - and no question too, there are some better choices today for business legacy system than JAVA.
I think the programming world is moving to the component side (away from the one-for-all approach, but independent from the infrastructure system for now). So what I looked for is a modern language to program fast, system-near components. And I found D.

If you search for information D is a terrible name
Try “D” in google and you will get some billions of results. Too bad, we need a web-catalog for this topic, but start with wikipedia for a first try. You will find that …

D is imperative, object-oriented, and metaprogramming
In short, that means that D knows objects and templates.

Continue with “Hello World”
The usual hello world is pretty simple and pretty close to C:

import std.stdio; // writefln() needs this module
int main(char[][] args)
{
writefln("Hello World!");
}

As you see, the include “stdio.h” has been replaced by a import std.stdio (looks like we have a package-like concept here now). And the printf() is writefln() today.

But you need a D compiler now
So start with the dgcc project. They deliver for all major (and some minor) plattforms. Install the compiler, save the code from above as test.d then compile like “gdc test.d”. As result you get the well known a.out executable (or a.exe under windows).
Run a.out and you will get:

Hello World!
Error: AssertError Failure test.d(5)

That’s because you didn’t return from your main function, so D is more severe than C. Insert a return 0; after the writefln() line and you’re done.

Next post will start with a serious application: A TCP/IP server in D.

Social Bookmarking:
Add to social bookmarking sites.
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • MisterWong
  • Furl
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati

And I've started a Drupal relaunch of my EDV Beratung now.

Leave a Reply

I appreciate all comments that add substantial content to my articles. I do not like "link-building" comments and I do not like "congratulation" comments. Every such like data posted here will go to akismet hell.