Today I'm going over Modern Software Engineer by Dave Farley. I've read the book once and listen to it once. Coach Tim and I have been using it as a generic metaphor to help approach complex challenge in life as well.
The book changed my approach to software testing, deployment, and design. Going through one of his free online courses, I experienced the power of TDD by solving a very simple problem. However, the pattern that emerged was better than I could have planned. The solution could be applied to the same programming problem, though with different variable.
Here is that code:
There is the seemingly over engineered approach for a very simple problem. But, look at the
main function. It is very straight forward. Here is the prompt, and even if you are a non-programmer, I bet you can understand the solution:
100 doors in a row are all initially closed. You make 100 passes by the doors. The first time through, you visit every door and toggle the door (if the door is closed, you open it; if it is open, you close it).
The second time you only visit every 2nd door (door #2, #4, #6, ...).
The third time, every 3rd door (door #3, #6, #9, ...), etc, until you only visit the 100th door.
Question: What state are the doors in after the last pass? Which are open, which are closed?
I'm not completely sold on my solution, I'm sure there are improvements. Though, it came out of small tests. And let's say the next problem asked is 1000 doors and 50 pass through? A hard coded approach would have a hard time quickly solving that problem,
These prompts used to drive me crazy in high school and college. I would never know where to start. Now, I can take small steps. If I get stuck, all that means is I need to learn or the experiment I'm trying to run is too large.
And that's the reason why this book is not only for software engineers. If you get stuck in life, what experiment are you running? Are you running any tests at all to prove or disprove your hypothesis? Are you trying to approach something that is very complex without any curiosity to learn?