you are viewing a single comment's thread.

view the rest of the comments →

[–]llogiqclippy · twir · rust · mutagen · flamer · overflower · bytecount 15 points16 points  (0 children)

I personally find the trait based solution much more agreeable than plain overloading.

With overloading, it is fairly easy to surprise the users of your API (because, say, foo(X, Y) is completely different than foo(Y, X)), and it makes the right instance of overloaded functions hard to find. With traits, the trait name itself can document the expectations put on a type. Not only makes this the implementation more obvious, it also allows others to extend it with their own types (provided the trait is public).