Global variables and program structure

One of the main problems with that style is that your logic is non-local and hard to debug.

Put your variables into structs, and pass those around (see Parameters.jl for some helper macros). Break your functions up into smaller ones which only do one thing and thus only need access to a few variables. Compose those smaller functions into larger ones.

There is definitely a trade-off between quick programming and writing maintainable code. But at least for bigger projects it does pay off as eventually there will be code maintenance and refactoring.

4 Likes