|
Some people really don't get when they should use switch/select statements
|
|
|
|
|
|
The fact that the final else block will never be executed suggests either (a) this code used to do something different and has been hacked around blindly, or (b) the person who wrote it didn't really understand what he was doing.
|
|
|
|
|
or (c) he really didn't trust integers. To be sure, to be sure, to be sure...
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
...but in real-life I've seen "obviously unnecessary" else-blocks quite often. Most times there was an error-handling routine, which put something like "unhandled case; please look at routine foo()" to your log-file. And in some cases it make sense - who guarantees you that a guy who extends this routine, thought on all possible occurances of "i"?
|
|
|
|
|
I already saw a teacher showing "how" to use switches.
The combo-box had 2 values:
Gif.
Jpg.
Then, in the code, he did something like:
for(int i=0; i<2; i++)
{
if (i == combo.SelectedIndex)
{
switch(i)
{
case 1:
break;
case 2:
break;
}
}
}
Note that not only the "for" is useless, the "switch" using the values of a for is ridiculous... but the valid values are 0 and 1, and the code checked for 1 and 2.
And finally, but not presented in the code, the code was copied and the filename was something + ".gif" or something + ".jpg"... he could simple do a better working code with:
string name = editName.Text + '.' + combo.SelectedValue;
|
|
|
|
|
or maybe he is just impressing his students how genius he is
|
|
|
|
|
Someone who has been using Python for a while?
|
|
|
|
|
Found this description on a function called "Periodic" yesterday.
<br />
"This function is periodic, it runs periodically. This function will be executed every period"<br />
Mark Brock
"We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen
|
|
|
|
|
That's exactly what we need - functions with PMT!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
A comment like that would make you wonder if it actually was executed every period... Or was the commenter just trying to egg it on...
|
|
|
|
|
"then shalt thou count to three, no more, no less"
Hey yes, exactly three times telleth he the nature of this very function!
|
|
|
|
|
I fail to see the problem. It's clear and to the pouint.
Everything makes sense in someone's mind
|
|
|
|
|
Almost as good as:
"Now frig about with the data until we get the right answer"
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
Indeed!!!
That's what I call a good comment
It's almost as good as saying "this function will run each time it gets called"!!
Just an irritated, ranting son of ... an IT guy.
At your trolling services
|
|
|
|
|
Reminds me of answers to an exam...after the 5th consecutive answer being the same the voice in my head will start to question if I am actually getting them right :/
|
|
|
|
|
maybe he put that comment there so that when he become senile later on his life
and stumble across to that code, he will remember everything just glancing
on that pretty witty comment
|
|
|
|
|
#region InterfaceImplementation(s)
public int CompareTo(Project other)
{
return this.Description.CompareTo(other.Description);
}
public bool Equals(Project other)
{
return this.PN.Equals(other.PN);
}
#endregion
I kid you not. This is eaxctly as my former collegue left it. Including the comments.
A further look in the code(where the calss is actualy used) he did something like
if(BinnarySearch(currentProj)!=0){
{ if ListOfItems.Contains(currentproject) return true;
else return false;}
else return true;}
Instead of doing something like(pseudo kindof only):
if((descriptionComparer==0) || (PN_Comparer==0)) {return 0;}
else if(descriptionComparer<0){return -1;}
else{return 1;}
inside the CompareTo method. Why??? I guess, that he thought that it will be faster in most cases.
As a note, neither myself or my famous former collegue are programmers per say.
We're just lazy suns of ... and we did all kind of "apps" to limit the number of
phones and/or mails geared toward us from the users.
modified on Sunday, May 2, 2010 9:18 PM
|
|
|
|
|
SELECT Actions = REVERSE(RTRIM(REVERSE(@Plan)))
Copied verbatim from production code (including the code comment).
|
|
|
|
|
Well, obviously right-trimming is more efficient than left-trimming.
|
|
|
|
|
LOL, I couldn't think of why they would possibly do that, but a misguided attempt at optimization seems feasible.
|
|
|
|
|
Almost certainly.
If you are doing a search, then LTRIM(my_col) LIKE 'A%' may be much slower than RTRIM(my_col) LIKE 'A%'. That's because the second query can use an index on my_col, whereas the first one can't.
So, from there someone might wrongly conclude that the LTRIM operation itself is slower than RTRIM, and avoid using LTRIM in all cases. It's not the LTRIM operation per se that's a problem, it's the fact that it precludes the use of indexes during searches.
|
|
|
|
|
Test App : MFC dialog typed (unmanaged)
Code:
char szModel1 [256] = { "REQ$-$$$$-$$$$-$$$$-$$$$-$$$$" };
size_t sizeModel1 = strlen ( szModel1 );
char szModel2 [256] = { "REQ?-????-????-????-????-????" };
size_t sizeModel2 = strlen ( szModel2 );
Result on debugger on VC2003 & VC2005, I don't test it on 2008 & 2010 if some one can try...
+ szModel1 0x0012fc10 "REQ$-$$$$-$$$$-$$$$-$$$$-$$$$" char [256]
+ szModel2 0x0012fafc "REQ?-??~??~??~??~????" char [256]
sizeModel1 29 unsigned int
sizeModel2 21 unsigned int
The content and the size of the string is bad with "??-" sequence...
Strange
...
|
|
|
|
|
|
really it is the good old trigraphs
i dont know if they abandoned them in C++0X, but at THAT time, they WERE useful
nowadays, they are annoying :<
look at this[^] for example =D
|
|
|
|