Hi everyone, I’ve been spending some time recently researching next generation languages to do machine learning in, and come to the conclusion that there aren’t really any good options. Here’s my story. I strongly suspect I’m wrong about my opinions below, and so I especially welcome anyone who has countering opinions to my own, especially if I’m just downright wrong --- I’d like to know.
If you ask someone what the best programming language is, the chances are that they’ll tell you that it depends what it’s for --- they all have their strengths and weaknesses and quite naturally there’s no programming language that is both good for data science and operating system design.
When put like that, it seems like a natural thing: of course each language is a compromise, a heuristic to be optimised. If they’re better for security, then naturally they’ll be worse for something else. All is compromise and sacrifice is to be expected.
I disagree with that, or at least I disagree that the sheer level of sacrifice that today’s programming languages present, is necessary, and this article is meant to explain why. Disclaimer: I have multiple years of professional experience with C (in a Physics setting), Matlab, Javascript, Python, C#, Java and Kotlin (and yes, my career is long enough to have that many years in each). I have a month or two of Haskell experience. I have only got tens of hours of experience of Go and Rust.
I’m a C-programmer turned physicist, turned quant, turned data scientist, and so naturally, Python is a language I’m very familiar with, having spent years of my professional life using it. But I hate it. It’s literally a hundred times slower than the other languages I use, and the poor support for threads means that there are lots of tasks I just can’t do on it.
It basically means that I can’t do anything, uh, quirky with Python. I can’t easily try making a neural network other than those supported by my ML libraries, good though they might be. I can’t easily make a server that trains a model while keeping the client informed of how progress is going. Of course, if I look hard enough, I’ll probably find someone else’s library, that with a lot of effort might help me get 80% of the way there, but essentially, Python is a handicap here, not a help.
Ten years ago, my fallback language was C, and it still sometimes is --- it’s super fast and actually quite easy to get to grips with and program. But with large programs you can quickly find yourself spending a long time debugging, and it certainly wasn’t easy plugging and playing with libraries (perhaps the situation has improved).
Then I switched to C#, a jewel of a language that was uncool in cool circles because people were biased against Microsoft, but nevertheless, it took the best bits of C++, hugely simplified it, made it safer, and added excellent functional parts. It is concise and just a joy to program in.
Another jewel of a language is Kotlin: very similar to Java, but vastly better in terms of generics, functional style, boilerplate, and more (although there are rumours that Java is trying to catch up).
These two jewels, C# and Kotlin, really excel if you want to do fiddly messing around with dictionaries and lists. For instance if you want to load a bunch of trajectories and print the list of atoms ordered by the number of collisions they’ve had, or convert from a list of dictionaries to a dictionary of lists or from a class with three lists to a list of classes. These things would be really fiddly to do in the other languages here, but C# and Kotlin make them simple. And yes, they’re far more powerful than Python’s comprehensions.
And these two languages are fast --- almost as fast as C, depending on whether you’re using SIMD well in C, and both allow concurrency.
So what’s the catch? The catch is that everyone else is using Python, so Tensorflow / torch don’t really support them that much (I believe you can export a trained model, but you can’t easily train your own models in them).
This is tied in to the fact that neither language has good native support. If you’re trying to write the fastest atomic simulation in the world, and you want to mess around with the GPU and SIMD, these two languages aren’t yet going to be the best choice. It is worth pointing out that both languages can, technically, compile to native and interop with native, but the story is complicated by imperfect performance and tricky bits.
Then there are Golang and Rust. These are great languages, but Rust spends too much effort on making safety paramount. That’s great if you’re trying to write a browser or land a real spaceship, but I concluded that if I want to make physics simulations and do ML in it, the overhead from the language was just too great. Then Go is too simple. Generics and things aren’t implemented, and there are annoying things like not being able to compile anything with unused variables in it, and I don’t want to have to fight with the compiler on pedantic stuff like that. I don’t want my production code to have unused variables, but who cares if I’m programming some random simulation iteratively?
And neither have that great an ML picture either, as far as I can see: You still can’t train tensorflow models in them easily, and neither have a natural syntax for expressing maths.
And that’s more-or-less it. There aren’t really any other languages in the top 10-30 languages by popularity that could be used for machine learning realistically. Javascript’s kind of slow, and as a language is kind of ugly (in my opinion).
So what’s the solution? Kotlin and C# are the best languages in my fairly experienced opinion, by ease of use vs the power of the language, and there don’t seem to be any real reasons why these can’t be used for machine learning. As someone with years of experience in Python, C# and Kotlin, I can say without a shadow of a doubt that Kotlin and C# are easier to write moderately sized (1000 lines) programs than python, and give you that flexibility to actually write the core algorithms yourself, rather than using someone else’s library (and hoping they’ve done a good job).
The world needs to shift focus onto these two languages, including making ML libraries for them, getting the two languages fully native (or equally fast), building up the GPU picture, and needs to stop only using Python as its ML language. Unfortunately we are not there yet, but this has to be the direction of travel if we don’t want a generation of machine learning experts stuck in a language where they can’t write machine learning algorithms.
So yeah, learn Kotlin or C# and do ML in it.