clojuredesign-podcast

Discussions around the Functional Design in Clojure podcast - https://clojuredesign.club/
Cora (she/her) 2019-10-15T03:27:50.012700Z

why not just use nested maps if that's how the data needs to be accessed?

Cora (she/her) 2019-10-15T03:28:43.013200Z

also I wonder if meander would be good for this use case

jumar 2019-10-15T03:30:18.014100Z

I guess that's the usual approach but Chris and Nate have been advocating namespaced maps I believe πŸ™‚

nate 2019-10-15T03:34:31.014600Z

nesting maps is definitely a common approach

nate 2019-10-15T03:35:48.015700Z

we've found that flattening maps leads to simpler code: fewer calls to get-in to dive into deeply nested data structures

nate 2019-10-15T03:36:09.016200Z

of course, nesting is still used for sub-entities

nate 2019-10-15T03:37:44.017800Z

for an example of what namespacing can do, look at Stuart Halloway's example here: https://youtu.be/Qx0-pViyIDU?t=1463

nate 2019-10-15T03:38:20.019Z

you could structure that data as nested maps, but using rich keys makes it unnecessary

Cora (she/her) 2019-10-15T03:39:05.019800Z

I just mean that if you need to access all the keys with a given prefix then that probably means you're better off nesting maps

Cora (she/her) 2019-10-15T03:39:12.020100Z

barring other constraints

nate 2019-10-15T03:39:21.020300Z

oh, I see what you mean

nate 2019-10-15T03:39:38.021100Z

yeah, unmixing data is much easier with nested maps

Cora (she/her) 2019-10-15T03:42:18.022600Z

but yeah, medley has a filter-kv that might do the trick for filtering on the key namespace. unfortunately that also means iterating over the entire map, though :(

Cora (she/her) 2019-10-15T03:50:28.023Z

oh, it has filter-keys too

nate 2019-10-15T04:01:32.024800Z

I'll have to try it out.

Stefan 2019-10-15T05:53:33.028100Z

Hi guys, I just listened to your episode #37 about, well, me basically πŸ™‚ One piece of advice I would give other beginners is to choose an IDE and stick with it for a while. Like, minimum a year or so. In this stage of your learning it really doesn’t matter which one, all of them are good enough. Just use what you’re familiar with. I find I’m constantly tempted to try other thing because of stuff I hear experts say, and before you know it your learning editors and plugins instead of Clojure,..

neumann 2019-10-15T15:32:07.049700Z

@stefan.van.den.oord I think that's great advice! Thanks! I totally relate to wandering off on "expert picks". Make progress first. Optimize later. πŸ™‚

Stefan 2019-10-15T05:56:21.030800Z

Liked the episode by the way. I also found out about Clojure Koans early on, which I liked, and this year I plan to do Advent of Code in Clojure. Regarding all the goodness in clojure.core, I’ve been wondering whether I should spend time to sit down and go through the whole thing, function by function, on clojuredocs for example. On the one hand I’m sure I would learn lots of valuable things, on the other hand I’m a bit wary of the amount of time and effort it would require πŸ™‚

lodin 2019-10-15T12:54:06.040600Z

@stefan.van.den.oord A great way is to check the cheat sheet. If you need to do eg a sequence transformation, check all the seq functions before writing it. I usually use the cheat sheet as an index anyway.

πŸ‘ 1
neumann 2019-10-15T15:37:08.050100Z

@stefan.van.den.oord I've found it useful to open the Clojure Cheat Sheet, skim through it, look for a function I haven't seen before or I don't know very well, and then read about it. Then put it down, and do that again tomorrow. Combine with a morning coffee to great effect! https://clojure.org/api/cheatsheet

neumann 2019-10-15T15:37:58.050300Z

But yes, more substantive problems like the ones on 4clojure will also introduce you to more uses.

neumann 2019-10-15T15:38:10.050500Z

Definitely read other folks answers to Advent of Code!

neumann 2019-10-15T15:39:38.050700Z

One year I read all of Mike Fikes's and Bruce Hauman's answers. I learned so much! https://github.com/mfikes/advent-of-code https://github.com/bhauman/advent-of-clojure

Stefan 2019-10-15T18:45:23.054400Z

Yeah I’m looking forward to that, thanks Christoph!

jumar 2019-10-15T06:00:17.034200Z

I think not necessarily right from the start.

Stefan 2019-10-15T06:00:42.034400Z

Agreed! But when then? πŸ™‚

jumar 2019-10-15T06:00:44.034600Z

Of course is useful to learn the most used functions - for this books like Programming Clojure + exercises like 4clojure might be useful

jumar 2019-10-15T06:01:33.034800Z

Probably similar to the "spend at least a year" advice but it really depends

jumar 2019-10-15T06:01:42.035Z

Whenever you find a strong desire to do so πŸ™‚

jumar 2019-10-15T06:02:00.035200Z

For that I'd consider https://www.manning.com/books/clojure-the-essential-reference + reading the clojure.core source code

Stefan 2019-10-15T06:02:03.035500Z

Yeah I guess that’s as good an answer as can be expected πŸ™‚

Stefan 2019-10-15T06:02:34.035700Z

Ah that seems like an interesting book!

iGEL 2019-10-15T06:23:01.040500Z

Hi. Just a small correction to the nil punning episode (sorry if mentioned before): Ruby just like Clojure only evaluates nil and false to false, everything else is truthy. Maybe you meant to say PHP at 14:00?

neumann 2019-10-15T15:34:42.049900Z

@igel Did we say that about Ruby? Good catch. We've both worked with Perl the most, and I think we might assign some of Perl's attributes to Ruby sometimes. 😁

πŸ˜„ 1
neumann 2019-10-15T15:25:57.044800Z

I missed all the fun discussion about rich keys. We'll have to talk about that on the podcast. My short opinion is that they involve a lot less ceremony than nested maps, so your code gets simpler. For example, suppose you want to sort by player/name. That's:

(sort-by :player/name players)
instead of
(sort-by #(get-in % [:player :name]) players)
or even
(sort-by #(-> % :player :name) players)

neumann 2019-10-15T15:26:55.045500Z

And then, of course, the ceremony just multiplies if you want to sort by name and then ID.

neumann 2019-10-15T15:27:50.046700Z

(sort-by (juxt #(-> % :player :name) #(-> % :player :id)) players)
vs
(sort-by (juxt :player/name :player/id) players)

neumann 2019-10-15T15:29:13.048Z

At least for what Nate and I work on, it's useful to think of a map as a bag of dimensions that can grow or shrink. We have data pipelines, so we may start with a map that just has IDs in it, but then we enrich it with other data.

neumann 2019-10-15T15:30:43.049600Z

Likewise, we may have a map with lots of rich information in it (because it's not normalized), and we'll want to pick out all the ID parts for persistence and not save the rich information that got woven in from somewhere else.

neumann 2019-10-15T15:42:12.052400Z

Suppose I want to cut down the map to just :player/name, :player/id, and :team/name. So easy with rich keys:

(select-keys player [:player/name :player/id :team/id])

neumann 2019-10-15T15:44:49.053400Z

But with nested maps. If want to preserve the same structure. Once again, more ceremony.

(let [{{team-id :id} :team
       {player-id :id, player-name :name} :player} player]
  {:team {:id team-id}
   :player {:id player-id
            :name player-name}})

neumann 2019-10-15T15:47:38.053600Z

Or maybe

{:team (select-keys (:team player) [:id])
 :player (select-keys (:player player) [:id :name])}

neumann 2019-10-15T15:47:49.053900Z

I prefer the rich keys.