I find it a little tedious to list out every function for exporting. And doing this (pulled from a thread a couple of years ago) feels bad:
module DemoModule
# 25 functions here...
for n in names(current_module(), true)
if Base.isidentifier(n) && n ∉ (Symbol(current_module()), :eval)
@eval export $n
end
end
end
Is there syntactic sugar to mark functions to be exported automatically? I'd like to draw an analogy to Python's syntax for public/private methods:
module DemoModule
function add(a, b)
# `add` is exported automatically
return _private_helper(a) + _private_helper(b)
end
function _private_helper(a)
# `_private_helper` should not be exported, so it's marked with a `_`
return a
end
end
Some Additional Context:
- This pain point is usually in the code/docs interface with
Documenter.jl
. I'm writing in both and realize "I forgot to export something". - There was a lot of discussion around this for type fields going back to 2015. Private properties in types/structs have some best practices, and the style guide was updated ~25 days ago to make this more explicit. I cannot find something analogous for functions though.
Aucun commentaire:
Enregistrer un commentaire