Although I’ve found coming to Julia from Python to be straightforward and even delightful sometimes. However, as I’m scaling up my program (a Julia implementation of the UCR Dynamic Time Warping Suite of Optimisations), I’m hitting a few problems.
Are there any relatively small packages I could imitate the structure of?
The problem in the stackoverflow question is that you have managed to create two Query types. One inside of Structs (which would be Structs.Query) and one inside of Utils (which would be Utils.Structs.Query).
Remember that include is pretty much copy and pasting the code in place so if you include a file twice, it will get executed twice.
We can look at what type dist is defined on:
julia> methods(dist)
# 1 method for generic function "dist":
[1] dist(x::Main.Utils.Structs.Query, y::Main.Utils.Structs.Query) in Main.Utils at utils.jl:9
There is no way for Julia to know that Utils.Struct.Query is the same as Query. Rewriting your file to use the same Query struct:
include("utils.jl")
using .Utils: dist
a = Utils.Query("a", 1)
b = Utils.Query("b", -1)
println(dist(a, b))
You are absolutely correct. However, this solution seems a bit (subjectively) ugly. It seems to tell a potential reader of the code to look for the definition of Query inside of Utils, when it is actually defined in Structs. Is this a symptom of my project structure or something else?
Use using ..Structs: Query inside Utils.jl instead of reincluding the file. The .. goes up one module higher and uses the existing Structs module defined there.
This is the same what I have written on SO (I have read the question there first).
However, you could define Query module inside a local Query package and then after adding this package you can do using Query inside Utils module and also do using Query in the outer scope and Julia will know that this is the same Query - right?