Hack 21. Never Forget a TODO Again

developers that are nearly impossible to miss.The
task list (Ctrl-Alt-K/View.TaskList) is a handy
tool that is most often used to view errors or warnings from the
compilation of your code. In Visual Studio .NET 2003, when you
compile your project, any errors or warnings are displayed in the
task list. You can read the message and double-click on the item to
jump to the offending line in your code. (Visual Studio 2005 includes
a separate error list.)The task list also has another use; it can be used to leave reminders
for yourself or other members of your team in comment form.
3.7.1. Comments
By default, the
task list includes three different
comments; these are
//TODO,
//UNDONE, and //HACK.
|
will show up in the task list when the file with the comment is open.
Visual Studio .NET 2003 uses this functionality by default when you
create a new class; it adds the following code to the constructor of
every new class:
//First make sure that the task list is configured to show comments,
// TODO: Add constructor logic here
//
and then you will see in the task list that this comment has been
added as an item, as shown in Figure 3-14.
Figure 3-14. Task list comments

|
you need to add code. The other two comments work much the same way.
You simply need to use
//HACK: and a task list item will be created
for that comment. You can use shortcuts to step back and forth
between tasks as well. The View.NextTask
(
Ctrl-Shift-F12) and
View.PreviousTask (no default shortcut) commands can be
used to step through the tasks listed in the task list.You can also click in the area at the top of the task list with the
text
"Click here to add a new task," or
in Visual Studio 2005, you can click the Create User Task button.
This creates a user task for you and acts much like the tasks portion
of Outlook. You can also tag any line in your project as a task by
using the Edit.ToggleTaskListShortcut (Ctrl-K,
Ctrl-H) command. Whenever you
call this command, it will add a shortcut to the task list pointing
to this line of code. You can then add text that says what should be
done to the line of code. It is a quick and easy way to add something
to the task list to tackle later on. These tasks will appear only on
your system and not on the systems of your team members.Task list comments are a great way to remind you or others of
something that still needs to be done or something that may need to
be revisited for enhancement.
3.7.2. Custom Comments
You can also define and use custom comments
with the task list. Custom comments can be very useful if you want to
create a more specific comment. You can set a priority level higher
than the other comments so you can differentiate the comments easier.
I'll walk through creating a custom comment called
REFACTOR. You could use this comment to mark places that you feel
need to be refactored. I will also create a second custom comment
called BROKEN that will have a higher priority (since you
don't want broken code in your project for long).To add a new comment, you first need to go to Tools
Options and then select Task List under the Environment folder. Then
simply type the name of the new comment in the Name textbox, and the
Add button will become active. These comments are case sensitive, so
using all caps will help to ensure that the names do not get
mistypedthis is also consistent with the default Visual Studio
tokens. Figure 3-15 shows an example of adding a
REFACTOR comment.
Figure 3-15. New task list comment added in Options dialog

Add, this comment will be added to the list. Next, you need to do the
same thing for the BROKEN comment by simply repeating the same
process, except this time set the priority to High.After you have added both of the custom comments, you will be able to
use them in your code. Figure 3-16 shows your task
list after adding both REFACTOR and BROKEN comments to your document.
Figure 3-16. Task list with custom comments

information to other members on your team or just as a way to remind
yourself of something that needs to be done.