On 02/06/2010 03:55 PM, Matt Wozniski wrote:
> On Sat, Feb 6, 2010 at 1:50 PM, Girish Venkatasubramanian wrote:
>> Issues with tw 80 and fo=crqa
>> -------------------------------------------
>> 1) When textwdith iss set to 80 and I have two lines of code like
>> //This is a comment; This is a comment This is a comment
>> printf("Hello, World\n");
>>
>> commenting out the printf with a // gives me
>> //This is a comment; This is a comment This is a comment
printf("Hello, World\n"
>> //);
>> which seems quite ugly
>
> There's not really any way for this to differentiate between commented
> out code and "real" comments, though. It makes sense that it blends
> them together.
This is one reason I prefer to use ``#if 0 / #endif`` instead of
comments to compile out code. Instead of doing this:
// printf("Hello, World\n");
I do this:
#if 0
printf("Hello, World\n");
#endif
It has several other advantages:
- It clearly groups the section of code that's being removed,
and distinguishes that code from "regular" comments.
- It's easy to toggle the code in and out by changing the ``0``.
- Using C-style comments (/* like this */) to compile out code
doesn't nest well with other C-style comments embedded in the
code; using C++-style comments is not portable to all C
compilers and requires modifying every line in the group. By
comparison, ``#if 0 / #endif`` nests well and requires
modification only at both ends of the code group.
- It's useful for trying out new code, like this:
#if 0
oldCode();
wouldBeHere();
#else
newCode();
replacingAboveOldCode();
#endif
You can retain the original code while you work on refactoring
it into new code. At any time, you can easily switch back to
the old code for testing.
- When there are multiple sections of code that must be compiled
out all together or not at all during testing, it's easy to
add a new #define to control the sections together:
#define USING_OLD_CODE 0
#if USING_OLD_CODE
someOldCode();
#endif
/* ... */
#if USING_OLD_CODE
moreOldCode();
#else
withPossibleNewCode();
#endif
Michael Henry
--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php