Tour of scala started for me
lukaszkuczynski
Posted on May 22, 2018
Motivation
I attended Geecon 2018, this year’s IT conference. There are 2 main points I took into consideration. First, this is JVM, and as I can see there is a lot of that stuff running all around the world, so even if whole world would be magically converted to Python and stuff, it will take ages. And someone has to keep it running. Second, this is the language of Spark and Kafka, two of the projects of my interest in area of stream processing in Java world. Therefore I would like to be more fluent and write these processing pipelines in the suggested language so I can make use of all of the features.
First snacks
Scala is nice. It is less verbose. And as I can see it learned some nice features from Java applying in its syntax as a built-in (f.e. immutability). This makes my first steps nice. Especially I like following:
- inferred types
- immutability
- in-line functions
Learning
I decided to take a tour of Scala. And you can see the way I am learning in my repo at github here. Learning is done by writing the unit test and checking its results with sbt test
. Then I proceed to another point. It helps me to:
- understand points better
- have fun while learning
- make a step-by-step report, easy to review
This is nice. There was a while to find the best tool, and to make it all up and running on my Windows PC, and to have it running on Intellij, but finally I succeeded.
This is a sample how do I play with that, I write spec in Scala:
it should "make Fenix singleton by it being an Object" in {
Fenix.createOrRecreateFromAshes()
val historyOfFenix = Fenix.createOrRecreateFromAshes()
assert(historyOfFenix == 2)
}
that uses following object
:
object Fenix {
var livesCount = 0
def createOrRecreateFromAshes() ={
livesCount += 1
livesCount
}
}
This and much more at my github, you can check it, now worries.
Posted on May 22, 2018
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.