|
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."
|
|
|
|
|
it has a range though.. so i == 6 should not be included. maybe put all the special values in an array then check it with a loop. though the code in the first place looked bad. he/she should practice putting some comments!
|
|
|
|
|
You can't just go about it like that. Those numbers will vary from device to device (the app deals with more than one HID). Most importantly, these values will change for all the devices on a 64 bit computer!
|
|
|
|
|
With the context you gave us it was by no means anything other than clumsy code. I just pointed out one mathematical interpretation of the code - you don't like it - fine - but unless you share the context with us, it just looks like clumsy code to me.
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."
|
|
|
|
|
Really sorry about that. I explained the context of it later after creating the thread.
Link[^]
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->ßRÅhmmÃ<-·´¯`·.
|
|
|
|
|
I would use an "else if" to make it clear. Did the guy not knowing about enums or switch.
or:
if( i !=13 && ....)
i++;
I wont see other source code like this... it is often only the top of an icecube
Greetings from Germany
|
|
|
|
|
KarstenK wrote: Did the guy not knowing about enums or switch.
Well, what would you expect something from a guy who has hardcoded the port numbers
|
|
|
|
|
I would expect that he has to learn so much, so he better should write the documentation (manual) not the source code.
Greetings from Germany
|
|
|
|