Scala for Simpletons — What should have been my first article, What is Scala?

Anthony Johnson
4 min readFeb 13, 2021

--

Scala is a modern programming language written by Martain Odersky.

Fin…

Alright so what is Scala, scala, like I said above, is a modern programming language, it has some pretty cool features too, for one, and we will go deeper into everything momentarily, everything in Scala is either an object or a method, 1 + 1? yeah, it can also be written as 1.+(1) and will evaluate as two
What does this say about Scala as a language? Scala is Pure, so if you can program in Scala, you are automatically better than almost all programmers by default…

for brevity, you’re gonna have to trust me that this prints 2

Scala — Pure Object Oriented Programming Language or Functional?

Cool, so Scala is a “Pure Object-Oriented Programming Language” or Poop-L for short, and it can do some pretty neat things… But wait, not so fast, Scala is also a Functional Programming Language and when writing in Scala you should be thinking about things functionally to take advantage of the function stack (we will get into that another time).

So in Scala, everything is an object all operations are methods and all methods are evaluated and have a value, functions can be stored as variables and used within other functions.

Kind of cool, this example too way longer than it should have to come up with… I think it has the perfect amount of simpleComplexity to illustrate the very basic use of functions within functions.

I should have added it, but you can also assign function expressions to values and they are treated as if they have evaluated. so “val summed5 = sumNumbers(5)” summed5 would have the value of 55.

Val and Var

val and var are both variable declarations in Scala, the Scala interpreter is smart enough to infer the type without explicitly typing it. So, why two types of variable declarations? simple put val does not allow mutability where as var does, what is “mutability”? its the ability for a value to change, or the state of a program to change. If you understand memory, immutability does not allow change at the point in memory a variable is referenced.

some space…

val five = 5, will always equal 5, it cannot be changed to 6 or 4 or any other number, you can use it in your program, but you can not alter or redesign the val 5.

var five = 5, can be changed, five++ = 6; five++ = 7…n

Objects

Objects in Scala are self names instances of themselves, they're singletons. An Object is also the entry point into a Scala program, this is attained by extending the App trait (kind of like an interface… we will get into that more later). Objects have some very cool features, you have companion objects and companion classes, we will get into that another time… this is just an intro… I haven't read that chapter yet… Anyways we have shown a few objects in the prior examples of defs and values. Objects can have their own properties and methods, they are very similar to classes, they provide a way to keep your application self contained.

Classes

Classes in Scala, really easy to create, all you need as a class keyword and an identifier class Donut”

Oh boy, do I love Donuts 🍩

What is Scala? Scala is whatever you want it to be, it a modern high-level statically typed language made to fit the needs of our scala-able world. Scala is an easy-to-use, but the extremely deep language in which you can decent deeper and deeper into.

Who Uses Scala?

As the name entails, Scala is a language built for scalability and is used in many large companies, Amazon, Twitter, Facebook, you get the idea, Scala is used closely with mand big data services, Spark, Akka, Kafka… It is the language of Big Data.

Scala is seemingly very complicated due to the powerful operations built into the language, and the very expressive nature of the language, one developer can program completely differently than another in Scala… As you saw above in the brief intros, Scala can do some cool things… also, Scala 3 is coming out soon, like Feb ?? 2021. I'll link some info below.

You can learn more about scala below:

Scala3 (not fully released) https://dotty.epfl.ch/
Official Scala Docshttps://docs.scala-lang.org/
TutorialsPoint — tutorialspoint.com/scala/scala_basic_syntax.htm (There were some errors, but it does provide some decent material)
Coursera Course by Martain Odersky, himself — https://www.coursera.org/learn/progfun1

--

--