I know for the vets this has been discussed to death, but for the newer people I wanted to share. I set out yesterday to replace an if statement based on a boolean flag; I was convinced there was a better way.. And there was, but it took some mind twisting to get there. I learned a lot of really really important programing Philosophy that I'd sort of been foggy on previously. Granted it might have been overkill but I wanted understand the concept so I was ok with the simplistic usage.
The last code block in this first post gives a really great example of a very simplistic implementation of the idea. More importantly, I watched the Google Clean Code talk video (which is linked in the post right above the code I am referencing) and that really blew my mind. I had to watch it several times understand the specifics. Definitely worth the effort though.
Hope this is helpful to people.
"The greatest of all weaknesses is the fear of appearing weak." - JB Bossuet
just a tip...you say "the last code block in this post". the problem I see is that people can continually add new answers to that page, thus putting in new code blocks at the end, and depending on how people vote, entire sections can be moved around.
Can you be more specific which block of code you are referring to?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors