Reverse domain notation?

The reverse domain notation is used by companies to name their Java packages.

So I’m wondering if this would also be practical for Julia projects?

Example:
Imagine an organisation has a domain called mycompany.org and you want to create a new project called MyProject2019 and MyProject2020 . In java you would do this with namespaces like org.mycompany.MyProject2019 and org.mycompany.MyProject2020 (directory: org/mycompany/MyProject2020/).

If you try this with modules and submodules in your julia project, you will have to name your root module “org”. This leads to an problem If your package is used by other companies. Other companies can not define “org” themselves because it already exists (and yes i know you will just get an “WARNING: replacing module” message…, don’t do this).

Wouldn’t it be wiser to replace the dot with an underscore instead and use the full domain as module name? (org_mycompany_MyProject2019 → No submodule tricks needed!).

I also found out that dot notation in module names can work. I did this with a macro and eval, but would this likely be considered bad practice?

Code:

macro module_with_dot(name::String)
    sym=Symbol(name)
    :(@eval module $sym; println("It works!"); end)
end

Test:

julia> @module_with_dot "org.mycompany.MyProject2019" # It works ?!
It works!
Main.org.mycompany.MyProject2019

julia> Main.org
ERROR: UndefVarError: org not defined

It would be cool if julia could provide Reverse domain notation without the use of macros.

What problem does it solve / what’s the advantage compared to using UUIDs like we do now? The latter are already collision-free.

1 Like

Problem: How can you import two packages with the same name but different uuid in your project? Inside your julia project you want link two packages with the same name in Project.toml (for whatever reason). Additionally you want to access their project (root) module which has also the project name:

  1. PackageA: src/PackageA.jl (CompanyA)
  2. PackageA: src/PackageA.jl (CompanyB)

You: using PackageA (CompanyA); using PackageA (CompanyB) ???

Now, you need to rename one of those packages to be able to use both (somehow).

I havent found a solution yet and i am not an expert in julia.

I think java went with the reverse domain notation so they won’t have to provide some sort of aliasing ability for classes. If two companies created the same package name with the same class there would be no way to distinguish which class in which package you wanted. All classes end up in the same namespace for lack of a better word.

In Julia modules can be renamed when loaded see:
https://github.com/fredrikekre/ImportMacros.jl
So we can avoid the name collisions. There is also an open issue to add aliasing support directly to the language:
https://github.com/JuliaLang/julia/issues/1255

So there is no real need to control how modules are named to avoid collisions.

6 Likes