Introduction to Julia

Introduction to Julia

Recently, the Julia programming language hit the 1.0.0 version and is now considered stable. It’s a language that I have been vaguely keeping an eye on for a while, but didn’t really interact with until now.

From Wikipedia:

Julia is a high-level general-purpose dynamic programming language that was originally designed to address the needs of high-performance numerical analysis and computational science, without the typical need of separate compilation to be fast, also usable for client and server web use, low-level systems programming or as a specification language.

The impression one gets from this is that the language aims to fulfill many areas at once. This may work well or it may be a detriment – time will tell. More information can be gleaned from the developers’ Reddit AMA.

That said, it does have a primary focus on data science, numerical analysis, and statistics. Again, in a landscape largely dominated by Python and R, time will tell how well Julia integrates.

Julia blends different programming paradigms in an unobtrusive way, feels expressive like Python and has an interactive console/REPL. While it is dynamic, it also supports optional type annotations.
With regards to types, Julia has abstract types and concrete types. Abstract types do not directly represent an object. Instead, they group related concrete types, which do directly represent objects that are instantiated.

Let us look at some of the syntax

Printing to the standard output:

print("Hello World")

Assignment in Julia is straightforward:

x = 5

Applying  arithmetic operators works as you would expect:

x + 5
Result: 10

Operators are also functions and you can form expressions in prefix notation:
*(+(2, x), 10)
Result: 70

Something that I really like is the ability to write expressions with variables in a more natural way. The variable coefficients can be appended to the numerals to signify traditional multiplication, resulting in less visual noise:

2x + 5x
Result: 35

And with brackets:
5(x+1) + (2+x)x
Result: 65

Note: you can’t say x(2+x) in this case because Julia will interpret x as a function name.

We will explore topics such as functions, iteration, types and data structures in Julia in future posts.

Leave a Reply

Your email address will not be published. Required fields are marked *