Closed ErikSchierboom closed 3 years ago
Scala to me, gives you the option to implement anything in the way that is the most beautiful to you. You can write heavy Object Oriented programing and pretty much start using Scala right away with previous experiences in languages like Java or C#, C++.
But what is amazing with Scala is that you can grow your programming skills as you understand more about the language.
I am going to pop the word but yes, Functional Programing is the future.
Imagine you could completely abstract all edge cases. Forget about null
, forget about Exception
, forget about sync or async. And instead, solely focus on Type transformation.
You have your input / output and you just have to solve the puzzle on how to transform A to B.
Following Scala / FP practices, also tell you that "replacing a function by its result should have the exact same behavior" , meaning, no side effect and no mutable variables. It is hard to get to this state but when you have cross the boundary, the grass is much greener on this side of the fence 😄
This allow you to run your main
as a unit test. And each method is completely independent.
Which mean you can test your entire project the way you can test each function.
Everything is strongly typed. By wrapping everything into case class
you can differentiate not only an Int
from a String
but also if this id
is your userId
or your bookId
. Therefor, you can create unit test for each function with a fully known input and output.
As an other advantage of Scala, it runs in the JVM, so you have access to all the Java libraries.
I went a bit off track into how Scala is incredible and lost track about how Scala is unique I guess.
To me what was a paradigm twist was to start thinking in term of types instead of in term of values. With object oriented language you think a lot about architecture and this is still there in Scala. But you go a step deeper in Scala and think about the transformation from one type to another.
I hope that helps :) Let me know if you want me to write more haha. Little self promotion, I have a website with a lot of Scala content: https://leobenkel.com/
How was your experience learning Scala?
Scala was my first functional language. As such, I struggled mightily :) The way I learnt Scala was through the (at the time) free course at Coursera, taught by Martin Odersky, creator of Scala. The benefit of using Coursera was that there was an actual course, with a good teacher and a nice progression for the concepts that were taught. There were also exercises, which were really helpful in getting to apply these concepts in actual code. Hearing someone explain things and being able to do it yourself were vastly different things though, as I found out the hard way. In the end, I managed to finish the course with some basic understanding of Scala and functional programming. Wanting to learn and practice more, I found out about Exercism, which is where my Scala skills were honed further.
What was helpful while learning Scala?
Clearly, the Coursera course (with its exercises) was incredibly useful. There were also forums linked to the course, which meant you could ask questions and other people would help. Furthermore, a colleague of mine also enrolled so we could compare notes and help each other, which was very helpful.
The Exercism Scala track too was very useful. I also liked The Neophyte's Guide to Scala, which dug a bit deeper into more advanced concepts that were not taught in the course (or only hinted at).
How did you tackle problems?
While doing the course, I could ask questions on the forum. As said, a colleague of mine also enrolled so we could help each other. Besides that, I used the usual mixture of trial and error, StackOverflow and blog posts.
In what ways did Scala differ from other languages you knew at the time?
Scala was my first functional language, so all the functional programming concepts were new.
What was hard to learn?
Most of the functional programming concepts :) Immutability, tail-recursion and type inference took some getting used, but I think I struggled most with higher-order functions and function composition. I was used to working with functions, but not to assign them to variables, pass them as arguments, and combining them. Understanding implicit parameters was also slightly tough.
What concepts carried over nicely?
The object-oriented features I knew also carried over nicely: classes, inheritance, mutation, etc.
What did you struggle with?
Knowing when to apply which functional concept :) Having learnt the functional concepts, I really wanted to apply them everywhere. I did not know when to apply them though (e.g. when to use tuples over custom types).
As Scala supports object-oriented programming too, it was sometimes hard to decide when to use a functional approach vs an object-oriented approach.
Scala has quite a bit of syntax, which means that usually one can solve things in several ways. Getting to know most of this syntax was quite hard, as well as knowing when to best apply what. An example of this is calling a method with a dot or without a dot.
Furthermore, I had problems getting used to Scala code relying a lot on custom operators. These custom operators can lead to very terse code, but can also be very hard to read for people not knowing exactly what they do. They are also not always intuitive, far less so than a well-named method I feel.
What did you have to unlearn?
I had to unlearn to design everything in an object-oriented way. I also had to unlearn that every method needed an opening and closing curly brace.
What syntax did you have to remap?
One thing I did have to unmap was how to write lambda expressions (inline functions).
We're closing this issue as it was part of our research for the v3 version of Exercism which has just been released.
Thanks everyone for chipping in! It has been greatly appreciated.
We’ve recently started a project to find the best way to design our tracks, in order to optimize the learning experience of students.
As a first step, we’ll be examining the ways in which languages are unique and the ways in which they are similar. For this, we’d really like to use the knowledge of everyone involved in the Exercism community (students, mentors, maintainers) to answer the following questions:
Could you spare 5 minutes to help us by answering these questions? It would greatly help us improve the experience students have learning Scala :)
Note: this issue is not meant as a discussion, just as a place for people to post their own, personal experiences.
Want to keep your thoughts private but still help? Feel free to email me at erik@exercism.io
Thank you!