This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-18
Channels
- # adventofcode (20)
- # aleph (25)
- # announcements (4)
- # babashka (117)
- # beginners (150)
- # calva (4)
- # cider (9)
- # clj-on-windows (2)
- # clojure (9)
- # clojure-europe (4)
- # clojure-italy (3)
- # clojuredesign-podcast (18)
- # clojurescript (16)
- # conjure (1)
- # core-async (35)
- # cursive (13)
- # datalevin (6)
- # datomic (6)
- # fulcro (8)
- # hyperfiddle (5)
- # malli (8)
- # nextjournal (4)
- # off-topic (51)
- # pathom (4)
- # reagent (21)
- # sci (14)
- # shadow-cljs (22)
- # specter (3)
- # testing (22)
- # tools-deps (8)
- # xtdb (7)
In episode 22, @nate and @neumann talk about using “flat data structures” and “namespaces keys,” instead of nested data structures. That concept is a bit unclear to me. Does anyone know of a paper or blog post which goes more in depth on this topic, with some code examples?
Hey @U01PE7630AC, I don't have any blog post links handy, but I do know we've discussed it a bit in this channel. Now that we have the full history searchable I was able to find some links to those discussions.
Here is Christoph with an example: https://clojurians.slack.com/archives/CKKPVDX53/p1571075516008300
Here's a mention of a Stuart Halloway talk: https://clojurians.slack.com/archives/CKKPVDX53/p1571110664017800
I believe we also talk about namespacing keys in our Maps! Maps! Maps! episode: https://clojuredesign.club/episode/051-maps-maps-maps/
I find that there is a lot of nuance to consider with regards to qualified keywords. In particular, context is very important. He touches upon that at https://youtu.be/IS3i3DTUnAI?t=1741 .
For what it's worth, I've been using namespaced keys for over 3 years now and I still fine them useful in a number of situations. In particular, when I have to mix a number of fields together that come from other sources.
Eg. player, team, season, etc. You would have :player/id
, :team/id
, :season/id
instead of :player-id
, :team-id
, :season-id
, and such.
And definitely not the horror of:
{:player {:id 42}, :team {:id 11}, :season {:id 99}}
In general, the situation where I find them the most useful is when the map is a "bag" of fields from different entities that are all combined together for convenience or correlation (data that has be joined.)
You can do nifty stuff like this:
(merge
(select-keys player [:player/id :player/name])
(select-keys team [:team/id :team/name])
(select-keys season [:season/id :season/year :season/phase]))