|
|
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Ã<-·´¯`·.
|
|
|
|
|
if (!(i & (12|19|26|33))) i++;
|
|
|
|
|
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
<code>if(!( i==12 || i==29 || i==26 || i==33)) ++i;</code>
codito ergo sum
|
|
|
|
|
Yeah you right, im kinda brain dead at the moment :p
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
Why decrement if you don't have to increment in the first place ?
codito ergo sum
|
|
|
|
|
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Ã<-·´¯`·.
|
|
|
|
|
Maybe it's only for those numbers that it should be decremented again, in which case a simple range check would suffice rather than what was provided.
|
|
|
|
|
This is a s/w that deals with a list of human interface devices. There are two APIs, namely getPortCount(DWORD devID) and getNextPort(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!
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->ßRÅhmmÃ<-·´¯`·.
|
|
|
|
|
brahmma wrote: app crashes on 64 bit machines.
You mean there are apps that don't!
(Sorry been installing Vista Ultimate (x64) onto a machine and had fun finding drivers for it. Although everything is working (amazingly) but then most of the hardware is only a few months old.
|
|
|
|
|
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.
|
|
|
|
|
Naah!!! You shouldn't be comparing this idiot guy with Abhimanyu.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->ßRÅhmmÃ<-·´¯`·.
|
|
|
|
|
Now I'm reminded of a Mad Magazine (or possibly Caldwell) cartoon from the '70s. Moses; having parted the Red Sea and the Hebrews having crossed, the last guy through says, "OK you can close it up now", and Moses is thinking, "Close it up?"
-- modified at 13:01 Wednesday 12th September, 2007
|
|
|
|
|
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
From five ifs to Moses, that's a stretch.
BTW: Microsoft had not yet invented Dispose() at that time
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
A classical reference... Cool!
|
|
|
|
|
jhwurmbach wrote: And what makes 20 different from 21?
Makes a big difference in BlackJack
|
|
|
|
|
The arcane magic of business logic.
|
|
|
|
|
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."
|
|
|
|