回複內容:
When working on a project, it's often needed to create a list of tasks for yourself or your team mates. While usually these tasks are described in an issue tracker like YouTrack
, some tasks are either too small or too code-specific to describe in an issue tracker. In such a case, adding TODO comments in source code makes sense.
具體來說,當你在寫代碼時,突然意識到你之前的代碼有一個潛在的小bug,但不重要,一般人通常的做法是:
- 立刻去修複bug,然後當你返回你現在的工作時,你的思路就被打斷了
- 把bug記在腦子裡,繼續寫你的代碼,很快這個bug就被你忘了
- 在bug的地方打一個注釋,繼續寫代碼,很快這個bug又被你忘了,很久以後,當你翻之前的代碼時你才發現這裡有個注釋
- ……
明智的做法是:
在bug旁邊寫一個
“#todo: computer will explode while running the program for 24+ hours”,然後繼續寫代碼。
為了防止你今後忘掉這個bug,pycharm會在3個地方提示你:
另外,在多人協作的項目中,todo還可以用來區分
“誰要去修複這個bug”。PyCharm官方文檔
介紹如下:
create several filters, which you will use to show the TODO items, say, for each of the developers, and not for your good self. For this purpose, in the Filters section, click , and specify the filter names, for example, For John, For Bob, and not for me. Associate these filters with the patterns:
Now, in the source code, create TODO items: in the line of code, where you want to add a note, press Ctrl+Slash, or Ctrl+Shift+Slash, and type TODO that matches one of the patterns, followed by some meaningful description: