Julia for Analysts: Tips for Better Beginnings - The Bigger Picture (#5)

24 August 2022

TL;DR

After the first week, have a look at other tools that the Julia ecosystem offers (Revise, Logging, Debugger). After the first month, re-visit the tools to solve the biggest pain points you encountered. Julia is only a small part of any project's (model/insight/application) success - invest time in version control, experiment logging, effortless outputs, and automation.

Packages that I wish to have used earlier

Revise.jl

Revise.jl is the best thing since sliced bread! Your (loaded) code will magically update every time you make a change and you don't need to restart Julia.

I used to simply track my scripts with includet(), but I have now started creating a dedicated package for every mini analysis (with ]generate). As soon as it deserves its own folder, it deserves its own project specifications - there are several downstream benefits as well.

PkgTemplates.jl

If you're considering publishing your work, you should ALWAYS start your project with PkgTemplates.jl.

A turnkey solution for a modern Julia package - it can set up your folder structure, documentation, tests, git, Github actions, and many more.

Test.jl

Testing could not be easier (using Test)! I think the overhead for a light test suite is c. 2 minutes per function and it will save you countless hours of debugging!

My workflow:

Logging.jl

Part of the standard library, but awesome nonetheless. Macro @info is your friend and you will never use print again!

You can customize your loggers with LoggingExtras.jl.

Debugger.jl

Debugger.jl is an excellent tool to debug your code interactively without having to do any initial setup.

Infiltrator.jl is a lighter alternative if all you care about is setting a breakpoint and being able to inspect the context.

My typical workflow when I get an odd error from my_func_that_breaks()

using Debugger
names(Debugger) # to see the functions  it exports
break_on_error(true) #or break_on(:error)
@run my_func_that_breaks()
# once inside, type ? to get help, backtick to switch to julia execution mode, and q to quit

JET.jl

An awesome code analyzer, JET.jl, can catch your errors before you run your code.

Simply run: using JET; report_and_watch_file("my_script.jl",annotate_types=true)

JuliaSyntax.jl

JuliaSyntax.jl is an exciting new syntax parser that will give you much better error messages. I'm waiting for version 0.1 to add it to my startup.jl. Check out the JuliaCon 2022 video

Term.jl

Term.jl is mostly for building beautiful CLIs and terminal applications (similar to Rich in Python)

However, it has several nice methods for everyday use, eg, termshow(func) for displaying available methods and the soon-to-be-released @showme macro that will show you the definition of a given method instance.

JuliaFormatter.jl

JuliaFormatter.jl is a great saver and it makes your code much more readable.

All you need to do is to run: using JuliaFormatter; format(".") in your project directory.

Literate.jl

Literate.jl is your gateway to Literate Programming](https://en.wikipedia.org/wiki/Literate_programming).

In short, you can write your code as an easily readable and version-controlled script but with one command you can export it into Markdown, Notebooks, etc.

The best part is that you don't need to change almost anything - just add a # here and there to achieve the desired layout.

What are the benefits of Literate Programming?

In the world of data, it's often not enough that your code runs and tests succeed, you need to be able to explain it and document it for other stakeholders and yourself (there are sometimes 100+ projects in a year, would you really remember what you did?).

It is even more powerful when used with Quarto.

Quarto

Quarto is "an open-source scientific and technical publishing system built on Pandoc" (you could say it's a cross-platform successor to Rmarkdown + Knitr available to Python and Julia users).

I have not seen a better tool for parametrized runs and for publishing of beautiful reports in many output formats (presentations, HTML reports, and more).

See Using Julia in Quarto.

My workflow is often to push my script into Quarto Markdown (with Literate.jl) and then produce an HTML report (for distribution) and an interactive Revealjs presentation for the meetings. As an ex-management consultant, I cannot believe how easy it is to create such beautiful and professional presentations.

Re-think your overall workflow

Julia is only a small part of any project's (model/insight/application) success. Invest time in building a robust workflow around it.

The below overview has some pointers on what works well for me and my use cases.

My Project Ecosystem

Honorable mentions that I have seen used but have no experience with:

CC BY-SA 4.0 Jan Siml. Last modified: December 09, 2024. Website built with Franklin.jl and the Julia asdasdas programming language.