When comparing D vs Dart, the Slant community recommends Dart for most people. In the question“What is the best programming language to learn first?” Dart is ranked 25th while D is ranked 28th. The most important reason people chose Dart is:
Dart is a single threaded programming language. So if any piece of code blocks the execution of the program, the program practically freezes. To avoid this Dart makes use of asynchronous operations which let your program run without getting blocked. This is done through Future objects. A Future is an object which represent a means for getting a value at a certain point in the future. A function may invoke a Future and when that happens, two outcomes can be achieved: 1. The function is unable to return a value, so it queues up work to be done and returns an uncompleted Future object. 2. Or later when a value is available to be returned, the Future object completes with that value.
Specs
Ranked in these QuestionsQuestion Ranking
Pros
Pro Has an improved C subset
With few exceptions, D will either compile C code to work exactly as when compiled as C, or it won't compile - it won't quietly change the semantics of C code and give unexpected results. This means that D contains an improved C, as it fails compilation where type safety is missing in C.
This allows learning the same machine operations available in C and other low-level languages.
Pro Easy to read and understand code
Pro Doesn't force you to deal with memory management
When you're just starting out, dealing with manual memory management and its bugs is a huge pain! D is garbage collected by default, which removes a huge class of things that could go wrong. And later on, if you decide you don't want or need the GC, you can turn it off.
Pro Very fast compilation
D is usually up to 10 times faster than C++. Having a language that compiles this fast means that you are free to write highly optimized code because of the relatively low cost of experimentation.
Pro Unit testing built-in
D provides unittest blocks to insert code that verifies functions preform their expected behavior and document edge cases. Since these are enabled with a compiler switch, there is no need to teach new programmers how to install new libraries and import modules, instead training on test driven design can start from the very first function.
Pro Provides a powerful data structure on top of C's arrays called slices
D provides a structure that builds on C's arrays called slices. A slice is a segment of an array that tracks the pointer and the length of the segment.
Slices are extremely powerful because they combine the protection of knowing the length of the data with the garbage collector that manages the memory backing that data, thus avoiding most memory corruption issues.
Pro It's a state-of-art evolution of C
Pro Static with type inference
For a new user adding types can feel tedious, and takes focus off the meaning of the code, but they are also important for checking logic. D provides static types, and a good system to infer types, so types are checked when calling functions, but do not need to be specified everywhere, making it feel more dynamic.
Pro Provable purity and immutability
The compiler can check that functions don't have side effects, extremely important for functional programming in concurrent scenarios, and can check immutability.
Therefore, the compiler will prove that your programs are functionally pure and respect immutable data, if you want it to.
Pro Compile-time Function Execution
Pro Built-in Unicode support
Pro Industrial quality
Pro Asynchronous I/O that doesn’t get in your way
Because all types can be treated as objects, all files can call functions in the same manner -- even stdin
and stdout
. stdout.writeln();
stdin.readln();
file.writeln();
file.readln();
Pro Easy to integrate with C and C++
D practically has the same memory structure as C and C++; all D does it build a structure around that. The entire C standard library is accessible at no cost (syntactic or speed) and it's being worked on allowing the same for the C++ standard library.
Pro Designed for concurrency and parallelism
Supports first-class functionality for both concurrency and parallelism, offered as part of the standard library.
Pro Supports calling functions from types in an object-oriented manner.
if (exists(file)) {}
may be written as if (file.exists) {}.
writeln(file);
may be written as file.writeln();
isDivisibleBy(10, 2);
may be written as 10.isDivisibleBy(2);
writeln(isEven(add(5, 5)));
may be written as 5.add(5).isEven().writeln();
Pro Great async language support
Dart is a single threaded programming language. So if any piece of code blocks the execution of the program, the program practically freezes. To avoid this Dart makes use of asynchronous operations which let your program run without getting blocked. This is done through Future objects.
A Future is an object which represent a means for getting a value at a certain point in the future. A function may invoke a Future and when that happens, two outcomes can be achieved:
- The function is unable to return a value, so it queues up work to be done and returns an uncompleted Future object.
- Or later when a value is available to be returned, the Future object completes with that value.
Pro Great standard library
Dart includes a truly comprehensive core library, making it unnecessary to include disparate, external resources for basic functionalities Other than reducing the need to pull in various 3rd-party utilities this also ensures that all Dart code looks and feels the same.
Out of the box, the developer gets core libraries to help with: async, collections, strings, regexps, conversions, formats, file I/O, math, typed data, and more.
Pro No compile time in development
Dartium (Chromium derivative) is a browser with integrated Dart VM, which allows you to run and debug native Dart code during development for short edit-reload cycles. Only for testing on other browsers and deployment is transpiling to JS necessary.
Pro A lot of tools are available to help in developing with Dart
Dart has a lot of tools available which help with developing Dart applications. Some examples of those tools include:
- pub - package and dependency management and build tool
- analyzer - static syntax analysis with linter, quick fixes, autocompletion support for easy IDE integration
- test - powerful and flexible testing framework and test runner
- dev_compiler - generate reusable JS instead of tree-shaken minified JS output (work in progress)
- dartfmt_ - source code formatter
- server-side VM
- observatory - a powerful tool for profiling and debugging running Dart code (for Dartium and Dart server code)
Pro Transpiled JavaScript code works on all browsers
In Dart many browser differences (subtle differences and also missing features) are abstracted away or polyfilled. When Dart is transpiled to JS the output works on all supported browsers. There is usually no need to load polyfills or to consider browser differences during development. No need for libraries like jQuery to make the same code work the same on all browsers.
Pro Will be familiar to Java developers
The language will look familiar to Java developers, easing the learning curve.
And yet, while it's similar, it has some nice syntax facilities to avoid common boilerplate code found in Java. Code is terser, yet readable.
Pro Easy prototyping
Dart has an optional type system which makes Dart a great language for prototyping. It encourages developers to gradually evolve their programs without worrying about types first.
Pro Can compile to efficient machine code
Dart was designed to be as expressive as possible. Ahead-of-time compilers can compile Dart code to efficient machine code. This is especially important when deploying to mobile where you don't want (or can't) use a JIT.
Pro AngularDart 2.0 support
Pro Optional strong mode.
Strong mode applies a more restrictive type system to Dart to address its unsound, surprising behavior in certain cases.
Pro Support of semi-coroutines (generators)
Generators, also known as semicoroutines, are also a generalization of subroutines.
Generators are primarily used to simplify the control of iteration behavior of a loop, the yield
statement in a generator passes a value back to a parent routine.
A generator is very similar to a function that returns an array, in that a generator has a certain number of values. But instead of building and returning an array that contains all the wanted values, a generator returns them one at a time, this saves memory and allows the caller function to start processing the first few values immediately.
Pro The Dart to JavaScript compiler generates high quality source code
Dart to Javascript compiler (dart2js) generates very high quality source code with very high optimization. The output code is also very readable and easy to understand.
Pro Crossplatform
Dart does not just compile to JavaScript, it also compiles to native code on mobile platforms like iOS and Android as demonstrated by flutter.io
Cons
Con Poor adoption even after many years of existence
There's a widely accepted perception of D as a language that has been poorly adopted. Since adoption is driven by perception this becomes a fact. So managers and engineers start becoming nervous in adopting a language that has such a perception among the community and that has been so unsuccessful for so long.
Con Failed at becoming alternative to C or C++
Almost as confused and complicated as C++, but without the popularity and widespread corporate usage. Also failed at becoming a good cross-platform GUI application development language like Object Pascal. Many missed past opportunities, and now newer languages are better alternatives.
Con Lack of vision
D is community-driven and lacks the support of any large corporation. While this increases the amount of talent and engineering abilities of the people working on D, it also brings a severe lack of charisma, leadership and vision.
Con Garbage Collection
Memory is not managed directly.
Con All the downsides of garbage collection without any of its benefits
When D decided to implement garbage collection it instantly alienated a large community of developers (C and C++ programmers). For them, the official policy has been: "Don't want garbage collection? Use D with RAII or manual management style!".
While true, it's also absolutely pointless because there's little to none support for alternate memory management styles in the standard library, which means that a new user will have to start with a language that is stripped down of the core infrastructure.
On the other hand, for those people who want to use garbage collection, the implementation of it is lackluster.
Con Doesn’t generate consumable JavaScript at present
Dart builds to JavaScript but the entire app needs to be built to JavaScript at once for now (that may change in the future).
Con Still many holes to fill while converting code to Javascript
While implementing callbacks, passing a type to any function that gets passed to Javascript causes the dart2js compiler to crash.
Con Dart SDK does not provide standard (out of the box) way to access SQL-based databases on server side
This missing (but very popular) feature requires to use 3rd-party packages developed by the personal enthusiasts or very small groups of enthusiasts, which is not very convenient because they are all very fragmented in terms of content, the essence and capabilities.
Con Small community, little momentum
Con May be difficult to use some JavaScript libraries
Dart is much more than a programming language, it's a platform with its own standard libraries and tools. It's a major departure from JavaScript itself (even though it can compile to JS) that it's not possible to directly interact with JavaScript libraries in Dart. Instead, you have to use a special interop library which exposes the wrapped versions of the JavaScript objects that you are accessing.
While this enables Dart to sandbox JavaScript so that its problems do not leak into a Dart application, it also means that it may be cumbersome to use libraries which don't have a wrapper library available.