The release of Google’s ‘Go’ language seems to have shaken the world of computer languages in general and native-compiled languages in particular. That world was exclusively dominated by C and C++, but now we’re seeing more and more new languages appear and gain programmer mind-share.
In recent years, it seems the progress of programming languages was happening mainly in the realms of interpreted languages and byte-code-compiled languages. Native-compiled languages looking to attract developers accustomed to the convenience of those languages must provide similarly convenient features. The D language is no exception for this rule, hence it provides the following features:
- Type inference – So programmers don’t need to manually specify the type of each variable.
- Automatic memory and resource management. D includes a garbage collector as well as a ‘scope’ statement that allows setting up code to always run when exiting the current scope (Looks and feels similar to the ‘trap’ statement of shell languages).
- Built-in high-level data structures such as hashes and dynamic arrays.
The D language makes an effort to enable programmers to use many programming paradigms:
- Object oriented programming is supported with classes and interfaces. The interfaces have an interesting feature where they can define complex and exact semantics for the parameters being passed and not just their types.
- The object oriented model is made more flexible by the inclusion of mix-ins in the language as well as the ability to “add” methods to a class by creating functions that get the object as the first argument.
- Generic programming is enabled by the inclusion of C++-like templates but with a much simpler to use syntax and semantics.
- The combination of classes, templates and operator overloading allows for the (somewhat limited) creation of DSL’s within the language.
- Functional programming is enabled with the inclusion of immutable data, lambdas, closures and tail call optimization.
One interesting feature of D is its approach to threading. While immutable data is made available to all threads, variables in D are not shared between threads unless explicitly defined as such.
Another interesting feature of D is that it allows the programmer to go ‘down and dirty’ and eschew the automatic safety features to create faster code when needed. D includes real pointers and type casts, allows for manual, explicit memory management, it even supports embedding inline assembly!
D includes built-in support for features that are usually provided in other languages by external tools and libraries. D has a built-in code documentation generator, a built-in unit testing framework and a built-in syntax to run the program in debugging mode.
The list of D’s language features can go on and on. The language avoids selecting any particular programming paradigm. Instead, it makes an attempt to provide the programmer with all the tools and let him choose. It seems that the designer made a conscious effort to include every conceivable language feature that makes sense in a native-compiled language. This is a very interesting approach, in the end it may either cause the language to succeed, or to be cast aside as too-complex to learn.