Language War – Scala v/s Python (Part 2)

This is a sequel to my earlier post – Language War – Scala v/s Python where I shared some of the practical yet emotional/instinctive factors that come into play when picking the core language at a startup. We left the story tied at 1 – 1. Read on to see who ultimately won the ZLemma language war.

Libraries and Tools: Scala’s interop with Java makes it very attractive, giving access to a wide range of libraries and tools for algorithms development. Although numerical computation forms the core of our app, we are not compute-bound and are unlikely to be compute-bound anytime soon. It’s easy to be sucked into the scipy mantra because of the nature of our business, but practically this is not the biggest consideration with our product right now.

What’s important is to note that ZLemma is not just about mathematical programming. A web platform and database engineering are key components of our app. Yes, Scala has Play (previous typo – “Lift” – corrected) but it can’t match the maturity of Django. This overrode the benefits of some of the other libraries/tools that Scala/Java have on offer. Python gets ahead again: 2-1.

Team Culture: A good language coupled with elegant paradigms enable us to express the math/business models more naturally and make the process intellectually satisfying as well as rigorous. This has the effect of establishing a strong and consistent culture in the team.

My view is that functional programming and stateless computation is the natural way to think and code. It’s not just about elegance and clarity of thinking. It’s also about “Kill state, and you kill bugs” (okay – I made up that line :) ). I wanted the team to think along the lines of “lambdas, maps and folds” to build a high-quality software product. While Python gives you lambdas and list-comprehensions, the languages doesn’t really encourage the functional style.

The other factor I thought a lot about was the “If it lints, it’s probably correct” approach to coding – we are all guilty of this, aren’t we? With Scala, the approach often works and we unfortunately end up with a false sense of security and consequent indiscipline. On the other side, this approach to coding doesn’t make any sense for Python, but we still indulge in it! The discipline problems are compounded in Python because the language generally encourages playing offense more than defense (seeking too much instant gratification). Ultimately, I felt Scala leads to a better coding culture in the team. 2-2.

Tried & Tested versus New & Cool: Scala is an impressive language because certain things can be accomplished more easily than in other languages, thanks to features like traits, type variance, lazy evaluation, and actors. However, I reminded myself that it’s a relatively new language and that very few startups have begun with Scala. I feared that we might be too slow in our development and what’s worse, might not even realize that we could be much faster if we had opted for Python.

I also worried that Lift might not be as convenient or versatile as Django. Most importantly, there was the fear of going off the beaten track and encountering something unexpected. The advanced features of Scala are indeed complicated (eg: type variance) – maybe we’d end up tying ourselves in knots trying some of these new things? I was chickening out … So, Python ended up winning the ZLemma language war 3-2.

Looking back: Our platform has been built in Python. But we do use some Scala for independent code outside the platform. The speed with which we have progressed has surpassed my expectations. I am sure it would have taken us much longer to get here had we opted for Scala.

With Python, we get a high from making things work quickly. That’s nice for team morale, but I also get frustrated with the poor defense habits it generates. So I’ve told the team: “Play offense to develop a feature for say a week, then play defense for a couple of days to consolidate (type asserts, exception handling, unit tests etc.), then go back to playing offense on the next feature, and so on …”. This is a happy middle-ground. But the occasional discovery of bugs (mainly due to dynamic typing) gets me ranting about Python. So I’ve decided to rewrite just the core calculation engine in Scala and have the web/data framework remain in Python. REST will bridge the gap. Wish us luck Cmd-Tabbing between Scala in Eclipse and Python in vim :)

Ashwin Rao
Co-Founder, ZLemma

Discuss on Hacker News (please be civil!)

9 comments

  1. [...] Time Out. The remainder of the story is here. [...]

  2. Smotko says:

    I see you looked into Lift, but what about Play? It’s been around for years and with version 2.1.0 it’s really awesome. I worked both with Django and Play and I prefer Play even though it doesn’t have an Administrator module like Django…

  3. Atin Sood says:

    Same here. I have been trying to learn both these languages for some time. Both have their pros and cons. As you mentioned python for quick prototyping and churning out something real quick. I generally end up using for writing a thin REST layer for my code. Scala, well miles ahead of java when it comes to productivity, super handy when you need to write solid mature backend and are dependent on 3rd party libraries from java/scala. Just that you still need to have correct project structure, steep learning curve, personally I find the syntax to be crazy hard at times.

    I am new to both languages and with years of enterprise experience, I still feel java is the language for the enterprise with sprinkling of python and scala here and there. Java is easy to understand for anyone, much easier to maintain for avg programmers. Lets just call it idiot proof. As much joy as coding in scala or python gives me, I generally have to end up writing documentation to remind me the flow and the intent.

  4. You mentioned Lift as a web framework, but have you tried Play web framework ? It has more support than Lift for now I think.

  5. That’s very interesting. I’m a Python developer at work, who is slowly going the way of Scala. I’m assuming that you made the evaluation a while ago, but I’m curious as to whether or not you would come to the same conclusion today. Scala has grown in popularity in the past year, and quite a few nice libraries and frameworks have come out (Play! and Akka, anyone?). I suspect that this would’ve been a much closer decision today.

  6. Josh Stone says:

    Lift? Seriously? You should be comparing Play framework.

  7. Two Unlimited says:

    You should have looked into Go. It is like C as it is procedural, compiled and statically typed. It is like Python and Haskell as functions are first class citizens. Functions can also have multiple return values.

    Concurrency is very easy to do. The language is also garbage-collected.

    You can do instantiate objects of structs; there are no classes, therefore no inheritance, but there is duck-typing through interfaces, which is alot easier imo and alot more useful.

    It is designed as a compiled web language, the libraries for HTTP/HTML etc. are very mature, but other libraries, like that for regex, aren’t since the language is very new.

  8. Avinash says:

    Very Interesting analysis, I just started looking into FP and must say your notes was interesting, Since you are in WEB and Database, did you thought about Clojure. scalalikejdbc looks interesting for database access.

Leave a Reply

Your email address will not be published. Required fields are marked *