How do you flag code so that you can come back later and work on it?

前端 未结 23 2069
后悔当初
后悔当初 2020-12-24 11:46

In C# I use the #warning and #error directives,

#warning This is dirty code...
#error Fix this before everything explodes!
<         


        
相关标签:
23条回答
  • 2020-12-24 11:56
    //TODO: Finish this
    

    If you use VS you can setup your own Task Tags under Tools>Options>Environment>Task List

    0 讨论(0)
  • 2020-12-24 11:59

    I use a combination of //TODO: //HACK: and throw new NotImplementedException(); on my methods to denote work that was not done. Also, I add bookmarks in Visual Studio on lines that are incomplete.

    0 讨论(0)
  • 2020-12-24 11:59

    I also use TODO: comments. I understand the criticism that they rarely actually get fixed, and that they'd be better off reported as bugs. However, I think that misses a couple points:

    • I use them most during heavy development, when I'm constantly refactoring and redesigning things. So I'm looking at them all the time. In situations like that, most of them actually do get addressed. Plus it's easy to do a search for TODO: to make sure I didn't miss anything.

    • It can be very helpful for people reading your code, to know the spots that you think were poorly written or hacked together. If I'm reading unfamiliar code, I tend to look for organizational patterns, naming conventions, consistent logic, etc.. If that consistency had to be violated one or two times for expediency, I'd rather see a note to that effect. That way I don't waste time trying to find logic where there is none.

    0 讨论(0)
  • 2020-12-24 12:01

    These are the three different ways I have found helpful to flag something that needs to be addressed.

    1. Place a comment flag next to the code that needs to be looked at. Most compilers can recognize common flags and display them in an organized fashion. Usually your IDE has a watch window specifically designed for these flags. The most common comment flag is: //TODO This how you would use it:

      //TODO: Fix this before it is released. This causes an access violation because it is using memory that isn't created yet.

    2. One way to flag something that needs to be addressed before release would be to create a useless variable. Most compilers will warn you if you have a variable that isn't used. Here is how you could use this technique:

      int This_Is_An_Access_Violation = 0;

    3. IDE Bookmarks. Most products will come with a way to place a bookmark in your code for future reference. This is a good idea, except that it can only be seen by you. When you share your code most IDE's won't share your bookmarks. You can check the help file system of your IDE to see how to use it's bookmarking features.

    0 讨论(0)
  • 2020-12-24 12:02

    'To do' comments are great in theory, but not so good in practice, at least in my experience. If you are going to be pulled away for long enough to need them, then they tend to get forgotten.

    I favor Jon T's general strategy, but I usually do it by just plain breaking the code temporarily - I often insert a deliberately undefined method reference and let the compiler remind me about what I need to get back to:

    PutTheUpdateCodeHere();
    
    0 讨论(0)
  • 2020-12-24 12:04

    If it's some long term technical debt, you can comment like:

    // TODO: This code loan causes an annual interest rate of 7.5% developer/hour. Upfront fee as stated by the current implementation. This contract is subject of prior authorization from the DCB (Developer's Code Bank), and tariff may change without warning.

    ... err. I guess a TODO will do it, as long as you don't simply ignore them.

    0 讨论(0)
提交回复
热议问题