Sunday, November 18, 2012

Should You Learn Scala?

It depends on what you want to accomplish*, but the answer is probably yes.

By way of background, Scala is a programming language originally developed at the Swiss university EPFL in an attempt to apply recent innovations in programming languages research to a language that can gain mainstream traction.  Researchers keep coming up with clever ways to it easier for programmers to write correct code and to write less code, but much of the time only academic programmers benefit because these features are implemented in boutique languages (for instance, OCaml and Haskell) that are not in widespread use in industry or open source projects.

On its own, without considering features such a libraries and interoperability, Scala is a nice language.  It is "multi-paradigm," supporting object-oriented programming and functional programming idioms.  Scala allows you to define types associated with both data attributes (with classes behaving like C++/Java classes) and behavior attributes (with traits corresponding to Java interfaces).  In the way of functional programming idioms, Scala functions are first-class (which means you can pass them around as values) and Scala also supports anonymous functions and currying (partial application of multi-argument functions).  This combination of features make it possible to write Scala programs that are quite concise and elegant**.

Scala's libraries and interoperability make it a force to be reckoned with.  Scala runs on the Java Virtual Machine (JVM) and can interoperate nicely with Java code.  This means that you can use Java libraries directly from Scala code.  It is also possible to call Scala code from Java (see here).  There is a nice post about how you can take advantage of Scala parser combinators, which use higher-order functions to help you write concise parsers, to write parsers for systems otherwise written in Java.  Not only can you do all of the things in Scala, you can easily write part of your program in Scala and the rest in Java.  (This is huge for mainstream adoption potential because so much of the world's code is written in Java and so many developers are taught in school!)

Learning Scala will make you more marketable.  Many companies are using Scala these days, including LinkedIn, FourSquare, Twitter, and Quora.  The founders of Quora spent a couple of months building a Scala web framework in order to use Scala.  Martin Odersky, the man behind Scala, is now behind the startup Typesafe for supporting Scala development.  There are some nice Scala web frameworks out there, including Lift and Play.  Scala is also gaining traction in the research community.  Many more people cared about our research on the Jeeves programming language for automatically enforcing privacy policies once we implemented it as an embedded domain-specific language in Scala.

Scala is also relatively easy to learn, especially compared to other strongly statically typed languages (OCaml; Haskell).  I have previously said that Python is the most marketable language for beginners, but I am beginning to change my mind.  Like Python, Scala has clean syntax, nice libraries, good online documentation, and lots of people in industry using it.  Unlike Python, Scala also has a static type system that can prevent you from doing bad things (whereas in Python the bad things just happen when you run the program).

If you are teaching a course using Java, you may want to consider switching to Scala.  I have recently had positive experiences teaching Scala to MIT undergraduates during recitation in 6.005, the software construction course taught primarily in Java.  During three recitations I introduced how to use functional idioms, how to build an evaluator for a simple language by using data types and pattern matching, and how to build an incredibly concise parser for the tiny language using parser combinators.  You may find my notes here, along with the accompanying code examples.

If you are considering the merits of Scala over other languages, you may also be interested in reading my Quora responses to the questions "What makes a good programming language?" and What are the advantages of Scala over C++ and Haskell?.

* If you are building scientific applications, a language with more math support (Matlab; Mathematica; R) may be superior.  If you just want to do a weekend project writing a Craigslist scraper, Python may be better because it is easier to learn and has great web scraping libraries.
** Okay, Scala programs are not as beautiful as OCaml or Haskell (I have another post on ML vs. Haskell) but it's so much more practical in many ways.


Clement Levallois said...

2 questions:
- Would your recommend a book or textbook for somebody coming from Java?
- and a book / or any source that would focus on the advantages of Scala for server side programming (I use JSF, why should I be interested in Scala?)
Thx a lot!

Jean said...

Here are some useful links for learning Scala from Java:

You may be interested in learning about the Play MVC framework:
There is a book with an early access edition about it:

Clement Levallois said...


christi parks said...

Hello, sir i would like to ask that what is the scope of java training, what all topics should be covered and it is kinda bothering me … and has anyone studies from this course of core and advance java online ?? or tell me any other guidance...
would really appreciate help… and Also i would like to thank for all the information you are providing on java concepts.

Mark Lewis said...

Great post. I love that you mention Scala as an option for introductory programming. I have been using it as the exclusive language of instruction for CS1 and CS2 at Trinity University since Fall of 2010 and I love how it works. Since there wasn't much material out there for that purpose I wound up writing a lot myself and it turned into this,

Nghia Huynh Trong said...

I do know that Scala is based on Java. So I would like to ask you whether I need to learn Java first, if not is there any diffculties?

