Hei there julians! Let’s say I’m working on a Julia App and I organize my code in a MAIN.jl script and mayn other scripts, which I call from the MAIN.jl with include(). The structure can be nested, so the scripts included in MAIN.jl can include() other script files as well.
And now let’s assume two case scenarious:
I’m running my App directly from Julia, without precompilation
I’m compiling my code into an executable and then I’m running it
Would my many include() calls impact performance in the the two cases above? My guess would be that, if at all, it would impact the parsing and compilation steps.
It should have a negligible impact (compared with simply pasting all of the code into a single file).
However, if you are writing re-usable code, I would strongly encourage you to think about putting the re-usable pieces into modules/packages, rather than thinking of it as “scripts”. (And write callable functions, not runnable scripts.) See also Best practise: organising code in Julia - #2 by stevengj
@stevengj Thanks for the fast answer! I’m happy to hear that include() impact on performance is neglijible.
And yes, you are absolutely rigth, the best code organization is into modules/packages. And I’m doing that also. However, within one module, I still feel the need to split the code into smaller units, so that I can navigate it easier. It is just a personal preference, but already 100 lines of code in one file becomes too much for me and I’m splitting it as soon as I find a logical way to group the code. I would be happy with one big file if I my IDE (VSCode) would have some type of toggle sections.