No – I am not going to discuss the theoretical pros and cons of Scala and Python. Instead, I am going to talk about the practical issues startup founders like me face in establishing our main language.
The context: The core of ZLemma.com is a mathematical framework involving highly structured data representations and numerical algorithms. The product involves a large relational database and is delivered through a web application. We wanted to move fast with our development, but we also wanted to build for scale and robustness. A compiled language like C++ was not in consideration because dev progress would be too sluggish. On the other hand, a web programming language like PHP was also not in consideration because it simply wouldn’t work for mathematical modeling.
Initial Thoughts: My first thought was Haskell. You say, “Haskell? Are you crazy?” Crazy – You got that right It’s a very beautiful language and once you start coding in Haskell, you tend to get religious about functional programming. Lately, Haskell has become a fairly pragmatic language and is gaining popularity because of the emergence of functional programming paradigms in mainstream languages. However, people talked me out of it – although I am still considering Haskell as a choice for the future
The next thought was Scala. Scala is inspired by Haskell and is a more pragmatic functional programming language because of its interop with Java. I decided that Scala will be our core language and that we will program in Scala in the “Haskell-style”.
When Zubin (our Python Guru) joined the team, he began selling me on Python. I remember my impatient persona telling him, “That’s great, but you are going to do Scala here”. Zubin is not religious about Python and appreciates functional programming, so he started learning Scala. After a couple of days, I realized I am being bull-headed and that I should give Python serious consideration. After all, many startups have built sophisticated functionality with Python. And who the hell does Scala? (Actually, Twitter does!)
After some analysis, I realized that Python and Scala are more similar than I had assumed (functions are first-class objects in Python, after all). However, the differences are significant. Here are the five factors I took into account before deciding on our main language.
Developer comfort: We’ve been fortunate to have a very strong dev team. Each of us can pick up new languages and paradigms quickly. Ajit is a very careful engineer – he prefers object-orientation and static typing. Gaurav comes from a mathematical computing background like me and so he is more comfortable with functional programming and static typing. But generally, both Ajit and Gaurav are fairly neutral in their attitude to languages. As should be obvious by now, I am pretty obsessive about functional programming and static typing.
Zubin is the classic hacker in the team, so it was important that we give Zubin a language that he is comfortable with. Zubin enjoys Python’s duck typing and swears by “Code like a Pythonista”. I paid close attention to this fact He also enjoys the elegance of list-comprehensions in Python (that made me happy!). Finally, I had to think about future developers we’ll hire. Hmmm … suddenly, it looked like Scala is losing this battle and it did. 1-0 to Python.
Fine – it’s just a battle. I was hoping Scala will win the war.
Typing: My first thought here was : “If you are doing any serious algorithms or anything mathematical, dynamic typing is just not on. When we define functions in Math, we first talk about the domains. The domain specification effort is always well-worth it – you need to know the space you are operating in, otherwise the Math goes out the window”. I heard myself and thought: “That’s the academic in me talking”. More practically, it’s a question of safety. This amounts to playing defense. Good defense is very important to me, even though playing defense slows down the pace of dev progress. Dynamic typing is like speeding on the highway on a motorbike – exciting and dangerous. Static typing is like riding in a military tank – safe and slow. Neither is ideal. The solution is somewhere in-between.
Either inferred static typing (Haskell, Scala) or libraries for automatic type assertions in a dynamic language (Typecheck in Python). My view has been that the former works without slowing you down much. Typecheck in Python sort of defeats a key philosophy of Python: duck-typing. Besides, dynamic typing scares the hell out of me. I’d rather be a bit slow and safe than fast and dead (a.k.a. chicken!). Scala wins this battle. 1-1.
Time Out. The remainder of the story is here.