By Oct. 23, 2012 — View Commentson
As a software developer, you need to keep pace with ever-changing programming languages. If you’re anything like me, you want to be on the bleeding edge of new technologies. I’m always looking for the latest, coolest tools or frameworks in order to be more efficient.
About a year ago, I started looking into Scala, a functional programming language that exists in the Java world. Scala has earned recent notoriety thanks to a popular social network: Twitter’s entire social media infrastructure is written in Scala and successfully handles billions of operations every day. Makes you curious about Scala, doesn’t it? So, just what is it?
Scala, in a Nutshell
Scala runs within the Java Virtual Machine and provides a completely different approach to application development. It allows you to interact seamlessly with standard Java libraries while developing from a functional perspective. Initially intended for writing complex back-end systems that are resource-heavy and use shared artifacts, Scala now has more widespread uses.
We found Scala to be the best option for some of our client web and mobile projects, but it's not right for every situation. Before you can decide if you should be using Scala for your project, it’s important to understand the pros and cons of the language and its core strengths.
Scala “Pros”: What makes it great?
In many ways, Scala is a superior language because it relieves many of the age-old, time-consuming Java programming headaches. Key benefits include:
- Simple and straightforward syntax. Scala typically requires two-thirds less code than Java. The syntax is also more flexible. For example, you can leave out periods between method calls so the code is more human-readable and easier to understand.
- Inherently immutable objects. Scala’s programming language reduces many thread-safety concerns that spring up in traditional Java applications.
- Highly functional. Scala treats functions as first-class citizens.
- Fast implementation speed. It allows for quicker implementation and enhanced performance.
- It is fun! Scala challenges strong engineers in a meaningful and entertaining manner, making development more fun.
- Easy to solve concurrency issues. It has an Actor library to solve concurrency problems more rapidly.
- XML support. Scala supports XML, which is beneficial if you have a need to encode documents in your products.
Scala “Cons”: What are the drawbacks?
While Scala does offer significant advantages over traditional Java, there are still some drawbacks and limitations:
- Limited community presence. Since the language is new, there are limited online communities and resources to help you troubleshoot issues. Unlike the Grails or Rails communities, Scala is still gaining followers and experts. If your developers do not have the time to resolve issues themselves, Scala may not be a viable option for you.
- Hard to learn. Syntactically, Scala is significantly different from traditional Java. Furthermore, it presents a completely different programming paradigm—requiring a higher level, more sophisticated developer/engineer skill set to understand it. As a result, Scala developers are in low supply and costly.
- Lack of ease of adoption. When coding with a team, it’s rare to find everyone writing purely in Scala. You need a team of eager adopters for Scala to be feasible. Otherwise, you will end up with code that’s a hybrid of Scala and Java, which can cause problems. Ramp up time can be very slow and time consuming. And it’s very difficult to find/build a team of pure Scala developers.
- Limited backward compatibility. Each major new release of Scala is incompatible with the previous version. This leads to a lot of wheel-reinventing, headaches and product delays. If your development schedule is tight, you should avoid using Scala, for now, to stay on track.
When to Use Scala
Scala is ideal for targeted functional hotspots, complex engineering systems and development environments where you need to:
- Solve concurrency problems
- Perform DSL related tasks
- Implement functional solutions
- Integrate with shared resources, files, databases or multiple backend processes and services
- Learn a new development paradigm
If any of the above characteristics are prevalent in a proposed software solution, then Scala is certainly a good candidate. However, the traditional MVC/ORM frameworks in the industry still work better with traditional web- and database-driven applications. Be forewarned that Scala is not the best choice for basic web applications and websites with forms.
Before questioning whether to use Scala, be sure to get a deep understanding of what needs to be solved. Scala has bright future, but at this point, you should still proceed with caution before diving in head first.
See how we integrate Scala and other social technologies into our client’s web and mobile projects.