Fork me on GitHub
#clojure-uk
<
2022-02-08
>
folcon02:02:04

Hmm, ok those are some definite upsides. So I've been wondering protocol or multimethod, I previously used protocols, the only problem is I need to define behaviour on a per instance basis, which makes me think multimethods are the right way to do this. I was wondering if I should reach for :extend-via-metadata instead, that way I could default to a noop if the record in question is missing the key of interest for the function, but otherwise it should work?

seancorfield03:02:35

As long as your protocol has a default implementation (for Object) that is a no-op, I think that should work...

seancorfield03:02:21

@folcon Yeah, it works:

dev=> (defprotocol Basic :extend-via-metadata true (do-it [_]))
Basic
dev=> (extend-protocol Basic Object (do-it [_] (println "Object!")))
nil
dev=> (do-it {:a 1})
Object!
nil
dev=> (do-it (with-meta {:a 1} {`do-it (fn [_] (println "Special!"))}))
Special!
nil

dharrigan06:02:08

Good Morning!

folcon12:02:28

Awesome @seancorfield ๐Ÿ˜ƒ... I'll have to try that approach and see if it's workable ๐Ÿ˜ƒ...

Aron13:02:51

brainwarp

Aron13:02:05

I wish I could hear how people read the code they write, it would be much easier to understand

folcon13:02:56

Interesting thought ๐Ÿ˜ƒ... I wonder if reading aloud the code I write would improve readability, similar to what I sometimes do when blog writing...

Aron15:02:19

yes, definitely

Aron15:02:27

especially with naming things

1
Aron18:02:41

although, if you read i or idx as Index then it might not work ๐Ÿ™‚ I just realized because our frontend is full of buttons that are called btns

folcon21:02:54

I definitely read idx as index, i / j as index keys I'd recognise, but it would not be reading, more recalling ๐Ÿ˜ƒ

folcon22:02:35

Ok, I've still not really used datafy and nav, I'm starting to work with really messy complex datastructures, is REBL still being used, or has something supplanted it? EDIT: Trying out https://github.com/djblue/portal/