Register and share your invite link to earn from video plays and referrals.

绚香音 Rizumu
@RizumuA3
aka 小音 LittleSound|💚 Member of Vue,参与开发 Vapor 模式中|🪀 玩 3D 打印并制作了大量程序员周边| 🔥热爱开源|Pride → 🧠 AuDHD、🏳️‍⚧️ she/her|🎮 喜欢玩 魂系、任天堂游戏|🐙: LittleSound
Joined January 2020
1.6K Following    12.4K Followers
因为 AI 很喜欢在代码里乱写注释。 我为了让 AI 写出清晰的代码注释写了一份 提示词。最终效果上来说,我不仅解决了注释混乱的问题,我还获得了非常优质的代码注释。比我自己写的都好。 * 如果每个使用某段代码(比如函数)的人都需要去阅读代码的内容,学习一遍它如何实现,那么这个代码就没有做好它的职责,违反了函数是“黑箱”的 基础定义。 所以函数体内的注释是仅是为了编写和修改函数的人所写的。但是代码最好是不言自明的,如果函数内部需要编写注释,那第一优先考虑的应该是这段代码有没有更清晰的写法,只在实在没办法的时候才编写函数内部的注释。 函数外的注释是为了函数的使用者而写的。函数通常有函数签名和函数体构成。函数的调用者使用时只能看到函数签名。比如输入输出的类型。但是总有一些事情从这些上面看不出来,比如函数什么情况下会报错。使用的时候需要注意的事情。像是事件监听器需要注意如何、何时取消注册。 其中有一个简单的原则:“注释应该写在函数外面而不是里面,描述调用者不显而易见的事情。” 最终的 Prompt 像是这样: - Use the `/** ... */` syntax at the beginning of a function to write comments, focusing on aspects that are not easily understood by reading the function interface. - The same applies to `computed` and `watch` `watchEffect` ... etc in Vue - add comments when their purpose is not clear from their name. - Avoid writing comments inside the function body unless the code logic is very complex. 如果你想让 AI 在 Vibe Coding 注释的时候只用英文,还可以加上: - Write comments in English.
Show more