clojuredesign-podcast

Discussions around the Functional Design in Clojure podcast - https://clojuredesign.club/
nate 2020-10-23T19:14:30.039700Z

In today's episode, we talk about multimethods: https://clojuredesign.club/episode/087-polymorphic-metal/

1
👂 1
bartuka 2020-11-05T01:26:29.045400Z

Nice episode. @nate you mentioned about using (def my-interface nil) to not loose your repl session and keep your defmulti in sync... there is also another trick that I use to do the same.. I find it a little bit easier (maybe bc I'm used to it)

(defn dispatch-fn [m]
  (:nice-logic m))

(defmulti my-interface #'dispatch-fn)
if you re-eval the definition of dispatch-fn there is no need to re-eval the defmulti, everything is synced! 😃

nate 2020-11-05T01:44:45.045600Z

That's a great tip. I'll have to try that next time to prevent wedges related to the dispatch. It's a nice way of controlling the dispatch function outside of the multi. Also, having it as a top level fn makes it easier to print the dispatched return value for debugging.

bartuka 2020-11-05T02:00:38.045800Z

Exactly! I work processing several files where 70% of their content is the same, but 30% is wildly different. I pray for multimethod everyday! haha. Another tip would be the usage of https://github.com/aleph-io/potemkin import-vars to combine definitions and implementations in the same namespace. (when you need to have them separate for ny reason) Let says we have interfaces.clj and impl1.clj, impl2.clj , etc.. now you have several files to remember requiring when you want to use a specific interface+implementation.. you can glue them together in a feature.clj namespace using import-vars. Now, you are sure that the interface and the implementations are both required and you only need to look into feature.clj

nate 2020-11-05T02:44:12.048200Z

Interesting. I've only heard of potemkin, haven't needed it so far.