Comparing Scala and Python.
By: Sachin Verma
Tags: Functional Programming, Scala, Python, Python3, Programming

Python is a high level, interpreted and general purpose dynamic programming language that focuses on code readability. Python requires less typing, provides new libraries, fast prototyping, and several other new features.

Scala is a high level language. It is a purely object-oriented programming language as well as functional language. The source code of the Scala is designed in such a way that its compiler can interpret the Java classes.

The main difference between the two is Python is made to reduce the headache of developers to develop quick apps i.e. they don’t have to think about programming and they can get to work easily; the code can be readable and prototyping is really suitable in python. It is really suitable for researchers and all who just ant to focus on core implementation want language to deal with rest part. Researchers love to write code in a english like language and so does everyone else. Also Python is considerably old language and it have its own ecosystem of tools and libraries so it’s easy, economical and faster to develop apps in python.

But when it comes to Scala the story is totally different, it is a language with huge appetite. It is a language that walks along with developer in the journey. You can get started with quick prototyping by using existing libraries and ecosystem of Java and prototype in a cleaner way than java. When it comes to language design, this one is absolute beauty. This is a language that grows with your project and you can write everything in it starting from a script and going towards huge and complex backend sytems that can afford to have throughput of hexabytes of data with a reliablity and pre-estimated performance and you can sit back on your chair that the app won’t crash at run time. And yes we were talking about language design, it is a language that gives you package of high level libraries and low level construct to write your own libraries also that have a feel like in-built library.

In case of Python there is ease in understanding pre-written code and you can feel great about writing scripts interacting with operating system and pipelining processes under 10 minutes. There is similar experience all of the times. While in case of Scala you might have bad dreams searching about what this small piece of code does. Libraries like Scalaz, Akka, Cats and other might really scare your coding capabilities if you have started new. But the complex code is not just written to prove yourself cool then others. The fact that you can deploy your Akka actors on large no of machines that do parallel programming and spin the fans of processors and when one server is overloaded by requests, you can transfer some piece of services to other machines and make them run there at runtime without breaking a sweat is really worth of the complexity. And if you try to do same thing in other languages the complexity increases by large scale. And working on such things is really challanging and satisfying also. So Scala is a language with huge capabilities.

Python is really suitable for top level layering of apps. Like you can use libraries written in c/cpp/rust etc which are performant at their peak and put your use case on top of that with a read file and call functions and done way. Great example is machine learning, you never need to put effort on programming on python you just have to get done with your nn architecture and cherry picking between RMSProp or adagrad or whatever. But even doing machine learning on large scale is preffered in scala. Big data engines like Apache Scala are written in Scala and you can harness their full power if you understand the constructs and apply same level of architecture at top of it you can perform even better.

Python is dynamically typed i.e. the type of data is inferred by compiler at run time. At first sight it seems cool that you are making machine work for you. But the compiler can easily give you run time errors and program can behave unexpectedly and the compiler have reason about it like what can I do if someone had passed string instead of int and you can do nothing about it. And when we’re developing serious systems like dealing with finance transactions and predictable behaviour is the most important thing.

Scala takes a better approach it gives you option to provide type of variable while writing code but it infers the type of variable at compile time and you can be sure that the app won’t crash in run time. Most of the errors are shown by IDE itself and you feel really cool when you type 100 lines of code and it compiles in first go without any error.

Python is made keeping in mind that the developer’s have easy life. Scala is based on pure mathematical concepts like category theory, dot calculus and all. It thinks programs can be broken down into small referentially transparent mathematics like functions which can be composed and pipelined to perform a given task. So you can have a clean architecture and intuitiveness coming in the end. Basics of this language are really strong and it also intends to make developers life easy but the fact that we also do difficult tasks with it makes outsiders think it is difficult.

It’s a paradigm shift in case of scala. Most of the time you are raised doing imperative programming that this will compile first then this and so on. In functional languages like Scala you have to thhink not in terms of times but in terms of composability of different blocks. This change in thinking also takes time and hence you feel its complex.

When it comes to preferences I think both languages have their own places. For fast prototyping, generating piplelines and general tasks python is superb. Scala will be overkill there. But Scala teaches you programming in a disciplined way and it may take even years to adapt disciplines and write expert level of code in Scala. Generally companies who work on Scala demand n years of experience.

But as you can easily get productive in Python companies also like to choose such languages in their tech stack so that they don’t have to spend resources in training developers. Scala developers are hard to find but if you have good knowledge you can fill your own salary in the cheque if you’re working in some cool product based company in USA. If not so, salaries are arguably higher everywhere on globe.