Tutorials
Blog
About

Tutorials > Julia Programming: a Hands-on Tutorial

Julia Programming: a Hands-on Tutorial

by Martin D. Maas, Ph.D
@MartinDMaas

Last updated: 2021-07-10

This is the first post in a series of introductory material about Julia, focusing on its use in Science and Engineering.

A Hands-On Tutorial of the Julia Programming Language

Why Julia?

Julia is an is a general-purpose, open-source, dynamic, and high-performance language. By leveraging a clever design around a just in time (JIT) compiler, Julia manages to combine the speed of languages like C or Fortran, with the ease of use of Matlab or Python.

Some Features of Julia

Julia has many interesting features, but here is a small sample of what I think is most basic characteristics that make Julia attractive for Science and Engineering.

How to learn Julia

This is hands-on tutorial series, based on examples.

In particular, we won’t be introducing much more syntax or language features than what is required to solve the different problems we will be tackling.

As a quick reference, it might be worth to check out the Matlab-Python-Julia Cheatsheet, and the Julia Express 16-page reference guide.

For a thorough explanation of the Julia language, you can always check out the Full Documentation.

Where to find help?

Julia is still a relatively new language, so you might not find as much information online as in other languages. For this reason, if you can’t find some answers online, don’t hesitate to address the Julia Forum, where people are very friendly and welcoming.

Installing Everything

You can download the latest stable release of Julia here, which, last time I tested this tutorial, was version 1.6.1. Bear in mind that if you install Julia from certain package distribution systems (like APT) you might get the latests LTS version which is currently 1.0.

In this tutorial series we are mostly going to be working with the VSCode IDE for Julia, which you can get here.

Make sure to also get the Julia Extension for VSCode.

Installing packages

One of the salient characteristics of Julia is its excellent package distribution system, and the open-source community built around it.

Packages can be easily installed from the REPL. Lets install, for example, the Linear Algebra package. Simply do:

import Pkg; Pkg.add("LinearAlgebra")

For using the packages in our projects, we need to include them with a using statement:

using LinearAlgebra

Searching packages online

Besides from searching Google or asking in the Forums for Julia packages, there are two very useful official resources that keep track and can help you find packages:

Is Julia Really as Fast as Advertised?

Coming from a compiled-language background, I have to acknowledge that I was skeptical about this at first. So I set out to write my own benchmark, suited for my personal use case. As it turns out, I found out that after some tweaking of both the compiled code and the Julia code, that indeed Julia can be just as fast as highly-optimized Fortran code. And it can do so with 3 times less lines of code.

You can read my post about this benchmark here. The benchmark has two parts: considering some basic out-of-the-box implementation and see which is faster, and then going for highly-optimized codes and evaluate how much effort we needed to create such codes.

Long story short, my conclusion is that not only the trade-off between programmer effort and code efficiency is what makes Julia shine, but the fact that we can get serious about optimizing the speed of our codes, and make Julia really high-performance, for a fraction of the effort we would need in older compiled languages such as C or Fortran.

Is the Julia Language Free?

The Julia language was originally developed by a group of researchers at MIT, and released as open-source and under a permissive license. Julia also has a thriving open-source community responsible for the creation of thousands of packages. As such, most of Julia is and will remain free to use.

Eventually, some of the Julia founding members formed JuliaComputing, a venture backed company, to continue the development of the Julia language. The business model of JuliaComputing is offering paid support and commercial Julia packages – like a Bloomberg API for financial modelling, or a software suite for pharmaceutical companies.

Conclusion

Do you want to give Julia a try? Are you already programming in Julia and want to read along? This is a growing series of tutorial posts, so stay tuned for additional material!

Ask me a question or send me your comments!

Don't hesitate to ask me any question about the topics I cover on this blog!

Click here to reach out!