This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-09
Channels
- # 100-days-of-code (6)
- # announcements (4)
- # atlanta-clojurians (1)
- # aws (1)
- # beginners (65)
- # boot (21)
- # cider (9)
- # cljsrn (3)
- # clojure (186)
- # clojure-android (4)
- # clojure-conj (1)
- # clojure-dev (12)
- # clojure-germany (3)
- # clojure-italy (8)
- # clojure-nl (1)
- # clojure-russia (32)
- # clojure-spec (19)
- # clojure-uk (41)
- # clojurescript (83)
- # core-async (5)
- # cursive (18)
- # datomic (15)
- # emacs (5)
- # events (4)
- # fulcro (7)
- # hyperfiddle (4)
- # leiningen (4)
- # liberator (1)
- # off-topic (65)
- # overtone (4)
- # pedestal (5)
- # perun (1)
- # planck (3)
- # re-frame (1)
- # reagent (3)
- # rum (5)
- # shadow-cljs (8)
- # spacemacs (19)
- # testing (3)
- # tools-deps (4)
- # yada (6)
Here's an example of a practical question. Should I do (a) or (b)?
;; A:
(ns testing.spec
(:require [testing.id :as id]))
(s/def ::id ::id/id)
(s/def ::data-structure (s/keys :req [::id]))
;; B:
(ns testing.spec
(:require [testing.id :as id]))
(s/def ::data-structure (s/keys :req [::id/id]))
You should do whichever one matches your data
::
is a spec for an UUID in a certain form, this gets used all over the place. Question is, do I alias it locally using ::id
? In other words, who "owns" the ::id
definition?
And Alex's Zen Master answer is actually spot on. My current thinking is that I should use local ::id
, since this is really a property of the data that I'm defining locally, and only coincidentally an UUID whose properties are defined elsewhere.
I think about it as two levels - it’s useful to have specs that capture common type/shapes/formats domain things - phone numbers, invoice numbers, etc. then there are entities that collect attributes and those may have their own names. Like you have a :foo.domain/phone and then you have :foo.company/phone
(and the latter would just be an alias for the former)
that adds weight (and there are some bugs around overriding generators for aliased specs) so it may or may not be worth it
phone number is probably something with extra constraints, but if you have something adequately represented as int?
then I would not pull it out as a domain type as that doesn’t seem worth it
some day we’ll consider doing a 2nd edition of Clojure Applied and think about some of this stuff :)
based on my time availability, I don’t think it’s happening anytime soon
A book would be very welcome. I would really like to learn about how people approach modeling data, preferably from people who actually build real systems. Spec seems very flexible, but I found that if you deviate from a certain path, you'll be swimming against the current (for example, if you insist on using unqualified keys).
BTW, I solved my coercion problems for the time being by judiciously removing every s/conform
from my code and writing a tiny piece of code that maintains registries of coercions (multiple registries, as it turns out: one for converting to the domain model, and one for converting to db form). This seems to work very well and apart from limitations of unqualified keys in specs solves the problem for me.