Python to Scala

Bryan Lott published on
2 min, 274 words

Let me set the background. I'm not a classically trained programmer. In fact, I've been coding for about 8 years and ended up teaching myself on the job. I'm currently a senior software engineer and end up fighting with Imposter Syndrome on a regular basis.

I've been a Python programmer for pretty much that entire time with occasional dabbles in other languages (Clojure, Java, Scala, Node, etc). In my current (new) position, I'm working in a Scala codebase. A language that I've never had to put the effort forward to learn. Three days in and I totally had a lightbulb moment:

Scala is Typed Python on the JVM with Braces

Take for instance the Person class in Python:

class Person(name, age):
    def description:
      return "{} is {} years old".format(name, age)

and the same thing in Scala:

class Person(val name: String, val age: Int) {
    def description = name + " is " + age + " years old"
}

I mean, yeah, there's a ton of other stuff in Scala (it's a batteries-included language like Python) but the more I look at it the more I see how similar they are instead of how different they are. Scala has an advantage that functional programming concepts are much more accepted in terms of style than they are in Python.

Scala also has things like for-comprehensions (list comprehensions).

Python:

l = [i for i in range(100) if i % 2 == 0]

Scala:

val l = for (i <- 0 to 100 if i % 2 == 0) yield i

So far, it's not as difficult a mountain to climb as I expected and that's a very good thing!