I would like to reopen this topic already discussed years ago at the following links:
I am used to write Python code, and I find the
if __name__ == '__main__' functionality very convenient in the Python open source environment, because it allows to reuse functions written by others (who maybe did not think they would have been useful outside their project) without modifying their code.
I am now dealing with a concrete case, which I submit here for advice. I am contributing to the static-julia project, whose main juliac.jl script calls the julia-config.jl script to define the proper
gcc compilation flags. To do this, since julia-config.jl is thought to be directly executed (see function
main()) and not to be included by other scripts, juliac.jl has to use the following awkward code to get the flags:
command = `$(Base.julia_cmd()) $(joinpath(dirname(JULIA_HOME), "share", "julia", "julia-config.jl"))` cflags = Base.shell_split(readstring(`$command --cflags`)) ldflags = Base.shell_split(readstring(`$command --ldflags`)) ldlibs = Base.shell_split(readstring(`$command --ldlibs`))
This of course is very inefficient.
In my mind Python’s
if __name__ == '__main__' functionality would be handy in this and similar cases. I would like to ask your opinion and advice on this.