Appropriate Structures for Reusing Code

I’ve recently been forced to relearn python for a work application. Needless to say, after working with Julia for a while, there were plenty of things I found a little painful (vectorisation, the need to use numba/cython or even write in native C, etc.) However, one thing I did find helpful was how easy it was to structure your code in python, in such a way that it could easily be re-used. The ability to write a module with a bunch of useful functions once and then ever-after type “from xxx import yyy as zzz” is really nice.

Is there an equivalent structure in Julia, which can allow for easy reusability of key code?

1 Like

Yes. There are modules, and they act the same way. Julia packages are just a module like this.

4 Likes

Yea like Chris said you can make a package and import it(https://julialang.github.io/Pkg.jl/v1/creating-packages/),

Or if you’re hacking away prototyping you can also using
include("myawesomejuliascript.jl")
and it will run all the code in the specified file(https://docs.julialang.org/en/v1/base/base/#Base.include).

Well… that was simple. Thanks!

1 Like

You’ll probably find this easier in Julia than python :slight_smile:

There are also helpers like https://github.com/invenia/PkgTemplates.jl to auto generate the package structure with docs, Travis/appveyor testing and everything already set up.

1 Like