Ep 118: Pure Parts

Ep 118: Pure Parts

Update: 2024-06-27
Share

Description

Each week, we discuss a different topic about Clojure and functional programming.


If you have a question or topic you'd like us to discuss, tweet @clojuredesign, send an email to feedback@clojuredesign.club, or join the #clojuredesign-podcast channel on the Clojurians Slack.


This week, the topic is: "parts of a pure data model". We look at pure data models we've created and see what they have in common.


Our discussion includes:



  • How we make pure data models

  • How to organize pure data models

  • What are the common parts of a pure data model?

  • What are schemas good for?

  • How is a functional pure data model different than an object-oriented class model?

  • How does a pure data model help with maintenance?

  • Semantic information verses concrete operational information.

  • What about I/O?

  • Input and output transforms for maximizing purity

  • Why save information that the program can't use?


Selected quotes


And when there's a pure data model, a pure data model is something that is both wide enough to handle an actual use case and be useful, but it's shallow enough that you can understand it and trust the function calls that it has. All of the operations on that data are in the same namespace, so it's easier to understand.


I know they're predicates because they end in a question mark.


All of the necessary changes and views are encapsulated in a namespace. That means the rest of your application can rely on its higher-level operations when working with the data model. These are a higher-level vocabulary for your application, instead of just Clojure core's vocabulary.


Everything that can be done is all co-located in a namespace.


Am I multiplying by 0.10 or 0.15? Or am I calculating a tip? One of those statements has more information.


A pure data model lets you, as a programmer, think at a higher level in the rest of your application. When you think at a higher level that's trusted, it's a lower cognitive load. You can come back to the code later, read a function, and know what it means in the context of your application.


In every pure data model, you have to know what the data looks like.


Don't underestimate the value of being able to find places where a predicate is used. It tells you what the code cares about this situation. When you have to nuance the situation, you can look at the call sites and take them all into account.


Once you've made the HTTP call, all the information about the request, the response, the body, and all that is pure data. You can do a pure transform from the domain of raw, external HTTP information into the internal domain of the pure data model.


But because it's a pure function, it's a lot easier to test. All things are easier to test when they're pure. I/O is a very, very thin layer—both on the way in and the way out.


Instead of mixing I/O and logic, do as much I/O as you can, at once, to get a big bag of pure information to work with. And then on the way out, do a pure transform to generate everything you need for the I/O, like the full requests.


You can have a big bag of extra context that's there for you as the programmer—even though the program doesn't need it.


Parts of a pure model



  • Data tree

    • Schema

    • Literals (eg. initial state)



  • Predicates

  • Data operations

  • Reducing function (state + event)

  • Transforms in

  • Transforms out

  • Views (special kind of transform)


Links


Comments 
In Channel
Ep 118: Pure Parts

Ep 118: Pure Parts

2024-06-2728:28

Ep 116: The Main Focus

Ep 116: The Main Focus

2024-05-1622:44

Ep 115: The Main Event

Ep 115: The Main Event

2024-05-0928:42

Ep 113: Highlightify!

Ep 113: Highlightify!

2024-02-2927:13

Ep 112: Purify!

Ep 112: Purify!

2024-02-2233:20

Ep 111: Loopify!

Ep 111: Loopify!

2024-02-1528:54

Ep 110: Contextify!

Ep 110: Contextify!

2024-02-0823:22

Ep 109: Extractify!

Ep 109: Extractify!

2024-02-0126:35

Ep 108: Testify!

Ep 108: Testify!

2024-01-2522:42

Ep 107: Idempotify!

Ep 107: Idempotify!

2024-01-1831:53

Ep 106: Robustify!

Ep 106: Robustify!

2024-01-1130:37

Ep 105: Codify!

Ep 105: Codify!

2024-01-0425:42

Ep 104: Assembleify!

Ep 104: Assembleify!

2023-12-2135:03

Ep 103: Explorify!

Ep 103: Explorify!

2023-12-1432:15

Ep 102: REPLify!

Ep 102: REPLify!

2023-12-0728:11

Ep 101: Sportify!

Ep 101: Sportify!

2023-11-3017:03

loading
00:00
00:00
x

0.5x

0.8x

1.0x

1.25x

1.5x

2.0x

3.0x

Sleep Timer

Off

End of Episode

5 Minutes

10 Minutes

15 Minutes

30 Minutes

45 Minutes

60 Minutes

120 Minutes

Ep 118: Pure Parts

Ep 118: Pure Parts

Christoph Neumann and Nate Jones