您将如何以您选择的语言在此示例中获得梦寐以求的 DRY 理想:
drawLine(Point(0, 0), Point(w, 0));
int curRowY = 0;
for(int row=0; row<rowHeights.size(); row++) {
curRowY += rowHeights[row];
drawLine(Point(0, curRowY), Point(w, curRowY));
}
drawLine(Point(0, 0), Point(0, h));
int curColX = 0;
for(int col=0; col<colWidths.size(); col++) {
curColX += colWidths[col];
drawLine(Point(curColX, 0), Point(curColX, h));
}
注意:大量的 ad-hoc 预处理器宏的可读性和可写性可能极低,因此已淘汰。