Why Scala seems difficult but really isn’t

When I learned C++ and Java a long time ago, I loved Bruce Eckel’s books Thinking in C++ (two volumes) and Thinking in Java .
They had very clear and detailed explanations and I learned a lot from them. So I value his opinion. Bruce also often wrote very positively about Python, a language I like a lot.

A few days ago, he published a great article about Scala:

Scala: The Static Language that Feels Dynamic”

It is a very interesting article which shows that Scala is not complex – at least not more complex than Java. He writes “… Scala should be a lot easier than learning Java!”.

I agree. When you use the subset of Scala that let’s you do with Scala what you can do with Java, it is not more difficult at all, probably even easier than Java.

Here are a few reasons why I think Scala seems more difficult:

1) Programmers think they can master Scala within a few days or weeks

Programmers are used to Java and learning something new is always an effort. Not everyone is willing to really make the effort. To truly master Java, it takes years of practice. Some programmers think after programming in Java for 10 years or more, they should become as proficient in Scala as they are in Java within a few weeks. But that’s not how it works, no matter how easy a language is. You can write simple or even somewhat complex programs in Scala after a few days studying it, but to truly master it, it will take a lot of time and effort. But this can be very rewarding. I am still relatively new to Scala and don’t claim to be an expert or even understand everything about the language. But when I play with it, learn or read something about, I always have fun and learn something. But I know to give it time to become an expert. If you just started with Scala, give it time. When you are stuck, ask on the mailing lists or try a different website or book with explanations. Don’t give up. Even if you end up not liking Scala very much, you will definitely become a better programmer by learning it.

2) Programmers don’t know anything or not much about functional programming

Java is not a functional programming language. If a programmer has been using mostly Java and C++ for the last years, he may have created great software with Java in an object oriented way. This works great with Java and there is absolutely nothing wrong with that. I love Java and OOP is a great way for building software. But when people start playing with Scala they are also confronted with functional programming. You can do Scala in a pure OOP way but you will get more out of the language if you also master functional programming (FP). Because most programmers don’t have much experience with it, it seems very difficult and strange at first. But like I wrote above, you will have to give it some time to really understand it. It will be worth it and you will even think differently about your Java code when you’ve played more with high order functions, closures and recursion. FP is not always better or worse than OOP. It is another tool that is good to have in your toolbox. Sometimes FP is a better fit, sometimes OOP and sometimes a combination. This is why Scala supports both.

3) Many Scala websites are blogs can seem intimidating to beginners

When someone is really good at a language, he or she often want’s to show it. This is why Ruby sometimes looks very complicated when a Ruby guru writes a blog post with 50 lines of code and 10 different meta programming techniques within them.
The same is true for Scala. In many blog posts and websites, you find stuff about Monads, advanced FP, very concise but not necessarily very readable code and other things you won’t need in your daily business and other stuff that is way too confusing for a beginner.
This can be and sometimes is very intimidating for beginners who just want to read a file with Scala.
That doesn’t mean I don’t like those blogs, but I think the Scala community should publish more simple stuff.

4) Lack of a good cookbook for Scala

Many programmers learn by examples of how to do everyday tasks like opening files, sending an emails or building a socket server. For many languages there are great cookbooks with hundreds of recipes about how to do that. Such a book does not yet exist for Scala. I think it could really help to bring even more people to this wonderful language.

Conclusion: Scala is not difficult – just keep on learning

This are just a few reasons why I think Scala sometimes seems more difficult than it really is. If you don’t know Scala yet, I highly recommend reading Bruce Eckel’s article mentioned above.
If you already know some Scala but struggle a bit to grasp some of it’s concepts, keep on learning. As I wrote, you cannot become a Scala expert within 3 weeks. Keep pushing until you are comfortable with Scala and you will very likely really love it. And if you don’t you will nonetheless have learned a lot. (Btw, this holds true for all languages).

Leave a comment ?

