Sunday, December 1, 2013

Is D worth learning?

D has been intriguing to me lately. The language saw a surge in popularity in October of 2013, when Andrei Alexandrescu commit 5112 lines of D to Facebook's repository, and posted about it on the dlang forums. The forum users were ecstatic, going as far of calling this commit the "new age of D". It was hard to ignore that there was something big happening in the D world, so I've taken four days to learn the basics of the language. This is my experience, and my opinion on the practicality and roadmap for D and its future.

Why use D?
D is an attempted improvement over its competitor, C++. C++ was made to stop the C preprocessor hacks that were dividing the language in the same way that the Lisp world was fragmented before Common Lisp. Because of this, C++ became a hodge-podge language, where everything under the sun was thrown in in no particular order to please everyone. D is a re-imagining of C++, with some added features from Java and the functional paradigm.

D is fast: In a trivial program, D executed only .001 seconds slower than C++, while the source code was 30 bytes smaller.

D is coherent: Lambdas, a much-loved feature in C++, were an afterthought. In D, the syntax for lambdas integrates well with the language, and how it handles blocks and values. There are tons of examples of afterthoughts from C++ being first-class citizens of D.

D is compatible: Concepts from C++ carry over well into D. Generics, pointers, structs, classes, etc. It's all there. D can also call C or C++ code with an extern statement, or embed assembly.

D is innovative: Supercompilation, the complicated process that D uses to compile itself, introduces some interesting features. Alias types that refer to any named D object (even functions) can be passed in to other functions as parameters, or instantiated. This, combined with mixins (the ability to turn any string known at compile-time into executable D code) gives the user levels of customization only rivaled by Template Haskell or Lisp.

What drawbacks are there to D?
If you read the last section about D's merits, you may be thinking that it sounds too good to be true. There must be some drawbacks to D, or else everybody would already be using it! Well, it turns out that there are some downsides to the usage of D, but not the language itself.

In the past, the D community was fragmented between two standard libraries. This fragmentation hurt D. In D2.0, the latest revision of the language, massive changes were made to the language, making obsolete the already sparse amount of tutorials on D out there. That leads into the next downer with D.

D has mainly been an enthusiast language. There is little information out there to help if you hit a snag, so you'll often have to turn to human resources to get the help you need. The amount of tutorials is minuscule compared to languages like Java or C.

D is not hard to learn. It's a familiar language, and the book "The D Programming Language" is a wonderful introduction to D, as well as one of the best books about object oriented programming ever written (in my opinion, but this is shared by many, even outside of the D community). However, if your program doesn't compile, and just spits out some obscure dmd error message, you could be out of luck finding another user who has run into your exact problem. With D, you're on the "last frontier" of meaningful documentation.

Due to the previous lack of interest, there is also a lack of third-party support. An emacs mode exists, and so do plugins for popular IDE's, but I found both to be lacking. It took about 200 lines of lisp additions to d-mode.el before I felt D was ready to be used with my editor.

So, should I learn D?
If you are looking to venture into the world of Object Oriented programming, and want to use D as a way of doing that, absolutely! If you are already an object-oriented programmer, and want to expand your horizons, D will give you the power to do just that. If you are a project manager, looking to modularize dying C++ code, or catch the wave of new technology, go ahead.

The only people I would not recommend D to are very new programmers. For me, it took a background of functional programming and Object-oriented design to be able to read the tutorials and books that are out there. There's no "A gentle introduction to programming, using D" style book out there. If you are a new programmer and feel adventurous, you really won't go wrong with D. If you can learn it, you'll utilize it a hell of a lot more than Java as a first language.

1 comment:

  1. You can give personal touch to your Hotmail account by configuring its settings, but you have to make sure that you don’t commit any mistake in it. For an error free email setting you can take help from our service agents by dialing them at 0800-029-4639.
    Hotmail Support Number UK