• 请不要在回答技术问题时复制粘贴 AI 生成的内容
LinkT
V2EX  ›  程序员

写注释也要解放

  •  
  •   LinkT · Feb 26, 2023 · 5502 views
    This topic created in 1360 days ago, the information mentioned may be changed or developed.

    不知道诸位公司有没有这样的要求,所有的代码改动都需要加注释。 比如这样:

    diff --git a/test.java b/test.java
    index 70fd330..941c28d 100644
    --- a/test.java
    +++ b/test.java
    @@ -1,5 +1,7 @@
     public class HelloWorld {
         public static void main(String[] args) {
    -        System.out.println("World, Hello!");
    +        //zhangsan modify this for xxxx. 2023-02-26 start
    +        System.out.println("Hello, World!");
    +        //zhangsan modify this for xxxx. 2023-02-26 end
         }
     }
    

    一般这种注释都是最终代码验证 ok 上传时才加。 如果代码的修改分散在很多不同的位置,那么加这个注释就很痛苦。

    作为懒人,实在不想做这种麻烦事,于是写了个小脚本为添加到暂存区的修改添加注释:

    使用方法

    ./icomment path "comment"
    

    发出来给各位大佬看看还有没有可以改进的地方,请尽情批评。 https://github.com/LinkTTT/icomment

    22 replies  •  2023-02-27 17:53:55 +08:00
    yolee599
    yolee599
    Feb 26, 2023 via Android
    1
    个人觉得这种注释很丑陋,多此一举,在 commit 填写描述就行了。
    LinkT
    LinkT
    OP
    Feb 26, 2023
    2
    @yolee599 是的,我也这么觉得,但是公司规定,没办法。
    f1ush
    f1ush
    Feb 26, 2023
    3
    这要是重构改几十个文件的时候,不是看着人都麻了
    LinkT
    LinkT
    OP
    Feb 26, 2023
    4
    @f1ush 是的,但是你说这种情况是小 case.
    最恐怖的是注释外面套注释,我和我另一个同事戏称为:叠杀人书。 哈哈哈哈~
    yan17
    yan17
    Feb 26, 2023
    5
    公司这规定有点离谱啊,那要是后续再次修改,原来的注释要删除吗?
    ```
    public static void main(String[] args) {
    //zhangsan modify this for xxxx. 2023-02-26 start
    + //zhangsan modify this for xxxx. 2023-02-27 start
    + System.out.println("Bye, World! ");
    + //zhangsan modify this for xxxx. 2023-02-27 end
    //zhangsan modify this for xxxx. 2023-02-26 end
    }
    }
    ```
    不删不就变这样了?
    jfcherng
    jfcherng
    Feb 26, 2023❤️1
    6
    人肉 git blame?
    f1ush
    f1ush
    Feb 26, 2023
    7
    @LinkT 套注释?后续再修改真不删啊,那还需要 git 做什么啊哈哈哈
    aver4vex
    aver4vex
    Feb 26, 2023
    8
    见过。也写过。确实比较头大。
    Pastsong
    Pastsong
    Feb 27, 2023
    9
    是你们公司没人会用 git blame ?还是你们不用 git
    Reminders
    Reminders
    Feb 27, 2023 via iPhone
    10
    你们公司是人工版本控制嚒
    adoyle
    adoyle
    Feb 27, 2023❤️1
    11
    喊你们的 CTO 来给大家解解惑。干嘛不用 git blame 或者 git log -S ,非要用这套蹩脚的注释。
    如果一次提交只是删除代码是不是还得加上两行注释?多删改几次这文件不就满屏都是注释了?

    如果不会用命令行操作,那我推荐 [git-history]( https://github.com/pomber/git-history),网页浏览变更历史,能本地部署,也有 VS Code 插件。不香么?
    MajestySolor
    MajestySolor
    Feb 27, 2023
    12
    传说中的手工版本控制🐶
    vsyf
    vsyf
    Feb 27, 2023 via Android
    13
    我猜是 aosp ,chromium 之类吧。
    darkengine
    darkengine
    Feb 27, 2023
    14
    前公司会让加 JIRA 上的 issue 号,其实比较合理,看到注释之后可以很方便的查到为什么要改。
    imnpc
    imnpc
    Feb 27, 2023
    15
    这个是在不用 git 的时代采用的方法, 有了 git 以后 不会在用这种了
    xuanbg
    xuanbg
    Feb 27, 2023
    16
    没 Git 的时候也不需要这么写。又没写原来是啥 xx 改了啥,有个 P 用。
    Ally
    Ally
    Feb 27, 2023
    17
    破规定,毫无用处,还拉低效率
    cp19890714
    cp19890714
    Feb 27, 2023
    18
    git 是摆设吗?
    Andy223
    Andy223
    Feb 27, 2023
    19
    why don't u use 'git blame'?
    hxndg
    hxndg
    Feb 27, 2023❤️1
    20
    我印象中,无论是 gitblame 还是 svn 都有渴死的功能吧。。。。
    这以后代码多了就变成一层一层的梯田了吧。。。。
    simplereasy
    simplereasy
    Feb 27, 2023
    21
    大改动应该写
    Goat121
    Goat121
    Feb 27, 2023
    22
    你领导咋想的啊,这种代码看一眼都觉得烦,还怎么工作
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2328 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 79ms · UTC 12:57 · PVG 20:57 · LAX 04:57 · JFK 07:57
    ♥ Do have faith in what you're doing.