tags:

views:

120

answers:

2

What's the performance hit of using multi methods? If I have 2 functions with the same name, and the same number of arguments that differ only by the type (list vs. int), is my performance going to suffer much?

In other words, it it better to name my vector adding function: "add-vector" or leave it as "add" or possibly "+"?

(For the sake of simplicity let's ignore the problems I may have re-defining built-in functions like "+").

+5  A: 

There is a performance cost to using multi-methods, but unless absolutely necessary, you should continue to use them if they're the best abstraction.

That said, Clojure 1.2's protocols provide a native-speed alternative to multi-methods for certain use cases, and are particularly suited to cases where one might formerly have used a multi-method with a type-based dispatch.

sanityinc
Excellent, I think this is exactly what I'm looking for. Protocols should allow me to "override" the + function for my vector classes.
Timothy Baldridge
A: 
kotarak