An idea from the book "101 Things I learned in Engineering School".
Electrical systems are protected by fuses or circuit breakers that trip before a power surge can ruin expensive components or damage hard-to-access wires.
In steel buildings, connections between structural members can be designed to deform during earthquakes, to prevent catastrophic failure of the larger system. Repair of the connections can be done at a fraction fo the cost of replacing the entire building.
Biomedical devices are often connected loosely to protect a patient. A pulse oximeter, used to detect blood oxygenation, is connected to a patient's finger with deliberate weakness, preventing injury should someone trip over the cable.
The clips that hold lobster traps together are designed to corrode after one fishing season. When traps are lost or abandoned, the clips will fail before the wire-gridded sides, leaving the pieces that are much less hazardous to boats than a pile of submerged boxes.
In my head I'm thinking, were these only discovered after the failures happened?
And engineers were working backwards from the problem, and figuring out a solution?
And through trial-and-error, realize that a circuit breaker was needed?
Or did they have enough knowledge about the system beforehand and discovered a failsafe was required?
In coding, writing tests is a similar philosophy. You write code where you expect failures to happen, and that increases it's reliability.
This concept can be applied to our lives.
If we can plan our lives while expecting that failure is a possibility, we can avoid expensive mistakes.
If we set high expectations for ourselves, without accounting for failure, without deliberate weakness in the design, it will cause mental injuries.
But what's the definition of failure?
Is failures = not meeting expectations?
Is the key to not setting expectations in the first place?
Are expectations just disappointments waiting to happen?
Design your life to fail.
So when failure comes, you're ready to face it.