Could Nim Replace Python?
By: Emmett Boudreau
Tags: Machine Learning, Python, Nim, Data Science, Programming

Compiled Executables

A common theme with Python is requiring Python in order to run Python, and this includes an application’s dependencies. This is problematic because it means that Python applications to be packages in one way or another with said dependencies. On top of that, it’s very likely that virtual environments will be frequented. While this isn’t terrible, and to confess most statistical languages do exactly the same, Nim does this significantly better by packaging an executable with the included dependencies needed to run. This not only makes managing dependencies from system to system a breeze, but also makes deployment

EASIER than Py (see what I did there?)

These compiled executables are also compatible universally across the Unix-like systems, Linux, Mac, and Berkley Software Distribution, but also the Windows NT kernel. Compiled executables take care of dependency issues and make it incredibly easy to publish an application, or even deploy an API with a simple “.” or “source” command.

Universal

Nim has a serious advantage to Python in that not only is Nim capable of being compiled in C, but also C++, and more excitingly:

Javascript

This means that not only does Nim have the potential to fill Python’s role as the scripting language that runs the data-based back-ends of the web, but Nim can also be used as a front-end similarly to Javascript. This is a huge benefit over Python. While Python is certainly great for deploying endpoints, and often does the job fine, having single-language fluidity across the board certainly has its advantages!

Features

Nim’s code-base is primarily structured on the functional paradigm. This means that Nim can be a very expressive language, and furthermore can easily implement far more cool features than Python can. One of these features is one of my favorite features of all-time to be implemented into programming back in 1958 with the release of Lisp,

macros.

(I will never understand why this is Lisp’s mascot, src = Common Lisp)

Macros and meta-programming have been around for nearly as long as computing itself, and can be very useful, especially on the grounds of machine-learning.

Speed

It’s no secret that as scale goes up, using Python for everything can be very problematic. This is because many training algorithms utilize a recursive Cost or Loss function that is intensive to run for any language. There are lots of languages and ideas with the intent to counter-act this, such as Julia, Python In Python (that’s a rabbit hole in and of itself), and more successfully: Cython.

With these solutions, however, come their own problems as well. Though Julia, which is, in fact, my favorite language, and likely the most apt to be a replacement for Python, does not have anywhere near the ecosystem that Python flaunts. Though there is a PyCall.jl, typically performance when using it dips below that of Python’s, and in that case,

why not just use Python?

Python in Python is an interesting concept, but has yet to see great implementations, as the concept itself is quite complex. Even worse, Python in Python is much more difficult to implement than a solution like Julia or Nim. As for Cython, contrary to popular belief, Cython does not work universally, and relying on it probably isn’t a good idea (been there, done that.)

Nim has the advantage of being faster than Python. For scripting, Nim’s added speed could certainly change the way that system-maintenance and various scripts are run. Using Nim might not be as fast as Julia, or C, but with the simple similarity to both Python and Bash that it boasts, it could certainly be a lot easier.