"I've noticed several times when someone says ‘X really changed the way I think about programming,' frequently X=Haskell.”
Andrew Binstock, editor-in-chief, Dr. Dobb's
The change in mindset Andrew is talking about has been experienced by many developers as they discover and apply Haskell, describing a true "aha” moment…a feeling that this is the way software development should be.
What Makes Haskell Different?
Haskell is a pure (actually, the purest) functional programming language. It has been in development for more than 20 years. Haskell programs are a series of high-level generalizable functions that define what the program is intended to do, and the language hides the mundane low-level details such as iteration. A strong static type-safety and inference system produces code with few side effects. The programmer focuses on results rather than articulating a lengthy series of steps. The compiler produces clean, concise, and correct code from the outset. If the code compiles, it works (almost all the time)! Contrast this with Ruby, for example, where the test code can be 2-3 times the size of the app, and even then, one is not quite sure if the runtime code is correct.
While it really shines in complex and unique analyses, Haskell can show its essential nature even in a simple snippet. Let's create a list of all even numbers up to 100, and another list omitting the first five of them.
|The program written in Java||The program written in Haskell|
It is immediately clear that with Haskell, you can understand what's going on; whereas in Java, or any imperative language, you can barely tell what the code is supposed to do because you are overwhelmed with the low-level minutia. This effect increases as programs grow more complex. From this simplicity and abstraction flow most of Haskell's advantages.
Because of these benefits, Haskell has an excellent reputation among developers who use the language. Comments from more than 3,000 Haskell programmers gathered by Hammer Principle indicate that Haskell is most liked for its type system; the confidence it creates that if the code compiles, then it is correct; and for the language's intrinsic elegance.
Improving the Economics of Software Development
While software drives the innovation economy, billions of dollars are wasted on project failures, bug fixes, and maintenance errors. Surveys and studies have consistently shown that 50%-75% of software projects are consumed by bug fixes and maintenance. One root cause of this problem is the use of current mainstream, imperative languages whose manual, low-level approach is error-prone and likely to generate spaghetti code when patched enough times.
This problem is well known but perpetuated because the vast majority of programmers, managers, and even journalists just believe "this is the way things always are." They try to improve around the edges with better testing tools, Agile, etc. But these aren't root solutions: They are workarounds. Poorly designed code in any language is a problem, but Haskell eliminates the spaghetti code via its type system, high-level syntax, and readability. Says one Haskell project leader, "We could revisit what we wrote in Haskell more than two years before and know exactly what was going on." This is difficult, if not infeasible, for most programs in Java, C++, Python, and other imperative languages.
Haskell's Sweet Spots
Algorithmic domains fit Haskell's algebraic and logical foundations well, as do problems that require parallel solutions. It is increasingly being adopted in enterprises, especially in data-intensive industries and domains such as financial services, big data applications, Big Pharma, and biotech, oil and gas, and consumer data.
Another important Haskell benefit is performance and its fast prototyping capabilities. The huge difference with other fast prototyping languages such as Ruby and Python is that a Haskell prototype can become the real app and stand the test of time due to its conciseness and correctness. A Ruby hack is easy to do, but gets you a lifetime of headaches down the road as you grow. For a startup, this accelerated time to market can be significant especially in light of the reduction in repetitive testing and debugging.
The New York Times recently used Haskell to present Fashion Week, a processing-intensive app that used numerous images and required massive amounts of analysis. The lead developer on the project, Erik Hinton, wrote, "We chose Haskell because we anticipated doing a large amount of fine-tuning to get the analysis to work well." Compared with the Ruby prototype, the Haskell code with the Repa library ran 100X faster, in part because "the mathematical assurances made by Haskell's type system meant they could automatically parallelize the operation over multiple CPU-cores without changing a single line of code."
Consequently, if a high-level language that defines processing in terms of intended outcome, rather than through elaboration of individual operations; compiles to fast, native code; and is easy to parallelize fits your needs, I suggest Haskell might just be the language you're looking for.
Aaron Contorer is the CEO of FP Complete, a company that specializes in tools for Haskell developers. Earlier, he was at Microsoft, where he worked on the Visual Studio product and served as a technology adviser to Bill Gates.