Julia, surprise me! (some astonishments while learning a new programming language)
Tags: julia, julalang
Published: 2018-12-02 23:51:06

---
title: Julia, surprise me! (some astonishments while learning a new programming language)
published: true
description: Checkpoints for Julia, positive and negative surprises and tips for self-study.
tags: julia, julalang
---

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](https://julialang.org/blog/2012/02/why-we-created-julia). 


1. What is essential to a new language
--------------------------------------

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"*).

### Minimum

- arithmetics, using REPL as a calculator `>1+1` prints `2`
- 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

## Next in line 

- 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)


### Soft issues 

- 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?

### Ecosystem

- package manager
- interpreter options, compiling to an executable
- IDEs
- debugger
- plotting

## A more comprehensive view: what is the total of a language?

- [list of keywords](https://stackoverflow.com/a/52341209/1758363)
- core language, base and standard library
- type system

2. Surprises 
------------

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, why?

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:

- keywords `function` and `end` (Ruby, no!)
- dictionary syntax with `=>`
   

### Julia, thanks!

**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).


```julia
# 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](https://www.sas.upenn.edu/~jesusfv/Update_March_23_2018.pdf)
- one line function definitions `greet(name::String) = println("Hello, $name")`
- simple start with unit tests with `@assert`, `@test`, `@test_throws` 
- mathematic notation greeks support: `\beta<tab>`
- MATLAB-like array manipulation
- user-defined function [vectorisation](https://julialang.org/blog/2017/01/moredots) with `.f`
- the `'` is for one character (like `'a'`), `"` is for string (like `"Hello!"`)

### Julia, I'm learning!

- project structure - Julia very silently assumes a project should have `MyModule/src/MyModule.jl` directory structure, I wish it was better documented
- built-in package manager: `]` vs `pip` (`]` starts to win for me)
- [own forum](https://discourse.julialang.org/) vs [Stack Overflow](https://stackoverflow.com/questions/tagged/julia-lang)
- 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

Small things:

- one-based list index: with python I almost got convinced zero-based was a true thing
- putting `end` and no `:` in functions

Really black magic to me yet: 

- [macros/metaprogramming](https://docs.julialang.org/en/v1/manual/metaprogramming/index.html#Functions-on-Expressions-1)

### Julia, we are hoping

*Julia, why?* is not likely to be corrected, but there are few things that actually may improve. I side with [this user](https://discourse.julialang.org/t/list-of-most-desired-features-for-julia-v1-x/4481/83) 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](https://docs.julialang.org/en/v1/stdlib/Pkg/index.html#Introduction-1) 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](https://gist.github.com/richhickey/1563cddea1002958f96e7ba9519972d9), so I'm grateful to what Julia achieved so far and made available for use.


3. Rules of thumb 
-----------------

1. 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. 

2. 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. 

3. 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. 

4. Pick a small nice **actively maintained project on Github** to learn about Julia in production. My choice in [Turing.jl](https://github.com/TuringLang/Turing.jl) and [VLMS.jl](https://github.com/VMLS-book/VMLS.jl/blob/master/src/VMLS.jl), based on a great course in linear algebra and applications, but you can check any of [trending repos](https://github.com/trending/julia?since=monthly).

4. Suggested reading
--------------------

### Priority

- I like all the stack of Quantecon.org both for python and Julia, [there are lectures](https://lectures.quantecon.org/jl/index_learning_julia.html) and [quick cheatsheets](https://cheatsheets.quantecon.org/julia-cheatsheet.html), 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](https://docs.julialang.org/en/v1/manual/noteworthy-differences/) is a good section in Julia docs, very saturated with food for thought.

- A central cheatsheet like [this](https://juliadocs.github.io/Julia-Cheat-Sheet/) and several useful R-Matlb-numpy-Julia comparison charts ([hyperpolyglot](http://hyperpolyglot.org/numerical-analysis2#numpy), [quantecon.org](https://cheatsheets.quantecon.org/))

- [Core idea of Julia](http://ucidatascienceinitiative.github.io/IntroToJulia/Html/WhyJulia#Core-Idea:-Multiple-Dispatch-+-Type-Stability-=%3E-Speed-+-Readability), found in a very tidy [introduction Julia](http://ucidatascienceinitiative.github.io/IntroToJulia) by Chris Rackauckas 

- [Vectors, Matrices and Least Squares textbook](https://web.stanford.edu/~boyd/vmls/vmls-julia-companion.pdf), course and Julia package. 

- [Julia for Machine Learning](http://www.cs.toronto.edu/~jsnell/assets/julia-tutorial.pdf), exceptionally clean and sane 2014 Julia language presentation, very relevant as an intro. 


### Other book-like choices

- We all should all [read the docs](https://docs.julialang.org/en/v1.1-dev/), 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](https://en.wikibooks.org/wiki/Introducing_Julia). I hate the visual design of the site, but selection of topics covered is right.

- [Think Julia: How to Think Like a Computer Scientist](https://benlauwens.github.io/ThinkJulia.jl/latest/book.html) - a replica of similar python book, nice, but a bit too long.

- I like Bogumil Kaminski's work and his [quick intro](http://bogumilkaminski.pl/files/julia_express.pdf) 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](https://www.sas.upenn.edu/~jesusfv/Chapter_HPC_8_Julia.pdf), a part of larger work of computational economics.

- [Exploring Julia. A Statistical Primer](https://people.smp.uq.edu.au/YoniNazarathy/julia-stats/exploring-julia-a-statistical-primer-DRAFT.pdf), nice 200+ pages on stats and Julia.

### Learn by package

- Example.jl (basic package structure)
- QuantEcon.jl (simple to more complex computational tasks)
- VMLS.jl (learning companion to a great book and course)


### Example-based introduction

- [38 excercises with Julia](https://github.com/DataWookie/MonthOfJulia)
- [Julia By Example](http://samuelcolvin.github.io/JuliaByExample), nice but could use some prioritising/cleaning.

### Stack Overflow and similar on various topics

- [docstrings](https://stackoverflow.com/questions/19821247/how-to-make-user-defined-function-descriptions-docstrings-available-to-julia)
- [reserved words and undocumented --lisp flag](https://stackoverflow.com/a/52341209/1758363)
- [using vs import](https://stackoverflow.com/questions/27086159/what-is-the-difference-between-using-and-import-in-julia-when-building-a-mod)
- [cli args](https://stackoverflow.com/questions/21056991/access-command-line-arguments-in-julia)
- [is Julia homoiconic?](https://stackoverflow.com/a/31734725/1758363)
- [multiple dispatch](https://stackoverflow.com/questions/33755737/julia-oop-or-not/34928086#34928086)
- [workflow with 1.0 packages](https://medium.com/@Jernfrost/my-new-workflow-with-julia-1-0-99711103d97c)
- [package introspection with `varinfo()`](https://stackoverflow.com/questions/21301451/get-a-list-of-current-variables-in-julia-lang)
- [my sad beta-hat on windows story](https://github.com/JuliaLang/julia/issues/30175)
- [lisp roots](https://tpapp.github.io/post/common-lisp-to-julia/)
- [what is `@.` in Julia `--project` command line option?](https://stackoverflow.com/questions/53613663/what-is-in-julia-project-command-line-option)
- [tentative Pkg3 docs](https://docs.google.com/document/d/1pdfao38w8fgSnEvf1JkF4Dz2EipWJK1TmaNCUXAlRVc/edit)