News for hackers. Stuff that matters.
Re:Write code that is easy to delete, not easy to extend (2016) by BurningFrog on Wednesday July 22, 2020 @10:09AM (#23917146)
Yeah, the idea of DRY is simple, but it doesn't change the fact that you have to use your judgement, do and learn from mistakes etc. Nothing ever does.

I'd tweak your code example to this:

     def drawHighlightingRectangle(someDecidingFactor1, someDecidingFactor2, x0, y0, x1, y1):
         def highlight_color(factor1, factor2):
             if factor1 == something && factor2 != somethingElse:
                 return "red"
             else:
                 return "blue"

         color = highlight_color(someDecidingFactor1, someDecidingFactor2)
         drawRectangle(color, x0, y0, x1, y1)
This doesn't Repeat the drawRectangle() call.

There are no comments on this comment yet.