Closed rafaqz closed 5 months ago
Not sure I understand the rationale here, can you elaborate?
Ok. So I want to add Interfaces.jl to a package, without adding a full dependency on it or adding any overheads.
Theyre not so bad, but I imagine people will want a no cost option initially. And if all the interface tests get really long it will have some small overhead.
So the options to do that are:
Its kind of annoying to have to do 1 everywhere. But 2 doesn't actually work currently, because if you use the @interface
macro in an extension, the types it generates are hidden in the extension and not available in the package.
So we need to define the interface type in the main package, e.g. in DimensionalData.jl.
So:
Interface
type that all interfaces depend on to InterfacesCore.jl, with a small macro for adding core interfaces.@interface_core
macro to define our interface type DimArrayInterface
without any tests inside DimensionalData.jl scopeDimArrayInterface
type into the extension from DimensionalData.jl@interface ...
in the extension using the existing interface typetest
function, so they will always have the full DimensionalData.jl interfaces available.I guess this should be the package readme
Is an 8-step procedure really worth the trouble of what is probably a very small package overhead? If Interfaces.jl is to be widely adopted it must be very simple, and that split makes it so much more complicated.
Can we quantify the overhead somehow?
Yeah, maybe not worth it its very little overhead. This is Interfaces.jl + DimensionalDataInterfacesExt.jl
julia> using DimensionalData
julia> @time using Interfaces
0.004137 seconds (4.39 k allocations: 334.969 KiB)
But didn't you put the Graphs.jl interface in a separate package? That's the problem I'm trying to solve.
But didn't you put the Graphs.jl interface in a separate package? That's the problem I'm trying to solve.
Two reasons for that
SimpleWeightedGraphs
and the like, which are not dependencies of Graphs.jlBut I didn't have to put the checks in the same place as the definition. Ideally the definition should go in Graphs.jl and the checks in each implementing package, as God intended
It just feels a bit weird putting the interface tests in runtime code with the rest of the package, and I'm guessing some people wont like that. But maybe its not an issue
I think we'll cross that bridge if we get to it. What I like about your approach is that the design is dead simple, let's not overcomplicate it to gain 4 ms.
If you really care about moving the tests out of runtime code, maybe there could be an extension of Interfaces.jl that depends on Test being loaded?
Yes could be interesting to use Test
as the weak dep. Have to think about how that works.
For now I'll move the DimensionalData.jl interface to the package.
And your right keeping it dead simple might be the most important thing here.
Thanks for the feedback
This PR adds an InterfacesCore.jl subpackage.
All it implements is
abstract type Interface end
and a@interface_type
macro.The reason for this is so we can define the interface type without any package overheads, and add Interfaces.jl as an extension. This means packages can just go
using Interfaces
and test their implementation, rather than needing to load another package.We cant use extensions currently because the type would be defined in the extension, and not be accessible to anyone.