Here is another point that the style guide is not clear on. When we have:
#if condition_foo
...
#else
...
#endif // comment_in_questions
should comment_in_question be:
1. condition_foo, so we know which #if the #endif refers to.
or
2. !condition_foo, so we know what conditions satisfy the #else block.
I agree with this, although after looking through the code #1 seems
more common currently
> PK
>
> --
> Chromium Developers mailing list: chromi...@chromium.org
> View archives, change email options, or unsubscribe:
> http://groups.google.com/a/chromium.org/group/chromium-dev
>
Personally, I recommend doing whatever you think looks clearest when
you write the code. We standardize a lot of things, which is nice, but
at a certain point it becomes too much overhead to worry about. Just
be consistent with surrounding code.
Brett
Brett
Except that this sort of falls apart as soon as there is an #elif involved.
#if A
#elif B // A? B && !A ?
#endif // A (?!)
Add another #elif and things get extra ugly, and the chances of the
comments staying accurate over time go down.
Personally I've found that in practice since I don't know how many
#else or #elif cases there are, or what style the author used, these
comments aren't actually useful beyond helping me match lines in
nested #if constructions; they don't actually tell me what the logic
above the #endif is for in isolation. In any non-trivial case I would
actually find:
#if A // Foo
#elif B // Foo
#end // Foo
more useful since it doesn't pretend it will communicate information
about the logic that it doesn't really. As long as the nesting doesn't
get too bad either style is mentally mappable to this though, and if
the nesting is so confusing that it's not, the code probably has
deeper problems.
-Stuart
In any non-trivial case I would
actually find:
#if A // Foo
#elif B // Foo
#end // Foo
more useful since it doesn't pretend it will communicate information
about the logic that it doesn't really.
--
what is Foo in this case? If Foo == A then it's pretty confusing for
the #else case
>
> -Stuart
Foo in my example is an arbitrary string that's not at attempt to
describe the logic, precisely so that there's no confusion as to which
sense it's being used in. It's just a marker that allows someone to
quickly find the other associated lines, particularly if there are
nested #if's.
-Stuart