When comparing Ruby vs Haskell, the Slant community recommends Ruby for most people. In the question“What is the best programming language to learn first?” Ruby is ranked 5th while Haskell is ranked 26th. The most important reason people chose Ruby is:
Ruby has a very clean syntax that makes code easier to both read and write than more traditional Object Oriented languages, such as Java. For beginning programmers, this means the focus is on the meaning of the program, where it should be, rather than trying to figure out the meaning of obscure characters. presidents = ["Ford", "Carter", "Reagan", "Bush1", "Clinton", "Bush2"] for ss in 0...presidents.length print ss, ": ", presidents[presidents.length - ss - 1], "\n"; end
Ranked in these QuestionsQuestion Ranking
Pro Clean syntax
Ruby has a very clean syntax that makes code easier to both read and write than more traditional Object Oriented languages, such as Java. For beginning programmers, this means the focus is on the meaning of the program, where it should be, rather than trying to figure out the meaning of obscure characters.
presidents = ["Ford", "Carter", "Reagan", "Bush1", "Clinton", "Bush2"] for ss in 0...presidents.length print ss, ": ", presidents[presidents.length - ss - 1], "\n"; end
Pro A large ecosystem of tools & libraries
Ruby has a large ecosystem of tools and libraries for just about every use. Such as ORMs (Active Record, DatabMapper), Web Application Frameworks(Rails, Sinatra, Volt), Virtualization Orchestration(docker-api, drelict), CLI tools(Thor, Commando), GUI Frameworks(Shoes, FXRuby) and the list goes on. If you can think of it, there is probably a gem for that ( and if not you can create your own and share with the community).
Pro Widely used
Ruby is one of the most popular languages for developing web sites. As a result, there's an abundant amount of documentation, sample code, and libraries available for learning the language and getting your project up and running. The most popular features are just 'gem install' away. Additionally, it is easier to find Ruby jobs because of this.
Pro Ruby on Rails
Lays out an easy to follow and opinionated MVC pattern that teaches best practices through necessity.
Pro Newbie-friendly community
Pro Hugely object oriented
Object oriented programming is one of the most important concepts in programming.
Pro Test Driven Development, #1
It's the fore-runner and trend setter for TDD.
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 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 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 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 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 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 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 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 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 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 Powerful Categorical Abstractions
Makes categorical higher order abstractions easy to use and natural to the language
Con Its ecosystem is limited outside of web development
If you're looking to host, generate, manipulate or secure a website, Ruby is your language. There's also some great support here for infrastructure as code work via Chef. However, it just doesn't have the depth and breadth that Python does. Things like native UI development, high performance math, and embedded / small footprint environments are barely supported at all in Ruby-space.
Con Meta-programming causes confusion for new developers
The ability for libraries to open classes and augment them leads to confusion for new developers since it is not clear who injected the functionality into some standard class.
In other words, if two modules decide to modify the same function on the same class can introduce a number of issues. Mainly, the order in which the modules are included matters. Since you more or less can't tell what kind of "helper" functions a module might write into any class, or for that matter, where the helper function was included from, you may sometimes wonder why class X can do Y sometimes but not at other times.
Requiring a library can change the rules of the language. This is very confusing for beginners.
Con No docstrings
It's hard to access Ruby's documentation from the REPL (irb), unlike Python, Lisp, and Smalltalk which let you ask functions how to use them, which is a great benefit to the beginner, and which also encourages you to document your program as you code it.
Con Arcane grammar based on Perl
Ruby is too complicated for beginners:
- arcane Perlisms;
- semi-significant whitespace;
- parentheses are not necessary around method arguments, except for sometimes they are;
- control constructs could be elegantly implemented with block like Smalltalk (Instead they're baked into the grammar.);
- verbose block syntax, unless it happens to be the last argument. (proc lambda).
- There are too many exceptional cases and arcane precedence rules.
Con More than one way to do it
A problem inspired by Perl. The core API interfaces are bloated. There's at least four different ways to define methods. More is not always better. Sometimes it's just more.
Con Dynamic type system
Majority of bugs could be resolved with types.
Con Viewed as a web development language
Despite its flexibility and performance, Ruby is often seen as being unsuitable for other tasks by those who are not familiar with it. As such, a lot of discussion about it centers around Rails, which is not at all relevant if you're using Ruby for something else, such as game development.
Con Does not teach you about data types
Since Ruby is a dynamically typed language, you don't have to learn about data types if you start using Ruby as your first language. Data types being one of the most important concepts in programming. This also will cause trouble in the long run when you will have to (inevitably) learn and work with a statically typed language because you will be forced to learn the type system from scratch.
Con Focus on Object-Oriented Programming (OOP)
Focussing on OOP in a beginner stage is an easy and popular plan, but not the best one.
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 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 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 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 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 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 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.