DEV Community

Evgeny Pogrebnyak
Evgeny Pogrebnyak

Posted on • Updated on

Julia, surprise me! (some astonishments while learning a new programming language)

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.

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?

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

# 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 
Enter fullscreen mode Exit fullscreen mode

Other big thanks:

  • fast compiler
  • 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 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 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

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:

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

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 and VLMS.jl, based on a great course in linear algebra and applications, but you can check any of trending repos.

4. Suggested reading

Priority

Other book-like choices

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

Stack Overflow and similar on various topics

Top comments (4)

Collapse
 
jmccabe profile image
John McCabe • Edited

Essential to a new language, for me, means lots of things but, in particular, getting away from idiotic syntax. A prime example is confusion with = and ==. The latter is stupid; = should be the equality operator and something else, e.g. := (like in some of the most well-designed and thought out languages of the last 40+ years, Pascal, Modula-2, Ada etc) used for assignment.

Another is Java's short-circuit logical operators; for a language that has such close ties to C++ (and C), the choice of & and && was phenomenally stupid. This is another place where Ada is superior, using 'and', and 'and then' (alternatively 'or' and 'or else') to differentiate between normal and short-circuit versions.

In addition, the language really needs to be able to do things that are impossible in existing languages.

Most of the 'new' languages I've seen over the last 30 years, especially the last 10 years, are just because some developer's ego has got the better of them. These are talented people, very talented in most cases, but their efforts would be better spent getting more involved in enhancing features of existing languages, rather continuing to fragment the market with more and more niche languages that won't last after the original author has got bored with it.

Collapse
 
epogrebnyak profile image
Evgeny Pogrebnyak

One developper's ego brought Python to us, for example. I would not be so sceptical of new languages. ) And Julia is cool. ))

Collapse
 
jmccabe profile image
John McCabe

Don't get me started on Python; had the geezer whose ego resulted in Python actually paid proper attention to 'real' programming languages, he wouldn't have decided to use exclusively zero-based indexes in sequences/lists (that's just lazy), nor specification of ranges from 'start index' to 'end index + 1', e.g. a slice a_list[12:15] isn't a 4 element subset of a_list made up of the items in index 12 through 15, it's a 3 element subset including items 12 through (15 - 1). This is related to the zero-based indexing; a_list[:12] gives you 12 elements starting at 0.
The point of a high level language is to allow us to abstract the implementation away from the machine domain into the problem domain; exclusive zero-based indexing at the source code level is nonsense.

I haven't looked closely at Julia; how closely based on C is it? What features does it have that 1) aren't in any other language and 2) couldn't possibly have been added to another language?

Collapse
 
aminmansuri profile image
hidden_dude

10 THESE: NEW LANGUAGES
20 ALL LOOK THE SAME

Where isThe new: syntax.

(varied-syntax (had old languages))

so_boring[is, the, "new"].

Nothing new here it all looks like C/Javascript now.