Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. if if if if if if

if if if if if if

Scheduled Pinned Locked Moved The Weird and The Wonderful
37 Posts 17 Posters 308 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B BadKarma

    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

    R Offline
    R Offline
    Rajesh R Subramanian
    wrote on last edited by
    #9

    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Ã<-·´¯`·.

    1 Reply Last reply
    0
    • B BadKarma

      Why decrement if you don't have to increment in the first place ?

      codito ergo sum

      R Offline
      R Offline
      Rajesh R Subramanian
      wrote on last edited by
      #10

      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Ã<-·´¯`·.

      1 Reply Last reply
      0
      • B BadKarma

        Why decrement if you don't have to increment in the first place ?

        codito ergo sum

        E Offline
        E Offline
        Ed Poore
        wrote on last edited by
        #11

        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.


        My Blog[^]

        R 1 Reply Last reply
        0
        • E Ed Poore

          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.


          My Blog[^]

          R Offline
          R Offline
          Rajesh R Subramanian
          wrote on last edited by
          #12

          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! :rolleyes:


          Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.

          E 1 Reply Last reply
          0
          • B BadKarma

            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

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #13

            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^

            **

            R 1 Reply Last reply
            0
            • J jhwurmbach

              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

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #14

              jhwurmbach 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^

              **

              1 Reply Last reply
              0
              • L leppie

                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^

                **

                R Offline
                R Offline
                Rajesh R Subramanian
                wrote on last edited by
                #15

                leppie wrote:

                at the moment

                Only at this moment ? :~


                Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.

                B 1 Reply Last reply
                0
                • R Rajesh R Subramanian

                  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Ã<-·´¯`·.

                  C Offline
                  C Offline
                  cp9876
                  wrote on last edited by
                  #16

                  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."

                  L R 2 Replies Last reply
                  0
                  • R Rajesh R Subramanian

                    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Ã<-·´¯`·.

                    K Offline
                    K Offline
                    KarstenK
                    wrote on last edited by
                    #17

                    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

                    R 1 Reply Last reply
                    0
                    • R Rajesh R Subramanian

                      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! :rolleyes:


                      Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.

                      E Offline
                      E Offline
                      Ed Poore
                      wrote on last edited by
                      #18

                      brahmma wrote:

                      app crashes on 64 bit machines.

                      You mean there are apps that don't! :wtf: (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.


                      My Blog[^]

                      1 Reply Last reply
                      0
                      • R Rajesh R Subramanian

                        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Ã<-·´¯`·.

                        V Offline
                        V Offline
                        Vasudevan Deepak Kumar
                        wrote on last edited by
                        #19

                        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

                        R P M 3 Replies Last reply
                        0
                        • R Rajesh R Subramanian

                          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Ã<-·´¯`·.

                          P Offline
                          P Offline
                          Pete OHanlon
                          wrote on last edited by
                          #20

                          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.

                          R 1 Reply Last reply
                          0
                          • C cp9876

                            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."

                            L Offline
                            L Offline
                            Llasus
                            wrote on last edited by
                            #21

                            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! :)

                            1 Reply Last reply
                            0
                            • R Rajesh R Subramanian

                              leppie wrote:

                              at the moment

                              Only at this moment ? :~


                              Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.

                              B Offline
                              B Offline
                              Bino B
                              wrote on last edited by
                              #22

                              Not bad coding

                              Regards Bino http://www.technix.co.nr

                              1 Reply Last reply
                              0
                              • R Rajesh R Subramanian

                                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Ã<-·´¯`·.

                                M Offline
                                M Offline
                                mimante
                                wrote on last edited by
                                #23

                                !!!!! :confused:

                                1 Reply Last reply
                                0
                                • K KarstenK

                                  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

                                  R Offline
                                  R Offline
                                  Rajesh R Subramanian
                                  wrote on last edited by
                                  #24

                                  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 :rolleyes:

                                  K 1 Reply Last reply
                                  0
                                  • C cp9876

                                    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."

                                    R Offline
                                    R Offline
                                    Rajesh R Subramanian
                                    wrote on last edited by
                                    #25

                                    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!

                                    C 1 Reply Last reply
                                    0
                                    • P Pete OHanlon

                                      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.

                                      R Offline
                                      R Offline
                                      Rajesh R Subramanian
                                      wrote on last edited by
                                      #26

                                      Pete O'Hanlon wrote:

                                      Obviously this guy doesn't use CodeProject because, God forbid, no developer on this site would ever produce code as awful as this.;P

                                      Holy crap! Finally someone could feel everything that I felt about that "developer" guy. :-D [EDIT] It's amazing how this guy managed to make me say so many WTFs with his merely five or six lines of code. I can't believe so many people were bothered only about the number of if conditions in it and not anything beyond that. Probably the title I gave the thread contributed to it.[/EDIT]   -- modified at 5:48 Wednesday 12th September, 2007


                                      Last modified: 55mins after originally posted --


                                      Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.

                                      1 Reply Last reply
                                      0
                                      • R Rajesh R Subramanian

                                        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 :rolleyes:

                                        K Offline
                                        K Offline
                                        KarstenK
                                        wrote on last edited by
                                        #27

                                        I would expect that he has to learn so much, so he better should write the documentation (manual) not the source code.:mad:

                                        Greetings from Germany

                                        R 1 Reply Last reply
                                        0
                                        • K KarstenK

                                          I would expect that he has to learn so much, so he better should write the documentation (manual) not the source code.:mad:

                                          Greetings from Germany

                                          R Offline
                                          R Offline
                                          Rajesh R Subramanian
                                          wrote on last edited by
                                          #28

                                          :laugh:


                                          Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups