您的位置:首页 > 其它

Code Fragment-删掉那些认为有用而注释掉的code。

2013-08-28 23:50 162 查看
本文思想参考自《Clean Code》

在android的源码里,有这样一段code。

// This is to replace p.setStyle(Style.STROKE); canvas.drawRect() since it
    // doesn't 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常常没有用,但是非作者一般不会去删掉,这就会使注释掉的code越来越不适用。
即便这些code有用,完全可以通过代码控制工具恢复。

所以:对于一些代码直接删掉,而不是注释掉!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: