Julia vs. Python: What should you choose?

Arpit Omprakash
Analytics Vidhya
Published in
5 min readFeb 12, 2020

Python has been around for as long as one can remember. The implementation of Python began the year Tim Berners Lee invented the world wide web (1989). Its philosophy can be described by 19 “guiding principles” a.k.a the Zen of Python:

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one — and preferably only one — obvious way to do it.
Although that way may not be obvious at first unless you’re Dutch.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it’s a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea — let’s do more of those!

It was envisioned as a general-purpose programming language that is clutter-free, easy to understand, minimalistic but highly extensible. The above features make it an excellent fit for beginners to learn, understand, and code in Python.

Julia, on the other hand, is described as “greedy” by its creators. The creators explain their motto in a blog post of Feb 2012 as:

We want a language that’s open source, with a liberal license. We want the speed of C with the dynamism of Ruby. We want a language that’s homoiconic, with true macros like Lisp, but with obvious, familiar mathematical notation like Matlab. We want something as usable for general programming as Python, as easy for statistics as R, as natural for string processing as Perl, as powerful for linear algebra as Matlab, as good at gluing programs together as the shell. Something that is dirt simple to learn, yet keeps the most serious hackers happy. We want it interactive and we want it compiled.

Julia started development in 2009 and was first released to the public as Julia 1.0 in 2012. Although it is yet to have a big fanbase as indicated by the TIOBE index, Python is the third most popular language after C and Java while Julia ranks somewhere in the 40s, it is still worth a visit. In this post, comparisons between Julia and Python are shown and a general rule of what you should choose is laid out.

Speed

Comparison of the rate of executions in C++, Python, and Julia

It can be easily seen that Julia outperforms Python by a significant value in terms of speed. The primary feature contributing here is, Julia is not interpreted; it is instead compiled using the fast LLVM framework. Julia gives quick results without many optimizations and is excellent at numerical computing. However, Python lately has been improving on this front (improvements to multi-core and parallel processing).

Libraries

One of the significant drawbacks of Julia is the relative scarcity of native Julia packages. The creators have tried to make up for this by making Julia able to interface with C libraries and also Python libraries (using PyCall), but it is not that great compared to Python. Python outshines Julia in this respect by a large margin. As a general-purpose programming language and with an extensible philosophy, it offers a vast standard library and also various community maintained and open source libraries for multiple tasks starting from web development (flask and django) to mathematical programming (numpy and scipy).

Parallelism

Python and Julia both can run on multiple processors, and both have inbuilt parallel processing. Python parallel programming methods require serialization and deserialization of data for parallelizing between threads. Whereas Julia’s parallelization is much more refined. Julia also boasts of less top-heavy parallelization syntax as compared to Python, in turn reducing the threshold to its use.

Code Conversion

It is quite easy to convert from Python or C to Julia. Converting code from Python to C and C to Python is a daunting task. Libraries such as PyCall make it easier to use python code inside Julia.

Example of PyCall in Julia

Typing and Indexing

Both Julia and Python are dynamically typed (i.e., developers don’t have to specify variables). However, one can also use static typing in Julia.
Python is 0-indexed, i.e., list and other indices start at 0, but Julia is 1-indexed. Indexing might be a problem as most hackers, programmers are accustomed to 0-indexing, but some people (those who use Mathematica, etc.) have experience in 1-indexing.

Community

Julia has a growing and enthusiastic community, but it is relatively new and, thus, much smaller. Python boasts of a pretty vast and helpful community. It is much easier to access help on different websites, including python documentation and stack overflow, as many people code in Python regularly as opposed to Julia. As a beginner in any language, having a massive community of experienced developers that can help with issues/errors in code is a huge boon. Thus, it is fit that most people start with popular languages like Python, C, or Java.

Versatility

Julia is much faster and mathematically better; this helps Julia serve academics better. Julia was founded at MIT by academians, and thus, it is geared towards academic programming, much like MATLAB or Statistica. The fewer packages and developers using Julia compromise other aspects of general-purpose programming.
Python has a broader range of packages available for different tasks starting from pure mathematics (numpy) to image manipulations (pillow) and even web development (flask). Python can be used as a language for full-stack development and deploying apps online and in different desktop or android systems.

Shell Integration

Working with the shell is quite easy in Julia as all variables are exported as environment variables in the shell, and Julia can access shell commands to open, edit and save files and for other tasks. The same task in Python is not that straight forward.

Examples

Binary Search in Julia
Binary Search in Python

The above programs are both very similar are both of 11 lines exactly. The Julia code is faster; however, the Python code is more human-readable. Note that the indexing in Python starts from 0, while in Julia, it starts from 1.

Conclusion

No one can predict what will happen in the future, but one can be sure that there will be fierce competition between the two languages. Although Julia is faster and much more suited for academicians, for now, Python outperforms it in terms of understanding, acceptance, and a well-developed community. If you are starting with programming, then I suggest Python as it provides a much larger developer base for you to ask for help with any problems. Julia is encouraged for people who are well versed in Mathematica and want an open-source alternative for MATLAB. However, data scientists need to be aware of the fact that Julia provides speed at the cost of a well-developed community. Experienced programmers may try out both and see which one fits them the best. As for me, speed is not an issue, and I am content with what Python offers now.

Before you go…

Connect with me on Instagram and Facebook.
If you liked this story, hit the clap button (you can clap up to 50 times with just one button!) and follow me for more such articles!

Share, recommend, and comment away! Engagement helps us communicate and be more human!

--

--

Arpit Omprakash
Analytics Vidhya

I'm a Programming and Statistics enthusiast studying Biology. To find out if we have common interests, have a look at my thoughts: https://aceking007.github.io/