3 ms·
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 twe
by BurningFrog 6y ago
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.