C# 你如何标记代码以便你可以稍后回来处理它?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/335378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you flag code so that you can come back later and work on it?
提问by Jon Tackabury
In C# I use the #warning
and #error
directives,
在 C# 中,我使用#warning
和#error
指令,
#warning This is dirty code...
#error Fix this before everything explodes!
This way, the compiler will let me know that I still have work to do. What technique do you use to mark code so you won't forget about it?
这样,编译器会让我知道我还有工作要做。你用什么技术来标记代码,这样你就不会忘记它?
采纳答案by Guge
Mark them with // TODO
, // HACK
or other comment tokens that will show up in the task pane in Visual Studio.
用或其他注释标记标记它们// TODO
,这些// HACK
标记将显示在 Visual Studio 的任务窗格中。
See Using the Task List.
请参阅使用任务列表。
回答by GurdeepS
Todo Comment.
Todo 评论。
回答by Elie
//TODO: Person's name - please fix this.
//TODO: 人名 - 请解决这个问题。
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.
这是在 Java 中,然后您可以查看 Eclipse 中的任务,该任务将定位对此标记的所有引用,并且可以按人对它们进行分组,以便您可以将 TODO 分配给其他人,或者只查看您自己的。
回答by Dustin
Add a test in a disabled state. They show up in all the build reports.
添加处于禁用状态的测试。它们出现在所有构建报告中。
If that doesn't work, I file a bug.
如果这不起作用,我会提交一个错误。
In particular, I haven't seen TODO comments ever decrease in quantity in any meaningful way. If I didn't have time to do it when I wrote the comment, I don't know why I'd have time later.
特别是,我没有看到 TODO 评论的数量以任何有意义的方式减少。如果我在写评论的时候没有时间去做,我不知道为什么我以后会有时间。
回答by Paul Tomblin
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.
gvim 以黄色突出显示“// XXX”和“// TODO”,这让我第一次以这种方式标记一些代码以提醒自己回到它时感到惊讶。
回答by John MacIntyre
If I've got to drop everything in the middle of a change, then
如果我必须在更改过程中放弃所有内容,那么
#error finish this
If it's something I should do later, it goes into my bug tracker (which is used for all tasks).
如果这是我以后应该做的事情,它会进入我的错误跟踪器(用于所有任务)。
回答by McKenzieG1
'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:
我赞成 Jon T 的一般策略,但我通常只是通过简单地暂时破坏代码来做到这一点 - 我经常插入一个故意未定义的方法引用,让编译器提醒我我需要回到什么:
PutTheUpdateCodeHere();
回答by Ulf Lindback
Todo comment as well.
Todo 评论也是如此。
We've also added a special keyword NOCHECKIN, we've added a commit-hook to our source control system (very easy to do with at least cvs or svn) where it scans all files and refuses to check in the file if it finds the text NOCHECKIN anywhere.
我们还添加了一个特殊的关键字 NOCHECKIN,我们在我们的源代码控制系统中添加了一个提交钩子(至少使用 cvs 或 svn 很容易做到),它会扫描所有文件并在找到时拒绝签入文件文本 NOCHECKIN 任何地方。
This is very useful if you just want to test something out and be certain that it doesn't accidentaly gets checked in (passed the watchful eyes during the diff of everything thats commited to source control).
如果您只想测试某些内容并确保它不会被意外签入(在提交给源代码控制的所有内容的差异期间通过警惕的眼睛),这将非常有用。
回答by Chris Lees
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.
我使用的组合//TODO:
//HACK:
,并throw new NotImplementedException();
在我的方法到是没有做过分别表示工作。此外,我在 Visual Studio 中不完整的行上添加书签。
回答by idan315
An approach that I've really liked is "Hack Bombing", as demonstrated by Oren Eini here.
我非常喜欢的一种方法是“Hack Bombing”,正如 Oren Eini在这里演示的那样。
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;
}