Fork me on GitHub
#clj-commons
<
2022-10-19
>
dpsutton19:10:50

does clj-commons/potemkin’s defprotocol+ support extend-via-metadata?

dpsutton19:10:05

appears that it can

lread21:10:19

I never really understood the advantages of potemkin’s defprotocol+. Do you have a good grasp on the advantages @U11BV7MTK? And if so, can you enlighten my poor wee brain.

dpsutton22:10:08

It does work. We have some records that serve as models. And a mechanism that checks a notion of can-read?. And this can depend on the collection that entities are in , and gets very domain-y. But there’s a protocol for things to identify as a model and if i can extend it by protocol then

(with-meta {:id 1 }{`models.dispatch/model
                    (fn [_] ::dispatches-on-dynamic)})
a simple map like {:id 1} can report it is a model and then i can sub out what can-read? means for a simple map

dpsutton22:10:03

otherwise i’d need to make a defrecord, have it implement the model dispatch stuff, etc

dpsutton22:10:15

and just for a simple test i don’t want records and a bunch of junk

dergutemoritz10:10:21

That's the advantages of extend-via-metadata though, not of defprotocol+ right? 😄

dergutemoritz10:10:52

IIRC the advantage of the latter is that recompilation retains the protocol's identity when possible?

dpsutton12:10:36

Oh good point. I misread which part the question was about. Yeah it’s basically a defonce on a protocol that is aware when it needs to recompute

lread13:10:14

Ah thanks! So a performance concern, ya? Do you know of any existing benchmarks of defprotocol vs defprotocol+? I'm a bit curious, your mention of it here surfaced a memory of me replacing defprotocol+ with defprotocol it when moving to cljc for rewrite-clj v1.

dpsutton13:10:15

It’s not performance. There’s a thread in #C053AK3F9 about the pain right now

lread13:10:43

Oh, thanks, I'll go check it out.

dpsutton13:10:09

It’s in #C03S1KBA2 I was mistaken

lread13:10:45

Oh.... gee, thanks, that helps! Thanks a ton @U11BV7MTK and @U06GVE6NR!

lread14:10:27

I created an https://github.com/clj-commons/potemkin/issues/67 to describe defprotocol+ in the potemkin README.