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

来源:互联网 发布:数据库的设计步骤 编辑:程序博客网 时间:2024/06/05 01:19

本文思想参考自《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);//    }

之前我也有过类似的行为,注释而不是删掉,常常有下面的原因:

  1. 这些code将来可能会用到。
而实际上:
  1. 这些code将来也不会用到。
  2. 这些code将来不能直接用,因为在注释掉的一段时间里,它本来的场景已经不合适。
  3. 这些code需要用到的时候,别人也不敢用,别人不知道你为什么注释掉,不清楚这些code现在有没有问题。
  4. 这些code常常没有用,但是非作者一般不会去删掉,这就会使注释掉的code越来越不适用。
  5. 即便这些code有用,完全可以通过代码控制工具恢复。
所以:对于一些代码直接删掉,而不是注释掉!





原创粉丝点击