This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-21
Channels
- # announcements (1)
- # beginners (20)
- # biff (5)
- # calva (43)
- # cider (5)
- # clj-commons (7)
- # clj-kondo (11)
- # clojure (58)
- # clojure-brasil (1)
- # clojure-denmark (1)
- # clojure-europe (27)
- # clojure-nl (1)
- # clojure-norway (13)
- # clojure-uk (2)
- # clojurescript (71)
- # data-science (32)
- # datalevin (6)
- # datomic (19)
- # emacs (1)
- # gratitude (3)
- # honeysql (8)
- # hoplon (15)
- # hyperfiddle (3)
- # introduce-yourself (1)
- # lsp (19)
- # malli (4)
- # nbb (7)
- # other-lisps (5)
- # practicalli (1)
- # re-frame (14)
- # releases (1)
- # ring-swagger (1)
- # squint (118)
- # xtdb (9)
- # yada (2)
Everytime I data model in datomic, there is a conflict on whether to use generic attributes or specific attributes. I've gone through the documentation multiple times but there is no advice on this. Are there any guiding principles that you use that you've developed from experience?
Say, for example, there are posts and I want to add the ability to vote (upvote and downvote) for it. Should I have a generic entity like this:
{:vote/type :vote.type/up
:vote/parent [:post/id "some-post-id"]
:vote/created-by [:user/id "some-user-id"]}
or a specific entity like this?
{:post.vote/type :post.vote.type/up
:post.vote/parent [:post/id "some-post-id"]
:post.vote/created-by [:user/id "some-user-id"]}
My actual scenario now is that I have a slider that allows choosing a number from 1-10 and it's associated to only one kind of entity atm, call it an issue entity. Should I use generic attrs that allow building a generic number voting entity, say like vote/score
or should I have a specific issue.severity.vote/score
attr?
I think specific should always be the default in everything. Generality comes later and must be carefully planned
The number of times I’ve been burned by premature abstraction for a feature that never gets built. Don’t design yourself into a corner, but also don’t assume you know exactly what general abstraction will eventually be the one you need
So if you know for sure you’re going to have a general voting system and know what’s the same and what’s different, go ahead and design that system. Otherwise default to solving the problem in front of you and figure out the generality later
that being said, if you have an attribute that has global semantics no matter what entity it's on, by all means make it a general attribute
You can always use other abstractions (such as rules) to make specific things conform to a more general interface you make later
+1 to ghadi’s point. Some systems are designed for their generality and you should establish those on day one of your db. Things like: how will I “type” entities, how will I determine existence and non-existence, what tx metadata will I use, how will I handle order and repositioning, etc
But these are more data-model concerns I think, and are pretty closely tied to the specific db tech you are using, and are driven by the strengths and constraints of your db. But for the domain model, default to specificity, because the generality is harder to know until you do literally have two of them
Thanks @U050ECB92 and @U09R86PA4. I default to specificity very much when it comes to code and then wait for patterns to emerge to create an abstraction but that’s in code. Just wanted to know if the same applies to datomic too from the experienced (since I’m new to datomic). There is this feeling I gather from datomic documentation that the schema should be carefully planned and planned for accretion which often puts me under pressure to design carefully. I’ll stick to specificity when in times of doubt then.
you're absolutely correct that schema has more pressure to design carefully.... good luck!