In this article I'm listing some checkpoints in learning a new programming language in general and provide entry points to Julia which I find useful.
My current task was writing a demonstration code in Julia for refreshing undergraduate econometrics(doing this in a language I know is not challenging enough). I wrote this article while doing this task (well, certain times, instead of doing econometrics).
As a general note, I think there should be something exciting that makes you learn a new programming language. In Python for me it was a clean syntax and easy access to object oriented programming (OOP), in Julia it is the typesystem and functional flavour. Julia is not perfect as the first language because of lagging documentation and a small and version-divided Stack Overflow answer corpus, but it is you are into 'start and do' attitude, there are quite a few benefits to reap. As a younger language Julia assembled concepts and best practices from many predecessors and offers an exciting mix of features.
All language documentations follow some hidden pattern, but is there one
stated explicitly? Here is my version for a "universal mindmap to learn any programming language" (next best is "code, code, code").
- arithmetics, using REPL as a calculator
- variable assignment
x = 5; s = "Hello!"
- native data structures (array or list, dictionary, set, tuple)
- function syntax
f(x) = 2x
- flow control (do..end, for/while, if-then-else)
- input and output (print to console, read from file)
- exceptions, try-catch error handling
- Additionally you'd want to look into syntax for arrays, sequences/iteration, comprehension and string operations.
- The statistical langauages would have some versions of a dataframe structure to assist working with tabular datasets.
- Data structures beyond basic types
- Support for OOP and its replacements if no OOP (method broadcasting in Julia)
- Functional features (lambda fucntions, currying, pattern matching, etc)
- some language philosophy (everything is a... function, expression, object)
- popular libraries and their alternatives
- what language authors had in mind and what is their sense of beauty
- why people stick to this programming language? what backgrounds they came from?
- package manager
- interpreter options, compiling to an executable
- list of keywords
- core language, base and standard library
- type system
While learning Julia I started documenting the surprises: something negative that breaks a "least astonishment" principle, but also something positive, where you say "thank you so much for doing it this way, I was hoping for it in python, R, etc."
You actually learn from both kind of surprises, in a different way. A negative surprise may have a different reason than neglect or malicious intent, it is a (good or bad) design decision with some ideas behind it. The positives surprises just make you slightly happier.
Julia sometimes seems to be following MATLAB (array manipulation), opposing python (for syntax) and trying to be lisp (functions). Sure, why not inherit good things, but still few things raise eyebrows:
- dictionary syntax with
Type system. If I had to name a single best feature about Julia that would be strong type system. Python type hinting is just about getting there, and Julia already feels like a bit of Haskell: you can have explicit function signatures (makes running things fast and your code transparent) or compiler will try derive them for you (if you do not feel the advantage and excitement of coding that yet).
# This function accepts only string as argument function greet(name::String) println("Hello, $name") end # This function is defined for integer arguments # and returns a real number function div(a::Int, b::Int)::Real b != 0 || throw(DivideError) return a / b end
Other big thanks:
- fast compiler
- one line function definitions
greet(name::String) = println("Hello, $name")
- simple start with unit tests with
- mathematic notation greeks support:
- MATLAB-like array manipulation
- user-defined function vectorisation with
'is for one character (like
"is for string (like
- project structure - Julia very silently assumes a project should have
MyModule/src/MyModule.jldirectory structure, I wish it was better documented
- built-in package manager:
]starts to win for me)
- own forum vs Stack Overflow
- overlapping packages of different provenance for similar tasks, annoying for beginner, but hey it is a young ecosystem (was it this way in early python?)
- error messages could be friendlier
- one-based list index: with python I almost got convinced zero-based was a true thing
Really black magic to me yet:
Julia, why? is not likely to be corrected, but there are few things that actually may improve. I side with this user for Julia development priorities:
- compiling to executables
- better error messages
- a debugger
As also mentioned in that thread, integration with Spyder IDE could be nice. Spyder seems to carry the traditions on RStudio and Matlab for 'scientific experimentation' with code, enabling to try small parts of the code and assemble them to larger programs. Technically, other IDEs do not forbid that, but practically, Spyder is much more convenient for this try-and-see approach, even though I have a feeling it falls out of mainstream IDEs, there is so much focus of Jupyter now.
Julia documentation - the style of writing that puts large chunks of text before getting practical is terrible to digest. Hope developers are courageous enough to scrap some part of the documentation for the better.
However, one should remember to take free software as a gift, so I'm grateful to what Julia achieved so far and made available for use.
Do not make Julia your first programming language - there are far less examples on Stack Overflow than python and R (in a magnitude of hundereds vs 5-20 of votes per similar question), which limits quick googling-learning, also choosing a proper library is sometimes ambiguous. Julia borrows heavily from python, R, Matlab, lisp, maybe Haskell, and some features are better exposed and documented there than in Julia.
For some tasks the speedup comes from Julia compiler, but often C-based python libraries almost as faster and better developed. The real sweet spot is ability to do static typing, this will help Julia develop long-term over python (extreme view: any dynamically typed program over 200 lines of code is trash). Yes, we have type annotations in python, but they just produce lint messages so far.
Skip a question which is a better language to learn - start with some microtasks in any language and see where your progress is the fastest. Learn any second language because you are likely in a trap of some sacrifices been made by developpers of the first language you learned. That means you of not likely to write scalable and maintainable programs in the first language of your choice.
Pick a small nice actively maintained project on Github to learn about Julia in production. My choice in Turing.jl and VLMS.jl, based on a great course in linear algebra and applications, but you can check any of trending repos.
I like all the stack of Quantecon.org both for python and Julia, there are lectures and quick cheatsheets, the pace of delivery and wording look very good to me. Recommended even if you are not in economics.
How is Julia different from other programming languages is a good section in Julia docs, very saturated with food for thought.
Vectors, Matrices and Least Squares textbook, course and Julia package.
Julia for Machine Learning, exceptionally clean and sane 2014 Julia language presentation, very relevant as an intro.
We all should all read the docs, but Julia docs are a bit of a pain to read through in some sections - too much blind text.
While google you often land to Julia wiki. I hate the visual design of the site, but selection of topics covered is right.
Think Julia: How to Think Like a Computer Scientist - a replica of similar python book, nice, but a bit too long.
I like Bogumil Kaminski's work and his quick intro to Julia, it is just 12 pages and gives you an idea of the language (a PDF could use some syntax highlighting, though).
Julia Tutorial by J Fernandez-Villaverde, a part of larger work of computational economics.
Exploring Julia. A Statistical Primer, nice 200+ pages on stats and Julia.
- Example.jl (basic package structure)
- QuantEcon.jl (simple to more complex computational tasks)
- VMLS.jl (learning companion to a great book and course)