CORed
Penultimate Amazing
I do that all the time.
I usually put "This should never happen".
I do that all the time.
Heck, every ASSERT statement is basically saying that.CORed said:I usually put "This should never happen".
I demand a list of all 12 comments. I can't wait ...SkepticScott said:One of 12 comments in a 1000-line module I was code-reviewing was something like:
//#include <stdlib.h> fix this!
I wish I could oblige you, but I don't remember them all. I think one or two were actually useful.I demand a list of all 12 comments. I can't wait ...
Or even:a_unique_person said:I like the redundant comments.
LD X ; Add 1 to X.
A =1
ST X
It's you. You are the problem.I've left the following many times:
# Why are you reading the comments? You do know comments usually say what the code is supposed to do or what it did at one time, not what it really does now. READ THE CODE.
Damn straightIt's you. You are the problem.
I'm trying to remember where I read about this--Joel On Software, maybe?--anyway, a programmer who, on long projects, would place a "you are here" comment in his code whenever he took a break from coding, so that he could more easily pick up where he left off when he returned.
ETA: Presumably, unlike my own personal experiences with programming, the last function he touched didn't haunt his every waking thought (and most of his dreams) from the moment he left the code until the moment he returned.
Obligatory reference to:
StackOverflow - What is the best comment in source you have ever encountered.
Me at link said:Next to a local variable that had to be declared just to pass a constant to a library function:
Code:// This only exists because Scott doesn't know how to use const correctly
i've left the following many times:
# why are you reading the comments? You do know comments usually say what the code is supposed to do or what it did at one time, not what it really does now. Read the code.
it's you. You are the problem.
damn straight
Hehe, yeah. Around page three of the answers on that one you'll find this response by me, which is the highest ranked answer I've ever given on Stack Overflow.
To save you a click:
Sorry, I don't understand. What is this conversion of which you speak?MRC_Hans said:Actually, it may have a purpose to assign a value to a variable, instead of using a const. You see, every time a value from a const is used, it has to be converted, so if you use that value a lot of times, your code executes faster when using a variable. Been there, dunnit.
Could you give an example? Are you saying that (assuming no optimization)You see, every time a value from a const is used, it has to be converted, so if you use that value a lot of times, your code executes faster when using a variable. Been there, dunnit.
int a = 1;
int b, i;
for( i = 0; i < 1000000; ++i )
b = a;
const int a = 1;
int b, i;
for( i = 0; i < 1000000; ++i )
b = a;
Could you give an example? Are you saying that (assuming no optimization)
executes faster thanCode:int a = 1; int b, i; for( i = 0; i < 1000000; ++i ) b = a;
The compiler would generate "b=1" in the second case. In fact it would do all the conversion at compile-time, so if you had "float c = a;" that would be the same as writing "float c = (float)1;".Code:const int a = 1; int b, i; for( i = 0; i < 1000000; ++i ) b = a;
Most assembly languages have instructions for setting a register to an immediate value; if they're small enough they even fit in the same storage unit so the const could save a memory fetch.
)I've left the following many times:
# Why are you reading the comments? You do know comments usually say what the code is supposed to do or what it did at one time, not what it really does now. READ THE CODE.