clojure-uk

A place for people in the UK, near the UK, visiting the UK, planning to visit the UK or just vaguely interested to randomly chat about things (often vi and emacs, occasionally clojure). More general the #ldnclj
jiriknesl 2020-10-01T04:10:55.077500Z

Good morning

mccraigmccraig 2020-10-01T06:21:34.077700Z

mån

dharrigan 2020-10-01T06:32:16.077900Z

Good Morning!

dharrigan 2020-10-01T07:25:03.078200Z

pinch + punch

dharrigan 2020-10-01T07:33:03.078700Z

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

dharrigan 2020-10-01T07:33:24.078900Z

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
    ...)

dharrigan 2020-10-01T07:34:05.079200Z

A or B?

agile_geek 2020-10-01T07:43:14.080700Z

@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.

codeasone 2020-10-01T07:46:11.081100Z

Morning 🌄

mccraigmccraig 2020-10-01T07:46:31.081400Z

@dharrigan i don't like either of them 😬

😄 1
dharrigan 2020-10-01T07:47:29.082100Z

There's always one.... 😛

agile_geek 2020-10-01T07:47:49.082700Z

...and it's always @mccraigmccraig

😱 2
mccraigmccraig 2020-10-01T07:48:02.082900Z

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

2020-10-01T07:49:29.083700Z

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

2020-10-01T07:49:57.084300Z

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

mccraigmccraig 2020-10-01T07:52:15.086500Z

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

dharrigan 2020-10-01T07:54:08.087300Z

Do you destructure inside the argument list or outside?

mccraigmccraig 2020-10-01T07:56:37.088200Z

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

👍 2
alexlynham 2020-10-01T08:11:48.088300Z

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

alexlynham 2020-10-01T08:12:07.088400Z

means two fns that look superficially similar can be immediately distinguished

alexlynham 2020-10-01T08:12:12.088500Z

also

alexlynham 2020-10-01T08:12:13.088600Z

morning

thomas 2020-10-01T08:42:20.088900Z

mogge

mccraigmccraig 2020-10-01T12:23:55.090600Z

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

Conor 2020-10-01T14:09:57.090700Z

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

mccraigmccraig 2020-10-01T14:19:37.092800Z

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

Conor 2020-10-01T14:50:29.092900Z

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

mccraigmccraig 2020-10-01T14:54:44.093300Z

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

mccraigmccraig 2020-10-01T14:55:05.093700Z

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

mccraigmccraig 2020-10-01T14:55:52.094200Z

so i can live with a special my-dereffn

dominicm 2020-10-01T18:01:13.094300Z

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