Code Fragment-删掉那些认为有用而注释掉的code。
本文思想参考自《Clean Code》
在android的源码里,有这样一段code。
// This is to replace p.setStyle(Style.STROKE); canvas.drawRect() since it // doesnt work well with hardware acceleration // private void drawEmptyRect(Canvas canvas, Rect r, int color) { // int linesIndex = 0; // mLines[linesIndex++] = r.left; // mLines[linesIndex++] = r.top; // mLines[linesIndex++] = r.right; // mLines[linesIndex++] = r.top; // // mLines[linesIndex++] = r.left; // mLines[linesIndex++] = r.bottom; // mLines[linesIndex++] = r.right; // mLines[linesIndex++] = r.bottom; // // mLines[linesIndex++] = r.left; // mLines[linesIndex++] = r.top; // mLines[linesIndex++] = r.left; // mLines[linesIndex++] = r.bottom; // // mLines[linesIndex++] = r.right; // mLines[linesIndex++] = r.top; // mLines[linesIndex++] = r.right; // mLines[linesIndex++] = r.bottom; // mPaint.setColor(color); // canvas.drawLines(mLines, 0, linesIndex, mPaint); // }
之前我也有过类似的行为,注释而不是删掉,常常有下面的原因:
- 这些code将来可能会用到。
而实际上: 而实际上:
- 这些code将来也不会用到。
- 这些code将来不能直接用,因为在注释掉的一段时间里,它本来的场景已经不合适。
- 这些code需要用到的时候,别人也不敢用,别人不知道你为什么注释掉,不清楚这些code现在有没有问题。
- 即便这些code有用,完全可以通过代码控制工具恢复。
上一篇:
IDEA上Java项目控制台中文乱码