12 Comments.

  1. I think you are 100% correct in regards to learning and investment of time. I would argue that is not necessarily true for any language switch (but it is the case with Scala or say C++.)

    The counter argument here is this: Going forward on the JVM, we developers want a suite of languages ranging from scripting to something like Java. Functional is fine; it is not an issue as Clojure has proven.

    To have this plentiful toolkit, we need focused languages that let us get things done and which do not demand a huge investment of time before they are used effectively. And no, Scala is not a Java replacement. Java is not cryptic.

    • You don’t have to invest a lot of time to use scala effectively.
      Using case classes, lesser typing for simple classes, tuples as return values and filter/map/ etc.. builtin collection classes actually make you more productive after 2 days of intensive reading/testing (repl!).
      Tooling is now also there – finally!.
      The only problem is java collection interoperability.
      There are now unfortunately 2 ways to do this in the scala library.

      The rest will follow.

  2. I think Scala will definitely get there. It’s a great language. I would have to disagree with Java not being cryptic. Starting with Scala, it can be a head scratcher trying to piece together how to integrate a third party library.

    Which, lets be honest is the whole point to Scala. It is to be able to use those third party libraries but in a better way. Java is so verbose it is a hairpull to try to figure out how to integrate a new library without really digging into it. YMMV.

    By the time you really dig into the library it feels as if you might as well have written it yourself. It often doesn’t feel like the blackbox upon which you feed some information and wait for a result.

    I have found the Scala-centric libraries relatively refreshing and easy to work with.

  3. Great post! I’ve personally experienced these exact reasons and would like to elaborate on how I’ve overcome much of reasons 3 and 4.

    I especially struggled with reason 3 because I found many of the “introductory” sites and books present examples that use unfamiliar syntax and concepts without really elaborating on them. E.g. partially applied functions. I’ve found the book Programming in Scala Second Edition (Updated for Scala 2.8) very helpful. Not only does it fit my learning style, it does an excellent job presenting the concepts it is currently discussing. If a feature of the language is presented before it is covered the authors explicitly mention it will be covered later and provide the reader with that section in case they want to explore it right then. Let me caveat my praise by mentioning I do have a Java background so if one is coming from a different language this book may not be as helpful.

  4. @davenatx: I agree that Programming in Scala 2nd edition is an awesome book and I also agree that previous Java knowledge definitely helps. This is not a beginners book.
    Cay Horstmann, author of the wonderful Core Java and Core JSF books is currently working on a book called “Scala for the Impatient” which is scheduled for November 2011 according to amazon.com. This probably will be a great to learn Scala once available.

  5. Hey Markus,

    great blog. I agree with all four points! Nevertheless, two more comments:

    1) “When you use the subset of Scala that let’s you do with Scala what you can do with Java, it is not more difficult at all, probably even easier than Java.”

    That may be true, but here your third point comes in: Not only blogs, but also most books use too complicated examples. Besides, you can look at code of open source projects. In Java, you could learn from such code, in Scala you do not understand anything (I tried this by myself when I started with Scala – I looked at Scala code of Apache Camel and did not understand any one code line).

    It is very difficult to start as beginner due to stuff like own DSLs, several solutions for method syntax, and so on.


    2) In my opinion, the killer argument against Scala still is the bad IDE support! Yes, IDEA works great in the meantime, but about 95 percent (I guess) use (or have to use) Eclipse in their enterprise projects – as I do. I hope that Odersky can speed up the development of the Scala Eclipse plugin even more…


    Nevertheless, I really like Scala and hope that it will be used more in future projects!


    Best regards,
    Kai Wähner (Twitter: @KaiWaehner)

  6. @Kai: I agree about the IDE support. There is still room for improvement for the Eclipse plugin although I think it already is much better than it was about 6 months ago.

    I also hope the Netbeans plugin continues too improve. It is not bad but not yet a match for the Java part.

  7. Hopefully NetBeans takes advantage of the lack of cookbooks and do something with the plugin that is in the community hands right now…

  8. Bruce Fancher

    I recently asked the author of a book on Scala to compare and contrast the experience of using Scala with the experience of using Clojure. He said that with Clojure, all the pain of the learning curve was up front, while with Scala, every time you thought you’d climbed the learning curve, you’d run into something that would drag you back down again.

    Scala is a very impressive piece of engineering, but it’s just too damn complicated. Just learn and use Clojure instead. If you have any doubts about why you’d want to learn and use a Lisp, read Paul Graham.

  9. if you want a simple and powerful language, try REBOL.

    http://www.rebol.com

    There is also another promising language RED

    http://www.red-lang.org/2011/07/redsystem-goes-beta.html?m=0

  10. I think you are 100% correct in regards to learning and investment of time. I would argue that is not necessarily true for any language switch (but it is the case with Scala or say C++.)

    The counter argument here is this: Going forward on the JVM, we developers want a suite of languages ranging from scripting to something like Java. Functional is fine; it is not an issue as Clojure has proven.

    To have this plentiful toolkit, we need focused languages that let us get things done and which do not demand a huge investment of time before they are used effectively. And no, Scala is not a Java replacement. Java is not cryptic.

  11. Regarding point #2 – I think you mean that Java is a purely imperative language and that is the biggest difference between it and Scala. Scala is an OOP language through and through, but the diffence between the imperative and functional paradigm is the primary difference between Java and Scala.

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Current ye@r *

WP-SpamFree by Pole Position Marketing