A review of the Julia programming language

I recently had a need to do some calculations for a circuit design. So I started a Jupyter notebook, as I’ve done many times before, but after starting and looking at the horrible XML file format, I remembered Julia, and fired up a Pluto notebook. Some things I really like about Julia/Pluto:

  • file format is sane – simply Julia, easily stored in Git, diff’d, etc.
  • output of expressions is always displayed, but you can hide or show the source equation – this makes sense
  • language is very simple, yet powerful – seems perfect for calculations.
  • package system seems very powerful as its built in, vs something like Python pip, which you have to run external to the notebook

Using Python as a numerical tool works pretty well (I still fire up Python any time I need a quick calculator), but anything past the basics seems a little clunky as external packages are needed to do about anything.

But back to the Julia language itself – here are some neat things I’ve discovered in reading the language docs:

Dumping bits of a number:

julia> bitstring(0xf5f)
"0000111101011111"

Built in support for semantic versions:

julia> v"1.2"
v"1.2.0"

julia> v"1.2" > v"1.3"
false

Rational numbers (fractions):

julia> 3//4 + 1//4
1//1

Dot operators:

julia> [1,2,3].*4
3-element Vector{Int64}:
  4
  8
 12

Any unicode can be used for function names:

julia> ∑(x,y) = x + y
∑ (generic function with 1 method)

julia> ∑(1,3)
4

Most operators are just functions:

julia> 1+2+3
6

julia> +(1,2,3)
6

Array indices are 1-based, instead of 0-based like most languages:

julia> [1,2,3][1]
1

julia> [1,2,3][0]
ERROR: BoundsError: attempt to access 3-element Vector{Int64} at index [0]

Named tuples:

julia> x = (a="hi", b=3)
(a = "hi", b = 3)

julia> x[1]
"hi"

julia> x.a
"hi"

julia> x.b
3

This is not very far through the manual, so I’m sure there are a lot more interesting things to discover …

REPL is a good feature for a language i agree