Introduction to Julia (Julia Academy): Where loop issue

Thanks for putting together the Introduction to Julia (Julia Academy) videos and notebooks.

Working through the video’s I was using a Julia terminal-REPL session, and bumped into the global/local variable issue when working through the “Loops” section.

After some head banging, I now know this issue has been previously discussed.

@jeff.bezanson has a useful comment that I think could be added to the Introductory materials.

Julia has two kinds of variables: local and global. Variables you introduce in the REPL or at the top level, outside of anything else, are global. Variables introduced inside functions and loops are local. Updating global variables in a program is generally bad, so if you’re inside a loop or function and want to update a global, you have to be explicit about it by writing the global declaration again.

Jeff also has another useful suggestion:

I suggest teaching functions first, before for loops. Functions are more fundamental anyway, and this will help set the expectation that code should be written in functions.

Rather than complicate first time users with getting their set up to match Jupyter (SoftGlobalScope.jl) it might be better to:

  1. Have the section on “Functions” right after “Data Structures”:
    • Emphasize the Julian way (best practice?) is to put (every?)thing in functions.
    • Close with Jeff’s comments about local vs. global, and the examples from Iain Dunning
  2. Have the section on “Loops” right after “Functions”, but now written using functions - this way terminal-REPL and Jupyter users should experience the same behavior.

To be clear, with 20+years of writing lectures and tutorials, please don’t think I underestimate the time it will take to make any changes to these materials.

Thanks again for all the effort put into the JA lessons.