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

本文思想参考自《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有用,完全可以通过代码控制工具恢复。
所以:对于一些代码直接删掉,而不是注释掉!





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值