Why Julia Is An Awesome Language For Iterative Development | by Emmett Boudreau | Towards Data Science

The Julia programming language is a rather new language that has been taking the software engineering and scientific computing communities by storm. This is for a lot of different reasons, as the Julia programming language is among the fastest available, and certainly the fastest language available at such a high level. The language codes like a scripting language, with syntax very similar to that of Python or MATLAB’s, while also remaining incredibly fast. This is where the old motto was incited, “ Walks like Python, Runs Like C.” However, while Julia is quite a fast language to compile, that is certainly not the only attraction of the language.
The language uses multiple dispatch as a paradigm. This can create some pretty remarkable results with programming that you simply cannot find anywhere else. Multiple dispatch is often treated as the backbone of the language, and shows its beautiful self in multiple aspects of the language. One way that multiple dispatch has greatly impacted the Julia programming language is in the ability to extend modules across the entire Julian ecosystem. This is cool because it creates packages that you can add and already know some of the methods without ever looking at the documentation.
In order to understand how multiple dispatch facilitates some pretty awesome iterative development, we first need to understand what exactly multiple dispatch is. Multiple dispatch is the centerpiece of the Julia programming language, and Julia without multiple dispatch is not really Julia at all. The concept allows us to take multiple types and pass them through the same function calls. These function calls can be limited to any section of a type’s parents, meaning that multiple versions of that function can be dispatched using merely one type. If you would like to read a bit more about why I love multiple dispatch so much, I recently wrote an article on precisely that you may be interested in reading:
towardsdatascience.com
While multiple dispatch is a great way to program in my opinion, and often feels more natural than code structures generated using other programming concepts, I think what really sets it apart in the Julia language in particular is that it can be used nearly everywhere. Usually in programming, there are two different types of things that we write outside of a normally global scope:
Constructors
Functions
How these two work together is usually determined by the paradigm of the language that we are working in. In Julia, both of these things stand to work with the exact same programming concept, multiple dispatch. This makes Julia an incredibly unique language, because we have both dispatch to create types, and dispatch to create methods. Consider the following example:
mutable struct CoolKid    cool_status::Int64    function CoolKid(height::Int64, weight::Int64, n_friends::Int64)        cool_status = height - weight * -n_friends        new(cool_status)    endend
The constructor above uses dispatch to create the CoolKid type. The first way that we could get the CoolKid type is by directly calling what is called the outer constructor. The outer constructor is the portion without the function in the middle of it. If we were to call this function with an integer provided as an argument, we would directly get a CoolKid(integer) return.
However, if we were to call this constructor with three arguments that were all integers, we would still get the same consistent return, but instead we would run the arithmetic provided in the function. The new() method is utilized in order to facilitate this. I think this is a really cool aspect of Julian programming because typical fully-functional programming languages cannot have an initialization function for types, and using this form of dispatch, we can choose whether or not an end-user calls this initialization function or not.
So what makes Julia and its multiple dispatch concept so great for iterative development? There are numerous advantages to the multiple dispatch paradigm, but one that I think is criminally overlooked is the extension of methods. Using multiple dispatch, any method inside of the language can be extended to work with new types. This includes methods from Julia’s base module, as well as methods that are available from other modules across all of Julia’s ecosystem.
With that in mind, we quickly realize how Julia’s ecosystem can very effectively be developed iteratively. Adding to code that already exists can be as simple as dispatching new types to those methods. Consider the following example, where I dispatch the addition operator to work with a dictionary and a pair.
import Base: ++(d::Dict, p::Pair) = push!(d, pair)
This is just one line of code, and with that line of code the binary addition operator has become useful to the dictionary and pair types. Of course, this could also effectively be used on our own types from our own modules and environments, and I went maybe a little too into detail on how to go about doing that in an article you can check out here:
towardsdatascience.com
That article is actually one of my favorite that I have written recently, because it really shows what is so great about the Julia programming language.
Now, using our one line of dispatch and one line of explicit imports, we effectively have an entirely new use for this method that would normally be essentially useless for this type:
d = Dict(:A => [5, 10, 15], :B => [10, 15, 20])d + :C => [25, 30, 35]
The Julia programming language is surprisingly well-suited to do a lot of really incredible things. A lot of these concepts might be more scientifically geared, but I think that most can agree the multiple dispatch paradigm is a huge advantage to software engineering. One way that it applies is in iterative development. This is because most anything in Julia can be built upon, one method, for example Base.push, or Base.filter, is seen throughout the entirety of the language, and used to dispatch multiple types from multiple modules — which I think is pretty slick! Thank you very much for reading my article, and I hope it was at least somewhat helpful in showing what is so great about writing your code and working with other’s code in Julia.