| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
On 8/29/03 9:21 PM, Camillo Lugaresi didst favor us with:
> At 21:09 -0400 28-08-2003, Laurence Harris wrote:
>> For example, one could replace all this stuff we've been using in our
example with function named:
SizeControlToFillWindowLeavingSpaceForHorizScrollbar( control, window );
This would not only eliminate the need for a comment IMO, but it would
condense the code considerably in a good way by eliminating the clutter
created be the local variables.
Um, I think most readers would see this specific example as an
argument _against_ self-documenting code. It looks more like a
caricature than something I'd want to see in an actual program.
Well, I only came up with it to demonstrate that you *can* be pretty clear
if you want to be. But as for seeing something like this in an actual
program, I don't think that's relevant. If you named a function with that
name, you'd see it in a program.
The point is that you don't have to be
limited to concatenating three words.
Do you think you'd ever see an API with a name like:
SetAutomaticControlDragTrackingEnabledForWindow()
in a program, or does that look like a caricature too? ;-)
> More specifically, I think that line of code is akin to thetautologic comments lamented by many.
As was said before, you don't need to have comments that document the
OS, or teach what a pointer is, or explain that x = 1 "Sets the value
of x to 1".
Similarly, you don't have to factor every single step of an algorithm
into a separate function and give it a name that is basically a long
comment explaining what it does in plain English, save for the
absence of spaces.
Everyone is different, but I can read through code faster if it uses these
kinds of helper utilities and the names are meaningful. Maybe I'm inherently
skeptical, but if I see a comment preceding a line of code, I'll read the
comment, and then I'll read the code to be sure it matches up with the
comment. That may seem silly if you've never seen a comment that was out of
sync or a line of code that simply didn't do what the author thought it did,
but the compiler generates object code from source code, not comments, so I
want to be sure they match up. So anyway, I read comments *and* code, and if
I can eliminate the comment part, I can read through code more efficiently.
YMMV
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.