if if if if if if
-
if (!(i & (12|19|26|33))) i++;
**
xacc.ide-0.2.0.77 - now with C# 3.5 support and Navigation Bar!^
New xacc.ide release RSS feed^**
I don't think this is correct if you or 12 with 19you get 31 all of them give you 63 this means that (i & (12|19|26|33)) == (i & (63)) and that will be true for 63 and for 177 and for 191 and so on ... The following should be correct
if(!( i==12 || i==29 || i==26 || i==33)) ++i;
codito ergo sum
-
i++;
if (i == 13)
i = 12;
if (i == 20)
i = 19;
if (i == 27)
i = 26;
if (i == 34)
i = 33;I've got absolutely no freakin' idea what the guy was trying to do there, but I can tell you all that if there was a competition for coding horror, this candidate would have had absolutely no rival! :rolleyes: :rolleyes: :rolleyes:
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.
For me, the Problem here is not the if, but the arcane magic in those numbers. Why exactly 13? And what makes 20 different from 21?
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
George Orwell, "Keep the Aspidistra Flying", Opening words -
For me, the Problem here is not the if, but the arcane magic in those numbers. Why exactly 13? And what makes 20 different from 21?
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
George Orwell, "Keep the Aspidistra Flying", Opening wordsAh! I had to give the thread a title. As you said, there's nothing to do with the number of if conditions there. The WTF in the code is that the coder did not know of the term called "decrement operator"
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.
-
Ah! I had to give the thread a title. As you said, there's nothing to do with the number of if conditions there. The WTF in the code is that the coder did not know of the term called "decrement operator"
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.
brahmma wrote:
The WTF in the code is that the coder did not know of the term called "decrement operator"
Well - how would that (or the use of the inverse logic proposed by leppie make things any clearer?
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
George Orwell, "Keep the Aspidistra Flying", Opening words -
Ah! I had to give the thread a title. As you said, there's nothing to do with the number of if conditions there. The WTF in the code is that the coder did not know of the term called "decrement operator"
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.
-
Indeed, one if is better. Also revert logic and set ++i; at the end of the code. This gives another performance boost.
codito ergo sum
This is a piece of code that I got to see from a project that has come to us for porting it to .NET. Nobody from our company is "technically challenged" enough to write something like that. :)
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.
-
That isn't our company code! Just see how many WTFs are there apparently within a few lines of code.
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.
-
This is a s/w that deals with a list of human interface devices. There are two APIs, namely
getPortCount(DWORD devID)
andgetNextPort(DWORD devID)
(from the docs that we got), that would assist you in the very range check that you're talking about. Clearly, the dumbass guy who wrote it did not bother to open the docs. That solved, there's a new WTF. The next issue listed is that the app crashes on 64 bit machines. I can read it in the docs that these numbers, which were hard coded in the original code WILL vary on a 64 bit machine! :rolleyes:
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.
-
I don't think this is correct if you or 12 with 19you get 31 all of them give you 63 this means that (i & (12|19|26|33)) == (i & (63)) and that will be true for 63 and for 177 and for 191 and so on ... The following should be correct
if(!( i==12 || i==29 || i==26 || i==33)) ++i;
codito ergo sum
Yeah you right, im kinda brain dead at the moment :p
**
xacc.ide-0.2.0.77 - now with C# 3.5 support and Navigation Bar!^
New xacc.ide release RSS feed^**
-
For me, the Problem here is not the if, but the arcane magic in those numbers. Why exactly 13? And what makes 20 different from 21?
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
George Orwell, "Keep the Aspidistra Flying", Opening wordsjhwurmbach wrote:
And what makes 20 different from 21?
Makes a big difference in BlackJack :)
**
xacc.ide-0.2.0.77 - now with C# 3.5 support and Navigation Bar!^
New xacc.ide release RSS feed^**
-
Yeah you right, im kinda brain dead at the moment :p
**
xacc.ide-0.2.0.77 - now with C# 3.5 support and Navigation Bar!^
New xacc.ide release RSS feed^**
leppie wrote:
at the moment
Only at this moment ? :~
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.
-
i++;
if (i == 13)
i = 12;
if (i == 20)
i = 19;
if (i == 27)
i = 26;
if (i == 34)
i = 33;I've got absolutely no freakin' idea what the guy was trying to do there, but I can tell you all that if there was a competition for coding horror, this candidate would have had absolutely no rival! :rolleyes: :rolleyes: :rolleyes:
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.
brahmma wrote:
I've got absolutely no freakin' idea what the guy was trying to do there
Out of context it is impossible to guess, but over a limited range the code (rather clumsily) does
if (i%7 == 6) i--;
Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
-
i++;
if (i == 13)
i = 12;
if (i == 20)
i = 19;
if (i == 27)
i = 26;
if (i == 34)
i = 33;I've got absolutely no freakin' idea what the guy was trying to do there, but I can tell you all that if there was a competition for coding horror, this candidate would have had absolutely no rival! :rolleyes: :rolleyes: :rolleyes:
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.
-
This is a s/w that deals with a list of human interface devices. There are two APIs, namely
getPortCount(DWORD devID)
andgetNextPort(DWORD devID)
(from the docs that we got), that would assist you in the very range check that you're talking about. Clearly, the dumbass guy who wrote it did not bother to open the docs. That solved, there's a new WTF. The next issue listed is that the app crashes on 64 bit machines. I can read it in the docs that these numbers, which were hard coded in the original code WILL vary on a 64 bit machine! :rolleyes:
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.
-
Ah! I had to give the thread a title. As you said, there's nothing to do with the number of if conditions there. The WTF in the code is that the coder did not know of the term called "decrement operator"
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.
brahmma wrote:
the coder did not know of the term called "decrement operator"
I am reminded of Abhimanyu's story (http://en.wikipedia.org/wiki/Abhimanyu[^]) This guy knew one part of story of incrementing the variable but not the other part of decrementing it. :-D
Vasudevan Deepak Kumar Personal Homepage Tech Gossips
-
i++;
if (i == 13)
i = 12;
if (i == 20)
i = 19;
if (i == 27)
i = 26;
if (i == 34)
i = 33;I've got absolutely no freakin' idea what the guy was trying to do there, but I can tell you all that if there was a competition for coding horror, this candidate would have had absolutely no rival! :rolleyes: :rolleyes: :rolleyes:
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.
I've sussed it. This is a candidate for when the guy is optimising the code. Imagine the scene. A manager is whining about how long the code takes to run, and this guy says that he'll optimize the code and he spends 10 seconds removing the code and the next 20 days surfing dodgy sites. 20 days later he runs the application and it runs faster without the useless code. Result - he gets a glowing review and a hefty pay rise for removing this steaming pile of crap (hey a new acronym, SPOC). Obviously this guy doesn't use CodeProject because, God forbid, no developer on this site would ever produce code as awful as this.;P
Deja View - the feeling that you've seen this post before.
-
brahmma wrote:
I've got absolutely no freakin' idea what the guy was trying to do there
Out of context it is impossible to guess, but over a limited range the code (rather clumsily) does
if (i%7 == 6) i--;
Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
-
leppie wrote:
at the moment
Only at this moment ? :~
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.
Not bad coding
Regards Bino http://www.technix.co.nr
-
i++;
if (i == 13)
i = 12;
if (i == 20)
i = 19;
if (i == 27)
i = 26;
if (i == 34)
i = 33;I've got absolutely no freakin' idea what the guy was trying to do there, but I can tell you all that if there was a competition for coding horror, this candidate would have had absolutely no rival! :rolleyes: :rolleyes: :rolleyes:
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.