Sunday, January 20, 2013

Why Scala Becomes So Popular?

This article is intended for developers who have an agenda to learn at least one programming language in a year. I recommend them to go for Scala this year. Also I strongly believe Scala can become the next best programming language. Here are the reasons.
  1. Scala runs on JVM; takes all the advantages of JVM. Scala is platform independent, object oriented and strongly typed.
  2. Scala has well structured type system than Java. Scala uses unified type system as in C#. For an example, all the types are derived from the base type “Any”. “Nothing” is a subtype of everything and not super type of anything.
  3. Scala syntax is similar to Java. Scala is easier to learn than any other functional language.
  4. You don't have to worry about third party tools for Scala. Third party tools and libraries for Java are matured. Almost all the Java development tools can also be used for Scala. For an example, JUnit can be used as unit testing framework for Scala.
  5. Scala is functional. Functional languages are suitable for scalable architectures. In theory functional languages don't allow to alter the variable's state. All the variables are immutable. (In that way, Haskell is a pure functional language, you can't change the state at all.) The advantage of immutability is thread-safe. You can apply parallelism and threading concepts even if the system is so big and rapidly increasing in size. Scala gives good support for concurrency.
  6. Scala has very good open source IDE supports. I prefer to use Eclipse plug-in for Scala. IntelliJ IDEA from JetBrians is also a good one. The community edition of IntelliJ IDEA is free. Visual Studio plug-in for Scala is also available here.

Comparison with other functional languages

  1. Haskell is another powerful functional language, but it needs a deep learning curve. It doesn't have proper open source editor. The third party tools and libraries for Haskell are not matured enough. Building and installing GHC (Glasgow Haskell Compiler) is very harder than Scala installation.
  2. Though Python is matured and functional, Python has limited support for functional paradigm. Python is not considered for enterprise systems. One of our products in Python didn't scale and faced severe performance problems. Python is suitable for string manipulation or string search based applications. Python is best suited for dynamic programming, so comparing Scala with Python is not fair. (My guess is Groovy may overtake Python in near feature. Groovy also runs on JVM.)
  3. Like any other functional languages Scala compiler supports type erasure and type inference. Checked exceptions in Java is annoying. This is eliminated from Scala. Scala has a lot of developer friendly improvements from Java.
  4. Like F#, Scala also supports multi-paradigm (functional and imperative). One of the reason F# seems to be scary to me is its syntax. Scala syntax is similar to Java, But F# syntax is not similar to C#. See Here. Scala is much more minimalistic language than F#. Scala has a very small orthogonal set of constructs that are re-used throughout the language. F# seems to introduce new syntax for every little thing, thus becoming very syntax heavy as compared to Scala. Scala has 40 keywords, whereas F# has 97”.
  5. Also you can find currying, tuples, anonymous functions, pattern matching and lazy evaluation in Scala.

Clojure is also getting popular. Since I don't have knowledge on Clojure or LISP, I can't compare with Clojure.

Any talk on languages is controversial, the above points are my personal views. I welcome your feedback.