Fork me on GitHub
#clojure-spec
<
2017-06-25
>
jjttjj16:06:18

I know spec is maybe too new for idioms to develop but is there a clear answer to having :x.specs.user/email, :x.specs.user/password and then :x.specs.user/user for the whole user entity or is :x.specs/user a better name for the "entity", what's everyone's preferences here?

jjttjj19:06:59

(ns x.specs.user
  (:require [clojure.spec.alpha :as s]))

(s/def ::username string?)
(s/def ::password string?)

(s/def ::user ;;or is :x.specs/user better?
  (s/keys :req [::username ::password]))

jjttjj20:06:27

I'm personally convinced x.specs/user is clearly better than ::user which expands to :x.specs.user/user, just trying to get a second opinion before imposing my will on others.

luchini20:06:58

We have been doing something similar to :x.specs.user/user in your example. It seemed like a natural choice at first and it quickly became a shared language across the team.

luchini20:06:19

Same pattern you suggested: always the last s/def of the file and one ns per entity.

luchini20:06:32

I’m also not sure if this will evolve into an idiom but surely has made the communication in our team much easier.

jjttjj20:06:36

thanks for the input!

luchini20:06:50

There’s an interesting side-effect that’s been great for the specifics of our project. We receive entity names from a remote system in a simple string. We can then convert the string into :x.specs.<string>/<string> and boom: we have our spec 🙂

jjttjj20:06:31

@lucascs awesome yeah that's basically what I'm going for with the overall project set up but is there a reason you go with :x.specs.<string>/<string> instead of :x.specs/<string> for the composite entity at the end of the file? Because what you're saying could be done with either of those options just as easily right? (Sorry to painfully over analyze small details here)

luchini20:06:31

Indeed it could. In practice the reasoning behind our choice was purely aesthetics. Kind of “everything related to the user entity is namespaced with :x.specs.user.” Otherwise we would need to always have the entity itself as a bit of an exception (defining it with :x.specs/user instead of autoexpanding with ::user).

luchini20:06:37

Pretty much a personal taste thing

luchini20:06:05

From a communication perspective, it’s one less cognitive level.

jjttjj20:06:25

cool thanks again 🙂