Re:IF-less programming
by raverbashing on Friday December 28, 2012 @02:14PM
(#4979026)
Yes, there are situations where changing the structure of the code is better than having an 'if' like the example you gave.
But this doesn't mean that it's better to completely eliminate ifs
For example I recently did some work on a graphics library which had a lot of ifs to do with line and fill styles. By changing those into an inheritance hierarchy I found a couple of places where clauses had been missed and so fixed some bugs, but more importantly when we needed to add new fill styles which were more complicated to draw it became very easy to turn the fill style objects into fillers which had all the responsibility for filling paths, not simply setting the graphics state.