3 ms·
You can't edit a function like that. If you add a new function definitoin for foo(x::Baz) then you will never enter the method that has those if else stat
by pdeffebach 6y ago
You can't edit a function like that. If you add a new function definitoin for
foo(x::Baz)
then you will never enter the method that has those if else statements. This is the benefit of multiple dispatch. You can't add more if else statements inside a method that is already written but you can add new methods.
- stabbles 6y agoManual 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.