Go and Julia Packages and Modules Compared
Comparing how Julia and Go deal with dependencies to other code
--
Julia and Go are a fun exercise in how terminology can get really confusing. In Julia and Go, the package and module concepts have basically been swapped.
The Go documentation defines a module as:
A module is a collection of packages that are released, versioned, and distributed together. Modules may be downloaded directly from version control repositories or from module proxy servers.
This is pretty much the reverse of Julia. In Julia a package is what get distributed and version controlled. A package however may contain multiple modules.
In Julia modules exist at the language level providing a namespace for your types and functions. In Go packages serve that same purpose. To be honest I think Go is the language that kind of screwed up in this case. Go began by rolling the idea of a namespace for code and the versioning and distribution of that code all into one concept called package.
Long term this was not a practical solution because Go did not offer a good way of specifying which particular version of a package your code depended on.
In Julia I can write the code:
using Greetings
message = Greetings.hello("Gladys")
println(message)
When I run this code, Julia will look at the current environment to figure out what actual package provides the Greetings
module which contains the hello
function.
In Julia this is determined by looking at a file inside our current package named Project.toml
. It says what our package is named and what other packages it depends on.
name = "Hello"
uuid = "f4029ba5-1bab-490d-8bbe-d6d1c8a1f0a8"
authors = ["Erik Engheim <erik.engheim@mac.com>"]
version = "0.1.0"
[deps]
Greetings = "1ef576d1-6215-4f11-828a-3bafa7859891"
For the purpose of figuring out dependencies our Hello
package is not actually called Hello
. That is what Julia's module system will refer to it as. Rather a unique universal identifier (UUID) is used. These are randomly generated and long enough to in practice have very low chance of being the same UUID as a package created…