On Nov 21, 2011, at 5:51 PM, Andrew Burton wrote:
No arguments there. I used to manage some
programmers and I'd find lots
of lines like:
a++; // add one to a
Totally pointless.
When I started learning (and coding in) 68000 assembly that's exactly the
sort of thing I used to write after each instruction.
Three years later and I no longer write that rubbish :) Instead I only
write comments where needed (e.g. when it isn't obvious what a particular
register is storing) and the things that give a bigger overview of what is
going on is prefixed and postfixed with asterisks to highlight it (e.g. ****
setup & display screen ****).
Certainly when I'm annotating previously unknown assembly (particularly if it's a
disassembly for which there are no comments or other semantic data to begin with), I tend
to annotate EVERY line unless it does something stupidly obvious (like return, or a really
obvious add right after a load, etc.) because I know I can't juggle all the register
semantics around in my head while I'm still discovering them.
In higher-level code, this is totally dumb:
a++; // add one to a
Whereas the following is helpful:
*dst++ = *src++; // Copy a word of src to dst while incrementing both
because, as mentioned, you're doing something "clever" that might not be
immediately apparent to people (we discourage people who are just starting C from doing
things like that exact example because until they've had more time to get used to it,
they usually assume it means (*src)++ instead of *(src++) and re-use it the wrong way in
their own code).
Or, of course, if you've been intentionally obtuse about your variable names (chances
are you should never REALLY have a variable named "a" unless there's a very
good reason to do so), you might need to explain what "a" is when you increment
it. Or, if it's a pointer to a struct, it's a good time to point out that
you're incrementing the pointer by one struct stride, not one byte. It's a matter
of whether the semantics are obvious, but I've found everyone has different metrics
for that.
- Dave