Know Your Next Commit

本文探讨了如何通过明确任务、分解问题和避免过量工作来优化代码提交流程,减少不必要的时间浪费和提高代码质量。通过实例分析,指导开发者在面对任务时做出更明智的选择,确保每次提交都有清晰的目的和实现路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Know Your Next Commit

Dan Bergh Johnsson

i TAPPED THREE PROGRAMMERS ON THEiR SHOULDERS and asked what they were doing. “I am refactoring these methods,” the first answered. “I am adding some parameters to this web action,” the second answered. The third answered, “I am working on this user story.”
It might seem that the first two were engrossed in the details of their work, while only the third could see the bigger picture, and that he had the better focus. However, when I asked when and what they would commit, the picture changed dramatically. The first two were pretty clear about what files would be involved, and would be finished within an hour or so. The third programmer answered, “Oh, I guess I will be ready within a few days. I will probably add a few classes and might change those services in some way.”
The first two did not lack a vision of the overall goal. They had selected tasks they thought led in a productive direction, and could be finished within a couple of hours. Once they had finished those tasks, they would select a new feature or refactoring to work on. All the code written was thus done with a clear purpose and a limited, achievable goal in mind.
The third programmer had not been able to decompose the problem and was working on all aspects at once. He had no idea of what it would take, basi- cally doing speculative programming, hoping to arrive at some point where he would be able to commit. Most probably, the code written at the start of this long session was poorly matched for the solution that came out in the end.
94 97 Things Every Programmer Should Know

What would the first two programmers do if their tasks took more than two hours? After realizing they had taken on too much, they would most likely throw away their changes, define smaller tasks, and start over. To keep work- ing would have lacked focus and led to speculative code entering the reposi- tory. Instead, changes would be thrown away, but the insights kept.
The third programmer might keep on guessing and desperately try to patch together his changes into something that could be committed. After all, you cannot throw away code changes you have done—that would be wasted work, wouldn’t it? Unfortunately, not throwing the code away leads to slightly odd code that lacks a clear purpose entering the repository.
At some point, even the commit-focused programmers might fail to find something useful they thought could be finished in two hours. Then, they would go directly into speculative mode, playing around with the code and, of course, throwing away the changes whenever some insight led them back on track. Even these seemingly unstructured hacking sessions have purpose: to learn about the code to be able to define a task that would constitute a produc- tive step.
Know your next commit. If you cannot finish, throw away your changes, then define a new task you believe in with the insights you have gained. Do specula- tive experimentation whenever needed, but do not let yourself slip into specu- lative mode without noticing. Do not commit guesswork into your repository.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值