if it's any good code, it would be self-documenting. comments irrelevant
Name:
Anonymous2007-09-27 0:28 ID:U0atWLRC
>>3
Sometimes you have to do something tricky for whatever reason. This is a very good reason for comments. Also, you should only write comments that explain why rather than how.
Name:
Anonymous2007-09-27 0:55 ID:97vmSJrI
>>3
That's why you only comment non-trivial things, or abstract reasoning behind the code.
Name:
Anonymous2007-09-27 1:10 ID:XSTmPQR/
#include <iostream>
int far ( int x )
{
return (x-32)*(5/9);
}
int cel ( int x )
{
return x+32*(9/5);
}
using namespace std;
int faren();
int cels();
int main ()
{
int input;
cout<<"1. Celsius to Fahrenheit\n";
cout<<"2. Fahrenheit to Celsius\n";
cout<<"Selection: ";
cin>> input;
switch ( input ) {
case 1:
cels();
break;
case 2:
faren();
break;
default:
cout<<"Error\n";
break;
}
>>3
So called "self-documenting" code tells you what it's doing, but not why. Comments that say "what" are useless, since duh, that's what the code says. Comments that say "why" are what people are always too stupid to include. Then again, most programmers are just genetic programmers that beat against it randomly until it works and have no fucking clue why it works.
Name:
Anonymous2007-09-27 2:01 ID:ecw0geTG
>>9
But "why" isn't the programmer's job, unless it's a non-corporate project.
Name:
Anonymous2007-09-27 2:07 ID:nmdtfKut
>>1
Comments are rarely required, and they are often abused to the point where it is difficult to find the code buried inside.
Name:
Anonymous2007-09-27 2:12 ID:Mr3/70No
>>10
It is definitely the programmers job to show why the decisions in his code fulfill the requirements.
Name:
Anonymous2007-09-27 2:36 ID:nmdtfKut
>>12
Look, the only way to know if what the programmer is doing "fulfills" the requirements, every line of assembly generated must be analyzed. Comments do *not* prove this.
Name:
Anonymous2007-09-27 2:40 ID:Mr3/70No
>>13
It's not a proof, it's a description of the decisions the programmer made that resulted in him writing that code. What, you've never looked at code, scratched your head, and thought "Why the fuck did he put that in there?" or "How does this even work?"
Name:
Anonymous2007-09-27 2:45 ID:nmdtfKut
>>14
Well, if the code isn't straightforward, then yes. Good programmers have a habit of making most of their code straightforward, with the exception usually being optimizations and shortcuts.
Name:
Anonymous2007-09-27 2:56 ID:Mr3/70No
>>15
...and writing code with ordering dependencies, and when downcasting under preconditions enforced elsewhere, and when doing state machines or other fragmented code, and when writing workarounds for buggy libraries or OS calls, etc. All of which are not optimizations nor shortcuts, but whose rationale needs to be documented in the code so others don't fuck it up.
Name:
Anonymous2007-09-27 3:06 ID:s6uKrndR
If you give me code without a fully specified proof in Coq...
I'LL BREAK YOUR FUCKING FACE!!!!11111
Name:
Anonymous2007-09-27 3:14 ID:97vmSJrI
>>15
Good programmers also make use of the language features available to good effect. Writing for an audience that is stupider than oneself is a good way to become stupid too.
>>18
Congratulations, according to this thing, you're fucking gay.
Name:
Anonymous2007-09-27 5:35 ID:kega/RfR
If you add a comment like this:
#include "stdafx.h" // lulz, why microsoft - you sux
or like this:
class Foo
{
//----------------
// Foo Constructor
//----------------
Foo()
{
}
};
I'LL BREAK YOUR FUCKING FACE!!!!11111
Name:
Anonymous2007-09-27 16:39 ID:nmdtfKut
>>16
The details of both of those could easily be hidden in classes such as FSM and OSCommand. The point is that a good programmer keeps a consistent intuitive style where comments are only necessary in the implementation details of the various functions are in another file. The right design ensures that everything the client will see is clear. Comments will not help clients get a grasp of very complicated code, since they are generally less versed in the details of a programming language.