Personally, I started programming in Scala in 2015… I did the Scala training on Coursera.
Guess what? at First I did not like Scala! I could not understand why I would want to implement all these complexity when I can use Java and Spring to solve all the problems… It turned out i was wrong.
To write functional Scala, you need to think functionally… rather than thinking in Object Oriented Manner & translating those thoughts into Functional Paradigm.
My real Scala interest started not with Web Api’s, it started when i laid an interest on Spark. I wanted to build a clean, abstracted approach to Big Data & implement it with the best functional language! that’s when I started loving Scala.
Immutable Data easily leads to pure function and easily distributable code.
I came to the conclusion, when i want to write something in Scala… to do it with Pure Functions if i choose to use the functional paradigm. This allowed me to do some of the following:
- Pure functions have no side-effects
- Pure function calls to immutable data are often easy to reorder
- Pure function calls to immutable collections are often easy to parallelise
Use Expressions instead of statements.. Expressions Can be passed into a function. As expressions can be chained together in Scala.
Don’t Mix Java Statements with Scala expressions.
Unlike statements, expressions can be used to be specify arguments to a function. As Functions, a subtle point – Scala allows expressions to be used in place of functions.
It took me some time to get used to the idea.