Julia vs Python

Julia is a challenger to Python in science, each with an extensive library. The newcomer can it replace the old? (Python dates from 1991).

Demo Julia programming language
Example of Julia code

The development of Julia began in 2009 and the language became popular when the compiler was open sourced in 2012. It is currently available under the MIT license. The objective is to create a language with the advantages of Python (simplicity and dynamism), R (statistical processing), C (execution speed), Perl (string processing), Matlab (linear algebra), and others. It also wants to be distributed, parallel, generic.

In the tradition of Pascal, the language name comes from the French mathematician Gaston Julia, who discovered fractals.

Its simplicity and its scientific capabilities make it a possible alternative to Python. But is it superior? It is usually much faster than Python, but the latter has libraries written in C to compensate for the slowness of the interpreter. Which one is the fastest to run an algorithm is important but what matters most is how they behave on large data sets, such as matrix calculations. See Benchmarks.
The advantage over Python is that libraries can be written in Julia as well and compiled while a different language must be used to add fast functions to Python.

We also compare features and syntaxes. Both languages ​​are meant easy to understand and are aimed primarily at an audience that has no interest in the hardware, and thus in derivatives of C such as the Go language, ​​that are done to simplify the task of the compiler and not improve programmer productivity.



Introduction to the syntax of Julia


The definition begins with the function keyword and ends with end. This is classic, but not optimal, Scriptol simplifies by ending a function with return or return followed by a value.

A function can also be defined by assigning an expression to a name with arguments. For example:

fun(x) = x * 5


This should display 10.

What is peculiar to this language is that the return value is the result of the last evaluated expression, unless a return statement is explicitly inserted into the body of the function.
Arrays are passed by reference in arguments and therefore can be changed after a function call.

Operators are functions. You can assign the + symbol to a function f, and make a call to f (x, y), it returns the sum of the two arguments.

Control structures

The if structure is similar to PHP or Python.

The for loop has the form:

for i = 1:n

This is as easy as Python albeit with a different syntax .

The iteration on a container has the same form that in Scriptol or other modern languages ​​:

for s in [1, 2, 3] 

The while loop is classic :

while a < 5
  a += 5

There are no other control structure. No until, no switch. Pattern matching is not envisaged by the creators.

Classes and homoiconicity

Classes are composite types in which are nested functions which become their methods.

type maclass 
   function f(x, y)

There are no prototypes as JavaScript to add members dynamically, but since a program can modify and extend due to homoiconicity, so it must be possible to modify the objects and dynamically add attributes and methods ...

This is covered in the manual, but the examples are not very clear. I note for now that the eval function, such as in JavaScript, can evaluate and integrate a code in the program, and various functions exist for "introspection", ie accessing code by itself.

Should I use Julia?

I'm really impressed by the possibilities of the language. Go and Dart seem to have been designed in another era. Python is left far behind but has the excuse of having been actually designed in another era.
Julia has all the features of Python and even more, the code is just as easy to write, it has similar libraries in science and seems to be an alternative. It allows even to use Python's libraries...

It is not perfect either. Nothing is planned for pattern matching, something that is highly developed in Scala, another modern and innovative language. Objects do not support inheritance or compositions which rules out wide applications.
The documentation is sparse and difficult to understand. Most examples are at command line and it is unreadable.
Error messages were the weak point during my first test in 2014. Most of the errors within a function are reported on line 1, which is the line where the code of the function starts and so there were difficult to locate.
My experience in implementing the Erasthothenian sieve was laborious at the time but would be easy with the current version.

Updated April 23, 2017

The language has evolved considerably since the first review carried out in 2014:

Julia Studio is an free IDE dedicated to the language. Escher is a graphical interface for Julia.

Julia vs Python. Comparison of the languages.

Julia On Wasm. How to compile Julia in WebAssembly. Experimental.

References: The site of Julia. The authors are Jeff Bezanson, Stefan Karpinski, Viral B. Shah, Alan Edelman.

Programming and data languages Asm.js - Basic - C - C++ - C# - Dart - Go - Java - JavaScript - Julia - Pascal - PHP - Prolog - Python - Ruby - Rust - Scala - Scriptol - Swift - TypeScript - HTML - Wasm - XML - XAML - SQL