Fork me on GitHub
#clojure-uk
<
2020-10-01
>
jiriknesl04:10:55

Good morning

dharrigan06:10:16

Good Morning!

dharrigan07:10:03

pinch + punch

dharrigan07:10:03

So, I've a question on style/approach...

dharrigan07:10:24

A:

(defn foo
  [{:keys [bar]} :as opts]
  ...
  ...
  use of bar somewhere
  use of opts somewhere
  ...)

B:

(defn foo
 [opts]
 (let [{:keys [bar]} opts]
    ...
    ...
    use of bar somewhere
    use of opts somewhere
    ...)

dominicm18:10:13

B by default, unless it's opts, then A

agile_geek07:10:14

@dharrigan I'm of the opinion that as long as the code is clear and readable use whatever style you want. However, I tend to favour A but it's a personal choice.

codeasone07:10:11

Morning 🌄

mccraigmccraig07:10:31

@dharrigan i don't like either of them 😬

😄 1
dharrigan07:10:29

There's always one.... 😛

agile_geek07:10:49

...and it's always @mccraigmccraig

😱 2
mccraigmccraig07:10:02

i never use :keys - i prefer to always use long-form destructuring, so that there's only a single destructuring style in the codebase

Ben Hammond07:10:29

haha I almost always use :keys it then makes you sit up and take notice if you have named a variable some thing different to its keyword

Ben Hammond07:10:57

I hate to see nested destructuring thats a personal bugbear but its so hard to read

mccraigmccraig07:10:15

i think it's one of those things you get used to, perhaps like using sexps to structure code ... i actually find :keys harder to read now

dharrigan07:10:08

Do you destructure inside the argument list or outside?

mccraigmccraig07:10:37

usually in the arg list... and i like using :as as documentation, even if the binding isn't used

👍 2
alexlynham08:10:48

yeah the :as is super useful when you're scanning code

alexlynham08:10:07

means two fns that look superficially similar can be immediately distinguished

mccraigmccraig12:10:55

there's no way to make an arbitrary java object (which i don't control) derefable in clj is there ?

Conor14:10:57

You could probably make an adapter (or whatever that design pattern is called) to give it the IDeref interface

mccraigmccraig14:10:37

yeah, i can write a fn which derefs the object (an RxJava Single)... but i can't hook it into vanilla deref... it's a shame IDeref isn't a protocol like it is on cljs

Conor14:10:29

I mean, I haven't tried it or anything so I could be way off, but can't you do something like public class DerefSingle extends Single implements IDeref, then just use those? AFAIK deref just checks if the thing you pass it is an IDeref

mccraigmccraig14:10:44

if i had control of the creation of the Singles, yeah, but i don't

mccraigmccraig14:10:05

it's no biggie... i only need it for repl noodling

mccraigmccraig14:10:52

so i can live with a special my-dereffn