Jean said...

You should not have to learn Scala first to learn Java. It may be useful to know some Java if you want to access Java libraries.

Randy said...

Hi Jean, really great article. I was just wondering what your thoughts are on how well scala stacks/compares against c#? Do you think scala will actually be a "successor" to java as some are claiming? And if it is a successor to java, which language do you think has a brighter future, c# or scala? also, which one do you think is more object oriented or has a better OOP model, c# or scala? thanks and sorry for all of these questions.

heena goyal said...

Very informative information provided.
Is online training reliable?
I have never taken any but these days if you want to study from the best teachers online learning is best. So i have decided to do my online java training course from as one of my friend recommended me this site. I don't know how is it going to work for me so if anybody have studied from this site please let me know .

sudheer said...

The information which you have provided is very good and easily understood.
It is very useful who is looking for java Online Training.

Anonymous said...

Indeed Java dev should now look to Scala. This article has covered some difference between Scala and Java and also shared few resources to learn Scala.

prabodh said...

I am from C++ background and do not know Java. DO you think I should go for Scala or learn Core Java first and then think of Scala?

Bala Murugan said...

This really useful this blogs i like it,CompTIA CASP Training VA
|CEH Training Fairfax VA

syed s said...

I was reading your blog this morning and noticed that you have a awesome
resource page. I actually have a similar blog that might be helpful or useful
to your audience.

sap sd and crm online training
sap online tutorials
sap sd tutorial
sap sd training in ameerpet

kits online said...

kits online trainings provides best online training for all it technologies

Ruby On Rails Training

SAP XI Training

OBIEE Training

Talend Training

PHP Training

Ravindra Reddy said...

Best kits online trainings,thanks for sharing

SAP Success Factors Online Training institute

SAP WebDynpro Online Training institute

SCCM 2012 Online Training institute

Selenium Online Training institute

Solaris Online Training institute

kits online said...

very nice article.Thanks for sharing the post..!
Oracle Golden Gate Online Training By Real Time Faculties

Ruby Online Training By Real Time Faculties

SAP XI Online Training By Real Time Faculties

OBIEE Online Training By Real Time Faculties

Talend Online Training By Real Time Faculties

PHP Online Training By Real Time Faculties

Coy Currin said...

Thanks for nice topic. I like it. We are Providing Online Training Classes. SAPMMonlinetraining

Anonymous said...

kits online trainings provides best online training for all it technologies
SCOM 2012 Online Training Institute

SAP Bw Hana Online Training institute

Oracle SOA Online Training institute

for IT the said...

Online Java Training | Online Java Training India | Online Java EE Training | Online Java EE Training India | Online Java Training Institutes

for IT the said...

Online Java Training | Online Java Training India | Online Java EE Training | Online Java EE Training India | | Online Java Training Institutes

Karthika Shree said...

It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command.
Java Training in Chennai

KarlDeville said...

Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point. | |

suresh H said...

AngularJS Training Institute in Chennai
AngularJS Cetification Training in Chennai
AWS Training in Chennai
AWS Devops Training in Chennai
Best AngularJS Training in Chennai
AngularJS Training in Chennai

Praveen said...

Nice article
artificial intelligence online training
python online training
talend online training

Upender said...

Nice blog this informations is unique information i haven't seen ever by seeing this blog i came know lots of new things
those are very useful tom me i will suggest the peopele who are looking this type of information
python training in hyderabad the best career

upender anagandula said...

nice blog thank you for sharing wonderful information
python training in Hyderabad the best career

Roja Priya said...

Great efforts put it to find the list of articles. thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
Angular JS Training in Chennai | Angular JS Training in Velachery

Alister cook said...

I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.

aws training in chennai

advanced aws training in chennai

Prasad Gowtham said...

Great post! Thanks for sharing with us, Its really gives lot of useful information. Regards,

Angularjs Training in Chennai

samala swathi said...

This concept is a good way to enhance the knowledge.thanks for sharing. please keep it up
core Java online training Hyderabad

SRI said...

Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.

rpa training in marathahalli

rpa training in btm

rpa training in kalyan nagar

rpa training in electronic city

rpa training in chennai

rpa training in pune

rpa online training

Ram priya said...

The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.
Data Science training in chennai
Data science training in velachery
Data science training in tambaram
Data Science training in OMR
Data Science training in anna nagar
Data Science training in chennai
Data science training in Bangalore
Data Science training in marathahalli

Deepika Analy said...

Great Article...Thanks for sharing the best information.It was so good to read and useful to improve my knowledge as updated one.

Mobile Apps Training
Mobile Apps Training in Chennai