This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-10-01
Channels
- # announcements (8)
- # aws (8)
- # babashka (21)
- # beginners (125)
- # calva (12)
- # cider (10)
- # circleci (29)
- # clara (6)
- # clj-kondo (34)
- # cljdoc (3)
- # cljfx (65)
- # cljs-dev (18)
- # clojure (38)
- # clojure-australia (4)
- # clojure-berlin (5)
- # clojure-czech (2)
- # clojure-dev (15)
- # clojure-europe (22)
- # clojure-nl (3)
- # clojure-uk (31)
- # clojuredesign-podcast (7)
- # clojurescript (87)
- # code-reviews (1)
- # conjure (3)
- # cursive (2)
- # data-science (1)
- # datalog (1)
- # datomic (36)
- # emacs (12)
- # events (1)
- # fulcro (3)
- # graalvm (68)
- # instaparse (2)
- # jackdaw (2)
- # jobs (2)
- # leiningen (8)
- # luminus (2)
- # nrepl (31)
- # pedestal (44)
- # releases (1)
- # remote-jobs (6)
- # shadow-cljs (4)
- # spacemacs (4)
- # sql (13)
- # tools-deps (56)
- # uncomplicate (4)
- # xtdb (40)
- # yada (11)
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 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.
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
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
morning
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