James Course - The Embedded Design Principle Flashcards
What is hidden coupling?
Remember about the spice bottles labels and how they are coupled but they don’t reference each other.
A single design decision to put the herb on the bottom right couples every label together, and if we want to change this decision we have to change all labels.
Any two units that are influenced by the same design decision are coupled.
How high level code can make the code more robust?
Imagine you programmed a car to drive to the store, and programmed in set time intervals for it to go forward, turn left, accelerate, etc. It would crash pretty quickly. Now imagine you programmed it to derive those numbers itself, but still follow a set route. It may not crash, but it will get stuck as soon as there’s construction and a road is blocked. Now imagine you taught it to actually compute those routes itself — now we’re getting somewhere.
By moving to a higher level, you are taking some of your own decision-making process, and putting it in the code. By doing so, you are actually reducing the number of decisions which are made in development, and hence making the code more robust to future changes, as well as higher level.
Why it was a bad decision to change the assembly code in the chemical plant example?
Because after changing the assembly code we lose the correspondence between the high-level code and the assembly code.
This illustrates the problem that we have when we make a bunch of design decisions and don’t encode these decisions in the code. Just like the high-level code and the assembly, the design decisions and the code will get out of sync if we don’t encode our design into the code.
What do you do when you encounter a messy function?
Ask “How would I describe the intent in plain English?”
Then make your code match the description.
In the database global lock example, what was the decision that wasn’t explicit in the code? The code was coupled?
There was a design decision to use a global lock to lock actions for payments and actions for locations. This decision was not explicit in the code, but every single line that was using the global lock would have to change when this decision changed, because they were created by this decision.
The global lock existed for a reason, which was the design decision to use the same lock for two different resources, but that reason was not explicit in the code.
What is design?
You start with the specification, that is, what you want to build, and through a series of mechanical transformations, we arrive at the final program.
Every transformation is done for a specific reason. The combination of this rationale and these transformations are the design.
The embedded design principle tells us that we should strive to put this rationale into the code.
How can we try to recover the design decision that is behind a line of code?
Personal insight: We can probably keep asking why a line of code exists to increase the level of abstraction and arrive at the design decision that was used to generate that line of code.
Complete:
Every design decision should …
appear exactly once in the code.
Remember about the hidden coupling in the spice bottles.
What can we learn from the join example where a low-level design was derived from a high level?
The decision in how to derive the low-level design from the high-level design can be put into the code, just like the query optimization exists in a database and just like a routing algorithm can be coded instead of leaving a hard-coded route.