How to jump from sudoku to configuring D code-completion in Eclipse

Rocky meets the town musicians of Bremen
Hacker News published today a small code snippet by Donald Knuth who exposed his way of programmatically resolve sudoku grids.

The snippet uses a strange .w extension and its syntax, although being very close to C, showed some strange particularities.

  • Comments seem to be marked using @<…@>=
  • The source code includes a @c declaration
  • Some parts were just strangely full of @:

    @d panic(m) {@+fprintf(stderr,"%s!\n%s",m,buf);@+exit(-1);@+}

From all these elements, I assumed that the code was written in D.

And if D is good enough for Donald Knuth, then I had to give it a try. Actually, I was coincidently looking for an efficient compiled language and D looks like a good candidate.

I love python, I like PHP, I will very soon fancy Ruby, but there are some times where efficiency does matter.
.Net and Mono (now) application run quite fast but sometimes you just want a binary, without having to get a framework installed, e.g. for a cgi script at your hosting partner that did not and will certainly not install mono libraries on his RedHat server.

Why not C/C++?
Sure. I am a bit rusty on C and a bit rustier on C++ but every descent programmer must know them. Period. No excuse.

The only thing is that we are in 2010 now. Knowing a language is nice. Having to work with one that does not include a garbage collector and where you need to explicitly malloc your structures is much less nice on a day-to-day basis.

And C is nice and clean but it is not object-oriented. And I agree with Steve Yegge that “C++ is the dumbest language on earth“.

So, D looks nice. Good performances, object-oriented, a garbage collector, some strings support, even some native unit-testing support. Well, a real language in other words. Further, its affinity with C/C++ tends to make me think that the learning curve may be lower than for other languages.

And so I jumped on Digital Mars website to get some more info.

And it turns out that comments in D, are just exactly the same as C ones: our old good // and /* .. */.

This lead to only one conclusion: Donald Knuth’s code was not written in D.

It turns out that the downloadable programs available on Donald Knuth’s web site are written in CWEB, a language that was invented by.. Knuth. Basically, it is a mix between some TeX and C, meant to write code for machines and human.

CWEB source codes can be parsed to produce some TeX documentation and some workable C code.

But anyway, even if Knuth does not use it (and maybe he does), I still want to give D a try.

I use Eclipse as my main IDE, for PHP and python. I also set CDT up and, even if I do not use it much, find it very good.
My choice of IDE for D was naturally Eclipse too.

There is an Eclipse plugin available to handle D. It is called Descent.

I must admit that it is not as polished as JDT, CDT or PDT or even Pydev can be.
As an example, by default, Descent does not handle code-completion, nor does it define a compilation/debugging environment.

There are some docs available on descent site and on the web but they mostly target either Jaunty or Windows and use an older version of ldc and things slightly differed during the installation/configuration on my Karmic distribution.

Here are the steps I used to configure the code completion:

I have not configured the compiler and debugger in eclipse yet but I am pretty sure it is very easy if you use ldc.

I also installed GDC, which has the big advantage of being part of Ubuntu repositories but I have not yet managed to make it work with tango, although it looks like it is possible.

  1. No comments yet.

  1. No trackbacks yet.