6 ms·
Manual dispatch can be an antipattern hindering composability though. If package A does: function foo(x) # some lines of code y = x isa Int ? 2
by stabbles 6y ago
Manual dispatch can be an antipattern hindering composability though. If package A does:
function foo(x)
# some lines of code
y = x isa Int ? 2.0 : 3x
# some other lines that do things with y
end
Then package B would have to define foo(x::MyType), copy the contents from package A, change the `y = ...` bit, and make sure the rest stays in sync with package A.
If instead package A did this:
foo_magic(x::Int) = 2.0
foo_magic(x) = 3x
function foo(x)
# some lines of code
y = foo_stuff(x)
# some other lines that do things with y
end
Your package B could just add an extra definition of foo_magic(x::MyType) instead.