Fork me on GitHub
#clojure-europe
<
2024-07-03
>
Mario Trost05:07:21

Good morning!

schmalz07:07:07

Morning all.

maleghast07:07:37

madainn mhath :flag-scotland:

teodorlu08:07:07

Morning 🙂

teodorlu08:07:28

You know entities from good old domain driven design? I’m kind of torn thinking of how to do entity design in Clojure. I see two options: 1. Make a namespace for entities that just works on that entity data. Then use that namespace from other parts of the code. Keep that entity namespace free from effects, functions from data to data only. 2. Just work on data in your functions. I feel like this is the “better but harder” approach, with a good entity model, it’s just data. We don’t use a “ring entity namespace” to work on ring requests and ring responses, we mostly just query / set :headers directly. The problem I’m trying to fix / avoid is to end up with a bag of functions that all take maps, and it’s not really clear which keys go in which option maps in which functions. Perhaps a third option is to design entities with namespace qualified keys, and not require people to import any namespaces to work on maps with those keys :thinking_face:

magnars09:07:58

Work with just maps, using namespaces keys.

👍 2
1
teodorlu09:07:16

Do you feel the need to “put” the entity model somewhere? Or just write unit tests as usual?

magnars09:07:51

I think the closest to the modelling you are looking for is in my Datomic schema file.

👍 1
magnars10:07:25

But no, I don't have a list of valid keys anywhere. Some people use spec or Malli for that.

👍 1
Ludger Solbach10:07:49

you may take a look at the structure of the https://github.com/soulspace-org/overarch code. I do have a domain folder with model and element namespaces. The entities themselves are just plain maps but there are a lot of domain specific functions, e.g. processors or navigation. I seperate these from the services and the outside world with a clean architecture. So far I'm pretty happy with the structure, even if it's not perfect I know where to look.

Ludger Solbach10:07:51

this is the overall structure of the namespaces (some recent additions missing 😕). each blue box represents a namespace.

teodorlu10:07:43

Interesting, thanks! Of course overarch itself is documented with overarch 😄

Ludger Solbach10:07:24

eat your own dog food. 😄

😸 1
plexus11:07:42

A bit late to the party here but this is relevant to my interests. I'm generally in @U07FCNURX camp, just use namespaced maps and access them directly where you need them. But I've been on multiple projects where people on the team "feel" they "need" some kind of schema definition because otherwise it's anarchy. The question is what you do with that. In a statically typed language your compiler will tell you immediately if you fat fingered a property name. Most approaches I've seen give you some limited guardrails at runtime, meaning issues often only show up when they hit production, and it mostly checks the write path, even though issues on read are more common IMO. So now it's this extra thing you need to maintain and which itself can be wrong or out of date, so now you're getting schema errors on code that would've been fine without the schema checks...

👍 1
teodorlu12:07:54

> But I’ve been on multiple projects where people on the team “feel” they “need” some kind of schema definition because otherwise it’s anarchy. […], meaning issues often only show up when they hit production, and it mostly checks the write path, even though issues on read are more common IMO. So now it’s this extra thing you need to maintain and which itself can be wrong or out of date, so now you’re getting schema errors on code that would’ve been fine without the schema checks... I generally have the impression that things are put into Clojure because they are needed, and I appreciate that aspect a lot. I feel like that criticism can be pointed to “excessive use of schema definitions”: do you actually know why you need a schema for this now? Will introducing a schema actually help you solve that problem? :thinking_face: If an example is needed, perhaps a comment or a test solves that problem as well as a schema definition (assuming you don’t use the schema for validation in production).

#_ (greeting {:person/name "Magnar"})
> people on the team “feel” they “need” some kind of schema definition because otherwise it’s anarchy I guess I’ve felt this, which is why I’m asking. I feel like separating “how do I get better at designing entity models with namespaced keywords” is a better problem formulation than “how do I nail down what namespaced keywords are with schemas” (which isn’t really a problem).

dharrigan08:07:58

Good Morning!

ray08:07:51

Good morning

😍 3
reefersleep11:07:38

Good morning 🙂

reefersleep11:07:46

Summertime = quiet time at the office. Lovely

❤️ 2
otfrom16:07:56

such busy ness. morning