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.
  • L leppie

    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^

    **

    B Offline
    B Offline
    BadKarma
    wrote on last edited by
    #4

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

      J Offline
      J Offline
      jhwurmbach
      wrote on last edited by
      #5

      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

      R L P 3 Replies 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

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

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

        J B V 3 Replies 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Ã<-·´¯`·.

          J Offline
          J Offline
          jhwurmbach
          wrote on last edited by
          #7

          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

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

            B Offline
            B Offline
            BadKarma
            wrote on last edited by
            #8

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

            codito ergo sum

            R E 2 Replies Last reply
            0
            • 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
                                          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