Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



You 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.


It doesn't have to be dynamic dispatch; you could also do static dispatch at compile time based on type information.


I 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)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: