Pycharm裡面的TODO功能有什麼作用?

來源:互聯網
上載者:User

回複內容:

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:
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.