Fork me on GitHub
#clojure-uk
<
2019-08-14
>
dharrigan05:08:34

Good Morning! Thanks everyone for the interesting discussion yesterday on keyword arguments and destructuring. Lots of food for thought!

👍 12
dharrigan05:08:41

I hope people have a nice day today! 🙂

guy07:08:54

morning!

dominicm07:08:48

the police were circling overhead again last night, horrible night's sleep

guy07:08:32

but at least you managed to avoid them! 😉

dharrigan07:08:11

@dominicm that happens where I live now and again. It's terrible, I agree. Can't sleep when that happens (I'm a light sleeper anyway)

dharrigan07:08:33

Where's the silent black helicopters then? Surely they have them (on loan from Mr Trump?)

benedek07:08:23

morning. quiet, rainy day ahead at ldn. perfect for coding

folcon10:08:23

Clearly quite late to yesterday’s discussion, but does anyone use the namespaced version of :keys?

(defn some-fn [{:user/keys [username] :actions/keys [history] :as _opts}]
  ...)
Or is it more:
{{foo-id :id :as foo} :foo 
 {bar-id :id :as bar} :bar}

dominicm10:08:21

I use the :user/keys syntax too. I think it's better than :keys [:user/foo]

Olical10:08:45

Huh, had no idea that was a thing.

folcon11:08:08

Does the :keys [:user/foo] work? I thought it didn’t…

dominicm11:08:23

it used to be how you did this

rickmoynihan13:08:10

regarding destructuring I’m with @mccraigmccraig… though I’m also not averse to using :keys. Essentially I’m ok with nesting destructuring forms and the full expresivity of destructuring. Also I’m fine with it in the fn args… I’m not saying that you should deeply nest data — I prefer shallow structures where possible — but if it’s what you’re given, nesting destructuring one level down is fine. Nesting more than that I might question it… I’d also advocate where you have a nested structure lifting values higher if you can… e.g. on a ring http request you might lift the params/headers up to be top level on a context map, and then have the rest of your code work with that; and not need to know the path to the data.

madstap15:08:37

One place I worked had the :keys [:user/foo] syntax in the style guide for greppability. For one namespace I like :user/keys but if there's more than one namespace involved I think multiple :foo/keys is kinda messy so I like the :keys [user/username actions/history] syntax as I feel that symbols are more "correct" in this context than keywords.

dominicm15:08:22

I always just grep :user.*foo

madstap16:08:21

Sure, but if you know the whole codebase is gonna use the full name everywhere you don't need to do that. They also disallowed all of the :: syntax IIRC.