Good morning
mån
Good Morning!
pinch + punch
So, I've a question on style/approach...
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
...)
A or B?
@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.
Morning 🌄
@dharrigan i don't like either of them 😬
There's always one.... 😛
...and it's always @mccraigmccraig
i never use :keys
- i prefer to always use long-form destructuring, so that there's only a single destructuring style in the codebase
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
I hate to see nested destructuring thats a personal bugbear but its so hard to read
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
Do you destructure inside the argument list or outside?
usually in the arg list... and i like using :as
as documentation, even if the binding isn't used
yeah the :as
is super useful when you're scanning code
means two fns that look superficially similar can be immediately distinguished
also
morning
mogge
there's no way to make an arbitrary java object (which i don't control) deref
able in clj is there ?
You could probably make an adapter (or whatever that design pattern is called) to give it the IDeref interface
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
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
if i had control of the creation of the Singles, yeah, but i don't
it's no biggie... i only need it for repl noodling
so i can live with a special my-deref
fn
B by default, unless it's opts, then A