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

I am not fond of the multimethods because they can easily tangle the code and give you a false sense of scalability. For example, in a blog post, "handle-action" is nicely decoupled with 3 different actions, but let's imagine how that will look after someone adds 20 new actions. Good luck debugging that.

Also, I saw numerous cases where people will copy/paste multimethod arguments without knowing what they are used for.

I still find case/cond more readable and way more performant, especially since the author uses the same type for a multimethod dispatch, but YMMV.



Case and cond are nice, but they suffer from the expression problem. When you want to let other people add methods to your code without modifying the source you need to use multimethods (or protocols).

If your method only needs 1 argument then why should the other ones matter? I don't see a problem here. clj-kondo will guide people to name them as _ or _thing anyway so you don't even need to think about it.


Multimethods also have some problems vs reloading that need working around.


case/cond is pretty readable, but I wouldn't say they provide a comparable api to multimethods.

From my perspective, I reach for multimethods when I want to provide my caller with the ability to declare their own "actions" as it were. The goal is to offer an open interface.

Without that need, yes, case or cond can be sufficient.




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

Search: