As my first major project using Scala hits production without too much of a hitch, I present a small list of notes that summarizes my experience with the language:
- Learn to embrace functional programming. I learned this early on that while Scala is able handle object-oriented programming quite well, it's built with functional programming in mind. This means learning flatMap/map, immutables, et cetera.
- Learn the thin cake pattern.
- For every XML library available, there are about 3,781 JSON libraries available. If you're using XML a lot in your project, I feel that Java 8/10 is still easier.
- Jackson is still king of JSON serialization. Is it the fastest? No. Is it the leanest? Not by a long shot. We used a lot of POJOs that rely on serialization, and we've tried a lot of JSON libraries, and while others are faster, they have soul-crushing limitations that were not present with Jackson.
- blocking > non-blocking. Whoever tells you that you should use
Future
and async as much as possible should be greeted with doubt--especially when he uses terms like "reactive" or "reactive streams" and "back pressure". I'm not saying you should only write blocking code, but it should never be treated as a magic bullet; async will never make your shitty app run faster. For one, async code are much more difficult to debug; it's hard enough to deal with one stacktrace. If you need to write async code, you should be using Monix Tasks as it allows you to evaluateFuture
s lazily, and it has bunch of features that allows you to write async code that is easy to reason about. - Scala is a JVM language, therefore object monitor locks are still a pain. If you're a backend Java developer and you're still not using YourKit you are wasting hours of your life hunting down bottlenecks of your application.
- It's maddenning how some third-party library tend to abuse Scala operator overloading. Yes, i'm looking at you Slick
- Maven is miles better than SBT. SBT is slow and it has a steep learning curve. This is compounded when you are using a lot of macros. It's gotten better with 1.x, but still slower than a comparable Maven-based project.
- Type inference and implicits are something you'll hate at first but once it clicks, they are hard to live without.
- It's hard to go back to Java 7 and earlier. I had to maintain a relatively old project that uses Java 7, and if it wasn't for Google Guava, writing code would have been really painful.