2 ms·
The problem is when you have the functions: Square.computeArea() Circle.computeArea() Clearly these should do different things. I suppose "computeArea(shape)
by feoren 4y ago
The problem is when you have the functions:
Square.computeArea()
Circle.computeArea()
Clearly these should do different things. I suppose "computeArea(shape)" does dynamic dispatch based on the type of shape? But you're still putting every function defined on every type in your entire codebase in a global namespace. It's not obviously awful but I'd definitely be a bit nervous about it.
- ilyt 4y agoI dunno, I kinda like that, add sum types and you can pass anything to computeArea. The problem really starts when you have typeA.func() typeB.func(x) typeC.func(x=default_value)
- jdmichal 4y agoYou only need dynamic dispatch if dynamic types are involved. If you can always resolve to concrete types, then you can statically resolve the required function.
- lalaithion 4y agoIt doesn't have to be dynamic dispatch; you could also do static dispatch at compile time based on type information.