2024-07-11 –, REPL (2, main stage)
Interfaces.jl is an attempt to solve Julias lack of explicit interface declarations. It provides macros to define and implement interfaces concisely, and functions to test and check that they are implemented correctly.
Its subpackage BaseInterface.jl defines some common Base Julia interfaces using Interfaces.jl.
This talk will cover things learned writing and using the package, and hopefully inspire some discussion on the future of interfaces in Julia more broadly.
Julia lacks a built-in method for defining strict interfaces. Instead, we use an ad-hoc combination of inheritance, traits, documentation, interface tests, and usually, run-time errors when something is not implemented!
At the same time we rely heavily on shared interfaces for high levels of package interop, and this combination makes better interfaces a common request from Julia developers.
There are a number of efforts underway exploring how interfaces could work better in Julia. This is just one of those, and certainly not the most sophisticated one!
The general assumptions of Interfaces.jl are that:
- Interfaces can enforce both run-time and compile-time constraints, e.g. it is reasonable to insist that a method must return a positive valued
Int
- Interfaces often need optional components, such as mutability in AbstractArrays
- Interfaces can be tested for package types only if given a specific object with that type
- Interfaces definitions should provide traits other packages can check
- Interface implementations should be verified during tests or package precompilation
- The easiest way to define an interface is to simply provide a named list of functions that test all the mandatory and optional ways an object should behave.
We get these properties by defining a simple NamedTuples of functions, and a mechanism to make some of those names optional in the @interface
and @implements
declarations.
By providing data during @implements
declarations we can also programmatically test interfaces implementations in any object, package or multiple packages with a single command.
Slides: https://rafaqz.github.io/JuliaCon2024-Interfaces/
Video: https://www.youtube.com/live/Bo3k4oD1Avg?feature=shared&t=27085
Rafael is an Ecologist at the Center for Macroecology, Climate and Evolution in Copenhagen. He works on process-based ecological models of species distributions, dispersal, threats and extinction, and contributes to a variety of geospatial, modelling and visualization packages.
- DimensionalData.jl: named dimensions for julia data
- JuliaGeo BoF: shared interfaces and plans for geospatial julia
- Rasters.jl: raster data and GIS tools for julia
- What’s new with GeoInterface.jl: traits for interoperability
- GeometryOps.jl: Building a Comprehensive Native Geometry Package
- SpeciesDistributionModels.jl: an SDM workflow
Postdoctoral researcher at EPFL (Switzerland) in the INDY, IdePHICS and SPOC labs.
Currently working on graph machine learning.
Active member of the JuliaGraphs and JuliaDiff organizations.
Personal website: https://gdalle.github.io/