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

前端 未结 23 2033
后悔当初
后悔当初 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:13

    I use // TODO: or // HACK: as a reminder that something is unfinished with a note explaining why. I often (read 'rarely') go back and finish those things due to time constraints. However, when I'm looking over the code I have a record of what was left uncompleted and more importantly WHY.

    One more comment I use often at the end of the day or week:

    // START HERE CHRIS

    ^^^^^^^^^^^^^^^^^^^^ Tells me where I left off so I can minimize my bootstrap time on Monday morning.

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

    As most programmers seem to do here, I use TODO comments. Additionally, I use Eclipse's task interface Mylyn. When a task is active, Mylyn remembers all resources I have opened. This way I can track

    1. where in a file I have to do something (and what),
    2. in which files I have to do it, and
    3. to what task they are related.
    0 讨论(0)
  • 2020-12-24 12:16

    gvim highlights both "// XXX" and "// TODO" in yellow, which amazed me the first time I marked some code that way to remind myself to come back to it.

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

    I'm a C++ programmer, but I imagine my technique could be easily implemented in C# or any other language for that matter:

    I have a ToDo(msg) macro that expands into constructing a static object at local scope whose constructor outputs a log message. That way, the first time I execute unfinished code, I get a reminder in my log output that tells me that I can defer the task no longer.

    It looks like this:

    class ToDo_helper
    {
      public:
         ToDo_helper(const std::string& msg, const char* file, int line)
         {
           std::string header(79, '*');
           Log(LOG_WARNING) << header << '\n'
                            << "  TO DO:\n"
                            << "    Task:  " << msg << '\n'
                            << "    File:  " << file << '\n'
                            << "    Line:  " << line << '\n'
                            << header;
         }
    };
    
    #define TODO_HELPER_2(X, file, line) \
      static Error::ToDo_helper tdh##line(X, file, line)
    
    #define TODO_HELPER_1(X, file, line) TODO_HELPER_2(X, file, line)
    #define ToDo(X) TODO_HELPER_1(X, __FILE__, __LINE__)
    

    ... and you use it like this:

     void some_unfinished_business() {
       ToDo("Take care of unfinished business");
     }
    
    0 讨论(0)
  • 2020-12-24 12:17
    // TODO: <explanation>
    

    if it's something that I haven't gotten around to implementing, and don't want to forget.

    // FIXME: <explanation>
    

    if it's something that I don't think works right, and want to come back later or have other eyes look at it.

    Never thought of the #error/#warning options. Those could come in handy too.

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

    This is my list of temporary comment tags I use:

    //+TODO  Usual meaning.
    //+H     Where I was working last time.
    //+T     Temporary/test code.
    //+B     Bug.
    //+P     Performance issue.
    

    To indicate different priorities, e.g.: //+B vs //+B+++

    Advantages:

    • Easy to search-in/remove-from the code (look for //+).
    • Easy to filter on a priority basis, e.g.: search for //+B to find all bugs, search for //+B+++ to only get high priority ones.

    Can be used with C++, C#, Java, ...

    Why the //+ notation? Because the + symbol looks like a little t, for temporary.

    Note: this is not a Standard recommendation, just a personal one.

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