Julia lessons
Scientific computing / data science
Julia was announced in 2012 to solve a dilemma in scientific computing: researchers would write the prototype in Python or MATLAB, and when speed was needed, rewrite the same code in C or Fortran. Julia's goal was to offer both easy syntax and near-C speed in a single language.
It achieves this with just-in-time (JIT) compilation: the code you write is translated into machine code right before it runs. That is why Julia is written like a scripting language but runs like a compiled language. Numerical loops can be tens of times faster than their equivalent in Python.
The language's defining design is multiple dispatch: which version of a function runs is determined by looking at the types of all its arguments together. This allows mathematical code to be expressed naturally — the same addition function can be defined differently for a number, a matrix, and a custom type.
- •→
Introduction to Julia
First step into Julia, the fast language of scientific computing and data science: printing with println.
- •→
Variables
Variable assignment with =; types are inferred from the value, and the value can be changed.
- •→
Data Types
Int, Float64, String, Bool; string interpolation ($) and text↔number conversion.
- •→
Operators
Math (+ - * / ÷ % ^), comparison (== != < >) and logic (&& || !).
- •→
Strings
Concatenation, interpolation, length (length), uppercase/lowercase, and search.
- •→
Arrays
Array creation, 1-based indexing, adding (push!), length and looping through.
- •→
Conditions (if / else)
Decision making with if-elseif-else; conditions without parentheses, blocks ending with end.
- •→
Loops (for / while)
Iteration with for using ranges (1:5), conditional repetition with while, and the global scope rule at the top level.
- •→
Functions
function...end block, single-line definition (f(x)=...), return and calling.
What you will learn
- Printing output with println and defining variables
- Array and matrix operations
- Writing functions and type declarations
- Writing different versions of the same function using multiple dispatch
- Loops and scope rules
- Adding libraries with the package manager
Who is this for?
- Researchers doing scientific computing and numerical analysis
- Those looking to transition from MATLAB or Fortran to a modern language
- Developers writing data and simulation tasks that require performance
When to use?
Julia is powerful for numerical simulation, differential equation solving, optimization, scientific modeling, and heavy matrix computation: it is both easy to write and fast.
Its ecosystem is not mature for web applications, mobile apps, and general software development. Also, because there is a compilation delay on the first call, very short-lived scripts do not feel as agile as Python.
Frequently asked questions
Will Julia replace Python?
It is gaining serious ground in certain areas of scientific computing, but in general use, Python's ecosystem is incomparably larger. The realistic picture is: Julia is chosen for numerical tasks requiring speed, while Python remains everywhere.
Why is it slow on the first run?
Julia compiles code just-in-time; when a function is called with specific types for the first time, a compilation cost is paid. When you call the same function a second time, the compiled version is used and it is very fast. This situation is known as "time-to-first-plot" and has been significantly reduced in newer versions.
What does multiple dispatch offer?
In object-oriented languages, a method belongs to a single class. In Julia, which version of the function runs is chosen by looking at the types of all arguments; this allows you to naturally define how two different types behave together. This is very valuable in mathematical code.
Do arrays in Julia start at 1?
Yes, it follows the tradition of MATLAB and Fortran. It suits the habits of the scientific computing community; it's a difference that those coming from Python need to watch out for.
Summary
Julia is designed for scientific computing by combining the convenience of a scripting language with the speed of a compiled language. In this tutorial, we progress from basic syntax to matrix operations and multiple dispatch.