Advocacy (Was: Who here actually uses D?)

bearophile bearophileHUGS at lycos.com
Sun Jan 2 03:43:46 PST 2011


Walter:

> Based on what?

It's just a lump of opinions of mine, I have not written a microkernel yet :-) But I am reading a lot, I am learning and I will be able to write this kind of code too.

Some people have tried to write a kernel with Python. D2 is a nice language to use, it allows some low level control, inline asm, and it compilation model comes from C with things added. So I am sure it's possible to write a good enough kernel with D2. So it's a matter of how much the language is fit for this purpose, it's not a binary thing. Is D2 the best conceivable language to write a kernel? I don't think so (but I am often wrong).

For a kernel writer D2 doesn't offer a lot of control on low level matters, like how the compiler compiles and optimizes code (see the thread about "guaranteed optimizations". This is a case where you don't want to "Let the compiler implementors do their job" because you lose low-level control on the code produced and this introduces bugs). This was one of the main complaints of Linus against C++ for Linux kernel development.

D2 type system is refined and much more powerful than the C one. And people have written many kernels with C (C plus with few nonstandard extensions). But if you want to write a modern kernel you may want a type system more powerful than the C and D ones, that give stronger static guarantees. Linus has written a tool to strengthen the C type system:
http://en.wikipedia.org/wiki/Sparse
In another thread I have written something about typed assembly, useful to make less wild parts written in assembly:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=125815
In some situations linear types too help:
http://en.wikipedia.org/wiki/Linear_types
The Spec# language and the experimental Verve kernel we have discussed a bit in past show possible directions for future kernels, they require a pretty strong static analysis. The Sparse tool shows that some of those type system feature may be added later to D with an external tool. But Verve shows that sometimes you need something more built-in.

Bye,
bearophile


More information about the Digitalmars-d mailing list