Why Scala Can Help You to Build a More Reliable Service
It turned out I am quite wrong after I look into Scala which is created about 13 years ago. It is a functional language inspired by Java, Lisp, Haskell etc. This is not my first time to hear about a functional language, but I do have some really bad misunderstandings for functional languages. As I mentioned earlier, C is my first language. Programming in C means that you’re using functions to construct everything, and you’d be thinking about procedures all the time. And you are dealing with memory by yourself which is not related to your business logics at all. So you end up with debugging and testing memory leaks and segment faults. This part of the job is pretty nasty. My first impression on functional languages is something looks like C language.
Scala is totally what I’m not expecting. I mean, functions are the first class citizens in Scala which loud and clear when I first see it. After all, it is a functional language. However at the same time, all the variables by default are immutable. The design actually solved a lot of issues. I wasn’t expecting this at all. Because of immutable variables, you’re free from thinking about who owns variables, and were the variables changed by others, do I need the lock it when I used it in multiple threads. Fun fact here, when you first learnt to do math, and try to calculate a formula, nobody would ask you the ownership of the variables. Why would programming be any different?
After a few weekends’ reading and experimenting, it fully convinced me that a functional language is very helpful to make developers focus more on the real business logics rather than figuring out how machines work. The thing it really matters is that business logic part. Life is too short to debug server issues. The side effects coming from the server’s memory management or locking/unlocking stuff shouldn’t be there in the first place. I hate to say that, but relying on a developer’s past experience to make the right call to manage memory are not reliable. How many times you forget to lock your key in your apartment when you go to work in your daily life? Shit happens when a person is dealing with a lot of repeated small details.
There is one thing really bothers me. Not many really good quality projects written in Scala are available on GitHub (https://github.com/trending?l=scala&since=monthly), so it’s harder for new developers to learn from each other. Checking out a real project or making a real world project is a really good way to learn a new language. I hope there will be more people contributing to this young language. You won’t regret it when you start to use Scala. It’s an amazing and attractive language to know.