This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-04-25
Channels
- # announcements (3)
- # aws (6)
- # beginners (143)
- # boot (14)
- # calva (2)
- # cider (1)
- # clara (1)
- # clj-kondo (1)
- # cljdoc (4)
- # cljs-dev (50)
- # cljsrn (5)
- # clojure (61)
- # clojure-chicago (1)
- # clojure-europe (4)
- # clojure-italy (5)
- # clojure-nl (5)
- # clojure-spec (32)
- # clojure-uk (11)
- # clojurescript (166)
- # clojureverse-ops (2)
- # clr (3)
- # core-typed (1)
- # cursive (8)
- # datomic (21)
- # defnpodcast (1)
- # emacs (1)
- # figwheel (1)
- # figwheel-main (1)
- # fulcro (7)
- # graphql (7)
- # jobs (8)
- # leiningen (4)
- # luminus (3)
- # lumo (17)
- # mount (3)
- # nrepl (4)
- # off-topic (113)
- # pedestal (1)
- # re-frame (15)
- # reagent (2)
- # reitit (2)
- # shadow-cljs (75)
- # spacemacs (3)
- # sql (12)
- # tools-deps (44)
- # uncomplicate (2)
- # xtdb (15)
now that usage of spec is pervasive and given the fact that defrecord produces handy functions
where MyRecord?
is a predicate returning true if its argument is an instance of the backing MyRecord
class and/or it has the required record fields with values that match some field specs?
I think there’s value in spec’ing fields of records (just as there is in spec’ing plain-old maps). as for protocols there are some technical reasons they aren’t supported. the workaround that was thrown around in the past is having protocol method implementations call a spec’d function
re: records. it sounds like most people don’t use them (?) and stick with maps and occasionally add some :tag
or :type
entry to achieve the ability to determine the “kind” of map
not sure if records were too JVM-centric or if they feel too restrictive to the free-spirited majority opposed to types
also in Clojure Applied it is recommended for “domain” objects, although I rarely see them used
yeah, you get fast single dispatch (like a Java class, since they’re implemented as Java classes)
fwiw, I would probably de-emphasize records in a 2nd ed of Clojure Applied
@alexmiller so fewer records but protocols still emphasized, correct?
seems like there’s plenty of boiler plate that packaging things as records could manage for you
defrecord-spec
where each field has an associated spec. spec’d record creation functions, reference the field specs elsewhere when performing a subset select with select
the only place I see them being awkward is when you’re building up the fields for a record. which I believe is an example Rich referenced in Maybe Not or another recent-ish talk
but, it’s not that bad to just use maps with a sub-select spec until you’ve gathered all the required fields and then throw it into a record
feels like serialization is motivating much of this. e.g., you may have some fields that are handy but can be computed from other fields in the map. so when you serialize maps for storage in a database, you drop those derived fields. but then results from the database are “incomplete” and processing is required to generate the derived fields before you could construct the record