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

前端 未结 23 2072
后悔当初
后悔当初 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 12:18

    An approach that I've really liked is "Hack Bombing", as demonstrated by Oren Eini here.

    try
    {
       //do stuff
       return true;
    }
    catch // no idea how to prevent an exception here at the moment, this make it work for now...
    {
      if (DateTime.Today > new DateTime(2007, 2, 7))
        throw new InvalidOperationException("fix me already!! no catching exceptions like this!");
      return false;
    }
    
    0 讨论(0)
  • 2020-12-24 12:19

    Besides keying off the "TODO:" comment, many IDE's also key off the "TASK:" comment. Some IDE's even let you configure your own special identifier.

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

    It is probably not a good idea to sprinkle your code base with uninformative TODOs, especially if you have multiple contributors over time. This can be quite confusing to the newcomers. However, what seems to me to work well in practice is to state the author and when the TODO was written, with a header (50 characters max) and a longer body.

    Whatever you pack into the TODO comments, I'd recommend to be systematic in how you track them. For example, there is a service that examines the TODO comments in your repository based on git blame (http://www.tickgit.com).

    I developed my own command-line tool to enforce the consistent style of the TODO comments using ideas from the answers here (https://github.com/mristin/opinionated-csharp-todos). It was fairly easy to integrate it into the continuous integration so that the task list is re-generated on every push to the master.

    It also makes sense to have the task list separate from your IDE for situations when you discuss the TODOs in a meeting with other people, when you want to share it by email etc.

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

    It's not a perfect world, and we don't always have infinite time to refactor or ponder the code.

    I sometimes put //REVIEW in the code if it's something I want to come back to later. i.e. code is working, but perhaps not convinced it's the best way.

    // REVIEW - RP - Is this the best way to achieve x? Could we use algorithm y?
    

    Same goes for //REFACTOR

    // REFACTOR - should pull this method up and remove near-dupe code in XYZ.cs
    
    0 讨论(0)
  • 2020-12-24 12:22

    //TODO: Person's name - please fix this.

    This is in Java, you can then look at tasks in Eclipse which will locate all references to this tag, and can group them by person so that you can assign a TODO to someone else, or only look at your own.

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