Fork me on GitHub
#clojuredesign-podcast
<
2021-12-18
>
leifericf09:12:18

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?

nate16:12:44

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.

nate16:12:12

Jump to that message and look at the thread and other messages in the channel after.

nate16:12:23

I believe we also talk about namespacing keys in our Maps! Maps! Maps! episode: https://clojuredesign.club/episode/051-maps-maps-maps/

leifericf09:12:00

That’s awesome! Thanks for digging those up, @nate!

lodin12:12:16

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 .

neumann18:12:41

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.

neumann18:12:45

Eg. player, team, season, etc. You would have :player/id , :team/id, :season/id instead of :player-id, :team-id, :season-id, and such.

neumann18:12:47

And definitely not the horror of:

{:player {:id 42}, :team {:id 11}, :season {:id 99}}

neumann18:12:22

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.)

neumann18:12:26

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]))

neumann18:12:45

So that would be an expanded record of information about a player that would include more context: the team the player was on (at the time) and the related season.

neumann18:12:12

@U01PE7630AC Let me know if that's helpful!

👍 1
lodin13:12:20

@neumann Why is the nested data horrible though?