Be less curious about people and more curious about ideas.Marie Curie
Today I was reading about DIP, which made me think a lot about how I write software.
Let start by defining what Dependency Inversion Principle. Uncle Bob, in his book Clean Architecture, says:
The Dependency Inversion Principle (DIP) tells us that the most flexible systems are those in which source code dependencies refer only to abstractions, not concretions.
Let’s picture this with a code example:
This is a simple function that accepts two parameters, but based on the DIP principle, there’s a problem with this simple function. Can you see it? It takes WC_Gateway_GreenPay, which is the class of a unique payment gateway; what if the site changes the payment gateway to Cash On Delivery, then we’ll need to update our function to:
Now imagine you have many examples likes these that force you to update your code; this is not very flexible; instead, let’s follow the DIP principle and make it adjustable by depending on the abstract class WC_Payment_Gateway:
If the site switches to another payment method or implements multiple, we won’t have to worry about our code not being compatible.
The DIP principle helps us avoid bugs and spend time fixing them in the future, makes our code flexible and without sacrificing anything.
You can’t become happy. You can only BE happySam Harris
sing examples from vacations to colonoscopies, Nobel laureate and founder of behavioral economics Daniel Kahneman reveals how our “experiencing selves” and our “remembering selves” perceive happiness differently
investing is simple: Diversify, buy and hold, keep costs low.
- There’s a real demand for overconfidence
- … TBC
This is a great documentary about the 1987 crash.