When comparing D vs Haskell, the Slant community recommends Haskell for most people. In the question“What is the best programming language to learn first?” Haskell is ranked 26th while D is ranked 28th. The most important reason people chose Haskell is:
Haskell's referential transparency, consistency, mathematics-oriented culture, and heavy amount of abstraction encourage problem solving at a very high level. The fact that this is all built upon little other than function application means that not only is the thought process, but even concrete solutions are very transferable to any other language. In fact, in Haskell, [it's quite common for a solution to simply be written as an interpreter that can then generate code in some other language](http://programmers.stackexchange.com/questions/242795/what-is-the-free-monad-interpreter-pattern). Many other languages employ language-specific features, or work around a lack of features with heavy-handed design patterns that discourage abstraction, meaning that a lot of what is learned, and a lot of code that is needed to solve a particular problem just isn't very applicable to any other language's ecosystem.
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 Highly transferable concepts
Haskell's referential transparency, consistency, mathematics-oriented culture, and heavy amount of abstraction encourage problem solving at a very high level. The fact that this is all built upon little other than function application means that not only is the thought process, but even concrete solutions are very transferable to any other language. In fact, in Haskell, it's quite common for a solution to simply be written as an interpreter that can then generate code in some other language. Many other languages employ language-specific features, or work around a lack of features with heavy-handed design patterns that discourage abstraction, meaning that a lot of what is learned, and a lot of code that is needed to solve a particular problem just isn't very applicable to any other language's ecosystem.
Pro Forces you to learn pure functional programming
It is pure and does not mix other programming paradigms into the language. This forces you to learn functional programming in its most pure form. You avoid falling back on old habits and learn an entirely new way to program.
Pro Open source
All Haskell implementations are completely free and open source.
Pro Mathematical consistency
As Haskell lends itself exceedingly well to abstraction, and borrows heavily from the culture of pure mathematics, it means that a lot more code conforms to very high-level abstractions. You can expect code from vastly different libraries to follow the same rules, and to be incredibly self-consistent. It's not uncommon to find that a parser library works the same way as a string library, which works the same way as a window manager library. This often means that getting familiar and productive with new libraries is often much easier than in other languages.
Pro Referentially transparent
Haskell's Purely Functional approach means that code is referentially transparent. This means that to read a function, one only needs to know its arguments. Code works the same way that expressions work in Algebra class. There's no need to read the whole source code to determine if there's some subtle reference to some mutable state, and no worries about someone writing a "getter" that also mutates the object it's called on. Functions are all directly testable in the REPL, and there's no need to remember to call methods in a certain order to properly initialize an object. No breakage of encapsulation, and no leaky abstractions.
Pro Hand-writeable concise syntax
Conciseness of Haskell lets us to write the expression on the whiteboard or paper and discuss with others easily. This is a strong benefit to learn FP over other languages.
Pro Very few language constructs
The base language relies primarily on function application, with a very small amount of special-case syntax. Once you know the rules for function application, you know most of the language.
Pro Quick feedback
It's often said that, in Haskell, if it compiles, it works. This short feedback loop can speed up learning process, by making it clear exactly when and where mistakes are made.
Pro Functions curry automatically
Every function that expects more than one arguments is basically a function that returns a partially applied function. This is well-suited to function composition, elegance, and concision.
Pro Easy to read
Haskell is a very terse language, particularly due to its type inference. This means there's nothing to distract from the intent of the code, making it very readable. This is in sharp contrast to languages like Java, where skimming code requires learning which details can be ignored. Haskell's terseness also lends itself to very clear inline examples in textbooks, and makes it a pleasure to read through code even on a cellphone screen.
Pro Popular in teaching
Haskell is really popular in universities and academia as a tool to teach programming. A lot of books for people who don't know programming are written around Haskell. This means that there are a lot of resources for beginners in programming with which to learn Haskell and functional programming concepts.
Pro Easy syntax for people with a STEM degree
Since the basic syntax is very similar to mathematics, Haskell syntax should be easy for people who have taken higher math courses since they would be used to the symbols used in maths.
Pro Powerful categorical abstractions
Makes categorical higher order abstractions easy to use and natural to the language.
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 Language extensions lead to unfamiliar code
Haskell's language extensions, while making the language incredibly flexible for experienced users, makes a lot of code incredibly unfamiliar for beginners. Some pragmas, like NoMonomorphismRestriction, have effects that seem completely transparent in code, leading beginners to wonder why it's there. Others, like ViewPatterns, and particularly TemplateHaskell, create completely new syntax rules that render code incomprehensible to beginners expecting vanilla function application.
Con Difficult learning curve
Haskell lends itself well to powerful abstractions - the result is that even basic, commonly used libraries, while easy to use, are implemened using a vocabularly that requires a lot of backround in abstract mathematics to understand. Even a concept as simple as "combine A and B" is often, both in code and in tutorials, described in terms of confusing and discouraging terms like "monad", "magma", "monoid", "groupoid", and "ring". This also occasionally bears its ugly head in the form of complicated error messages from type inference.
Con Package manager is unstable & lacking features
Cabal (There are other choices but this is the most popular) can not uninstall a package. Also working at a few locations it is difficult to have the same environment for each one be the same.
Con You have to learn more than just FP
Haskell is not only a functional language but also a lazy, and statically typed one. Not only that but it's almost necessary to learn about monads before you can do anything useful.
Con Symbols everywhere
Haskell allows users to define their own infix operators, even with their own precedence. The result is that some code is filled with foreign looking operators that are assumed to be special-case syntax. Even for programmers who know they're just functions, operators that change infix precedence can potentially break expectations of how an expression is evaluated, if not used with care.
Con Obscure ugly notation
0 = 1
Using "=" like this: <code>
-- Using recursion (with pattern matching)
factorial 0 = 1
factorial n = n * factorial (n - 1) </code> Example from https://en.wikipedia.org/wiki/Haskell_(programming_language)
is quite simply annoying aesthetics.
Con Documentation for most packages is short and lacking
A few Haskell packages are well documented but this is the exception, not the rule.
Most of the time a list of function signatures is what passes for documentation.
Con Too academic, hard to find "real world" code examples
Con You need some time to start seeing results
Haskell's static typing, while helpful when building a project, can be positively frustrating for beginners. Quick feedback for errors means delaying the dopamine hit of code actually running. While in some languages, a beginner's first experience may be their code printing "Hello World" and then crashing, in Haskell, similar code would more likely be met with an incomprehensible type error.
Con Lazily evaluated
Haskell's lazy evaluation implies a level of indirection - you're not passing a value, you're passing a thunk. This is often difficult to grasp not just for beginners, but for experienced programmers coming from strictly evaluated languages. This also means that, since for many, strict evaluation is their first instinct, initial expectations of a function's performance and complexity are often broken.
Con Only pure functional programming
Not proper functional programming but a subset of the style called pure functional programming.