Julia and VS code usage

Julia resources

Always use Revise.jl

This tracks changes and automatically updates code run from a REPL session.

julia> using Revise

VS code has an option to automatically load Revise.jl at startup (enabled by default).

Use Infiltrator.jl for debugging

https://github.com/JuliaDebug/Infiltrator.jl

The Debugger.jl built in to VSCode is an interpreter (Interpreter.jl), and is unusably slow for PALEO.

Install the VS code yaml extension

A VS code yaml extension is now available, https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml, this will flag errors in the PALEO yaml configuration files when opened in the VS code editor.

NB: The Julia YAML.jl parser allows duplicate keys (later key overwrites earlier) https://github.com/PALEOtoolkit/PALEOboxes.jl/issues/43. This is easy to hit when generating model configurations, the VS code yaml linter will catch this and other errors. If all else fails, check the .yaml file using an online validator eg http://www.yamllint.com/.

Julia best practices

Julia bugs/gotchas

  • Continuation lines in multi-line formulas can silently fail (this is easy to hit when copying across Fortran code). Workaround - add brackets.
  • Debug in VSCode is very slow. Use Infiltrator.jl instead.
  • Legends on subplots are merged with some backends eg plotlyjs (https://github.com/JuliaPlots/Plots.jl/issues/673). Workaround - use a different backend for multiple-panel plots.
  • jldoctest fails if there is an initial blank line (apparent off-by-one in input and validation output). TODO report.

Julia performance issues/gotchas

NB: the only place this matters in PALEO is for the model main loop. Everything else is non-performance critical. The PALEOboxes.TestUtils.bench_model function provides a convenient way of benchmarking a model and identifying problem Reactions (where all Reactions in the registered PALEO packages should have zero allocations).