Out of the Tar Pit (2006) [pdf]
My impression from reading this has always been &quot;Almost there! Keep going.&quot; If you keep pulling on these threads, I claim that you reach some inevitable conclusions. These ideas are a superset of all the other advice they give (and most other advice you hear, too):<p>1. Separate identity from data. These are <i>completely different things</i>. The number 7 is not mutable, even though my age is. Keep going! The phrase &quot;It was a dark and stormy night&quot; is not mutable, even though the opening line of your book is. Keep going! The statement &quot;there are seventeen cars parked on level 3 and four spots available&quot; is <i>not mutable</i>, even though the status of the parking garage is. Identity is immutable, and statements (data) are also immutable. Only the assignment of a statement to an identity is mutable.<p>2. Think about the operations that make sense on your data. Sure, you have &quot;map&quot;, &quot;filter&quot;, &quot;reduce&quot; that are mathematically pure. What about &quot;offset&quot; or &quot;rotate&quot;? Those have identity, they are associative, individually commutative (but not with each other!). Is there a distributive property that applies there? Okay, what about &quot;buy&quot; and &quot;sell&quot; operating on commodities? Are those mathematical operations? Do they have an identity element? Are they associative and commutative? &quot;Buy 2000 lbs of chicken&quot; -- is that equivalent to &quot;Buy 1 ton of chicken&quot;? What are its domain and range? Not &quot;chicken&quot;, nor even &quot;warehouses&quot; -- you&#x27;re not teleporting the chicken as soon as you commit that record. More like &quot;contract&quot;, or even &quot;contract request&quot;. What can you do with contracts? Is there an &quot;identity contract&quot;? &quot;Buy 0 chicken&quot;? Zero is a useful number! Is &quot;Buy 0 chicken&quot; the same as &quot;Buy 0 beef&quot;? Explore these questions. Find the math around your domain. Functional purity is all good, but it&#x27;s wasted if your domain is just &quot;Chicken : Meat : Commodity&quot;, &quot;Beef : Meat : Commodity&quot;, &quot;Pine : Lumber : Commodity&quot;. Wrong. Don&#x27;t think about nouns. Think about sensible pure operations in your domain. Successive abstraction layers should be <i>restricting</i> what&#x27;s possible to do with your data, by defining higher and higher-level operations. If your abstraction layers aren&#x27;t restricting what&#x27;s possible to do, they&#x27;re an inner platform and you don&#x27;t need them.<p>3. Don&#x27;t make big decisions upfront. That&#x27;s how you add accidental complexity. Don&#x27;t make any decisions you don&#x27;t need to, and prefer solutions that allow you to defer or lighten decisions. If you follow this thread, that means you&#x27;re using a relational model. They absolutely got that right (section 8). Otherwise you&#x27;re making decisions about ownership that you don&#x27;t need to be making. Domain Driven Design has it <i>wrong</i> here with aggregate roots. What&#x27;s an aggregate? Which concept goes inside of which aggregate? You do not need to make that decision. The authors of TFA get it right, and then wrong again, when they try to apply a relational model to shitty noun-based domain ideas like &quot;Give Employee objects a reference to their Department, vs. Give Department objects a set (or array) of references to their Employees vs. Both of the above&quot;. No. They&#x27;re not following their own advice. Can an employee exist without the concept of &quot;department&quot;? Yes. Can a department exist without the concept of employees? Probably. Therefore you <i>must</i> encode the relationship separately from both. Your hands are tied. If concept A can exist independently of concept B, you <i>must not</i> draw an arrow from A to B. The answer is not &quot;both&quot;, it&#x27;s &quot;neither&quot;. An employee&#x27;s assignment within a department is its own independent concept, that knows about &quot;employee&quot; and &quot;department&quot; both. And now it&#x27;s obvious you can give this concept its own tenure and add a new record whenever they change departments. You&#x27;ve found append-only event sourcing without needing to start there -- it came from first principles (in this case).<p>4. Operate on the broadest scope you can. Manipulate sets of things, not individual things. This is half of functional programming&#x27;s usefulness right here. This is supported by using a relational model. Operate on sequences of things, not individual things: there&#x27;s reactive programming. How else can you broaden the scope of what you&#x27;re operating on?<p>5. Don&#x27;t just do something, stand there! That is: don&#x27;t <i>do</i>, <i>plan</i>. Instead of immediately looping, just use &quot;map&quot;. Instead of immediately hitting the database, write a query plan. This doesn&#x27;t mean offload your thinking to GraphQL -- that&#x27;s just kicking the can down the road. See point #2. This is the other half of functional programming&#x27;s usefulness. Do only as much as you need to make (or append to) a plan, and then stop. Someone else will execute it later -- maybe! You don&#x27;t care.<p>There&#x27;s probably more, but there are more fundamental ideas than &quot;use functional programming&quot; or &quot;use event sourcing&quot; or &quot;use SOLID&quot; -- first principles that actually lead to almost all the other good advice you get. This paper kinda almost gets there a couple times, then walks back again. Keep going. Keep pulling on those threads. I suspect that the more you do this, the more your code will change for the better. But you have to be willing to keep going -- don&#x27;t half-ass it. If you only go part way and then stop, the benefits won&#x27;t be apparent yet.