Don’t Just Code DRY — Think DRY!
Important note: If you haven’t read the previous post, please do so now—and don’t come back to this one until you’ve given the brain teaser at least an hour to rewire your brain!
RECAP:
In that post, I asked you to count the pairs of different fingers on one hand. Hopefully, you arrived at 10 pairs. Then, I challenged you to determine the number of triples of different fingers, without counting.
HERE'S THE SOLUTION:
Imagine counting pairs of fingers by folding two fingers at a time. Each time we fold two fingers, three fingers remain unfolded. This means that counting a pair of fingers by folding them is equivalent to counting a triple of fingers by folding the remaining two! So, WITHOUT COUNTING, we immediately know that the number of triples is the same as the number of pairs—10.
WHY DOES THIS MATTER FOR PROGRAMMING?
What we just did is an example of reducing one problem to another — and that's how programmers think! This is exactly the DRY (Don't Repeat Yourself) mindset. Instead of reinventing the wheel, programmers define a minimal set of functions and then express every needed computation in terms of those functions.
And if you want to take it a level higher, great programmers design functions that create an application-specific language, allowing them to think and code within it.
ENJOYED THIS? 🚀
Give this post a like so more people can discover it, follow, and stay tuned for more!
0
0 comments
Meir Goldenberg
2
Don’t Just Code DRY — Think DRY!
University of Code
skool.com/universityofcode
You'll get Exclusive Lessons & Content, Badass Community Support & More here to elevate as a Dev!
Leaderboard (30-day)
Powered by