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. The Lounge
  3. == vs =

== vs =

Scheduled Pinned Locked Moved The Lounge
c++visual-studiohelp
46 Posts 23 Posters 0 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.
  • J Jim Crafton

    Don't feel too bad. A few companies ago, I was working on my code, and it kept crashing. The company was a startup, so we were under the gun, naturally, with an impossible deadline to meet. Needless to say, I'm banging my head against the wall trying to find what I did wrong, and not getting anywhere. Fast forward 3 hours later, it's 2:30 AM and I'm in the debugger, deep in the code of one of the other guy's in the company (the lead app coder/engineer/wank/whatever) code, that integrates with mine. Turns out he had written:

    if ( id == id ) {
    //do some stuff
    }
    else {
    //do some other REALLY, REALLY important stuff
    //that should have been flagged in his own testing,
    //if the retard had ever bothered to do so in the
    //first place!!!!
    }

    So 2:30 AM, I can't actually fix the problem, but I have now wasted ALL my evening and productivity chasing down someone elses lazy coding (I say lazy because the nature of this particular logic error meant that his code NEVER worked right in the first place). Man was I pissed. This same guy, let's call him "Biff", drove so many of the other developers nuts, created so many software problems, that a few months later, we all got together and talked to the CTO. We basically said, either he goes or we all go. So the CTO makes an announcement the following day: Biff was offically promoted to Project Lead. :(( :(( :(( ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!

    V Offline
    V Offline
    Vikram A Punathambekar
    wrote on last edited by
    #27

    Jim Crafton wrote:

    Biff was offically promoted to Project Lead.

    I don't know whether I should laugh or cry at that. :suss: Either way, you have my sympathies. Cheers, Vikram.


    "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.

    1 Reply Last reply
    0
    • S Shog9 0

      I don't really see much of a difference, so i use it. What is it that you find unnatural? (now on the other hand, i absolutely hate "safe" code that looks like this: if((((a/b)+c)==(d))||(((a*c)+b)==(z))) - i can understand not being entirely clear on operator precedence, but at some point you'd hope they'd stop typing and read up on it)

      ---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums

      R Offline
      R Offline
      Ryan Binns
      wrote on last edited by
      #28

      Shog9 wrote:

      What is it that you find unnatural?

      Try saying it out aloud "if i equals 2" versus "if 2 equals i". Yes, semantically it means the same, but in natural speech, you always put the thing you're comparing first, and the standard you're comparing against second. I find code is a lot easier to understand if it reads nicely.

      Ryan

      "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

      S J 2 Replies Last reply
      0
      • M Marc Clifton

        That's nothing. Years ago, I spent half a day figuring out why this loop only exected one iteration:

        for (int i=0; i<10; i++);
        {
        ... do something
        }

        BTW, isn't there a compiler warning for "are you sure you want to do an assignment here? Is your warning level set to the highest level? Marc Pensieve

        J Offline
        J Offline
        Jerry Hammond
        wrote on last edited by
        #29

        Marc Clifton wrote:

        for (int i=0; i<10; i++); { ... do something }

        I know some of you aren't going to understand my glee at this, but I'm damn happy I understood the error of that function. Hell, as a self-taught coder it's always good to recognise progress in one's skills. *self-gloat**self-gloat**self-gloat* My Programming Library

        A 1 Reply Last reply
        0
        • R Ryan Binns

          Shog9 wrote:

          What is it that you find unnatural?

          Try saying it out aloud "if i equals 2" versus "if 2 equals i". Yes, semantically it means the same, but in natural speech, you always put the thing you're comparing first, and the standard you're comparing against second. I find code is a lot easier to understand if it reads nicely.

          Ryan

          "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

          S Offline
          S Offline
          Shog9 0
          wrote on last edited by
          #30

          Ryan Binns wrote:

          Yes, semantically it means the same, but in natural speech, you always put the thing you're comparing first, and the standard you're comparing against second.

          I see your point. :)

          ---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums

          1 Reply Last reply
          0
          • S Super Lloyd

            Bloody typical with C++ if you ask me. One more reason to love C# if you ask me, relevant and concise error and warning message !

            J Offline
            J Offline
            Jerry Hammond
            wrote on last edited by
            #31

            I don't know. I kind of like the "this function will blow up your machine" error message... My Programming Library

            1 Reply Last reply
            0
            • Richard Andrew x64R Richard Andrew x64

              I just spent an hour and a half debugging a problem in C++ that was caused by using the '=' instead of the '==' !! :mad: Uhg!

              O Offline
              O Offline
              Owner drawn
              wrote on last edited by
              #32

              I used to have this problem regularly. But these days they don't happen. I changed my coding a little bit...

              if(TRUE == IsTrue())
               //do something...
              

              Hence even if I miss out I get an error message...


              Owner drawn Jesus Loves

              1 Reply Last reply
              0
              • J Jerry Hammond

                Marc Clifton wrote:

                for (int i=0; i<10; i++); { ... do something }

                I know some of you aren't going to understand my glee at this, but I'm damn happy I understood the error of that function. Hell, as a self-taught coder it's always good to recognise progress in one's skills. *self-gloat**self-gloat**self-gloat* My Programming Library

                A Offline
                A Offline
                Aamir Butt
                wrote on last edited by
                #33

                OK you did it here but believe me, you cant do it while you are writing a lot of code. This happened to me once as well when another guy embarassed me by telling me the error I made and that was after about half an hour of head-scratching. You simply dont pay attention to this. "Writing specifications is like writing a novel. Writing code is like writing poetry."

                1 Reply Last reply
                0
                • J Jim Crafton

                  Don't feel too bad. A few companies ago, I was working on my code, and it kept crashing. The company was a startup, so we were under the gun, naturally, with an impossible deadline to meet. Needless to say, I'm banging my head against the wall trying to find what I did wrong, and not getting anywhere. Fast forward 3 hours later, it's 2:30 AM and I'm in the debugger, deep in the code of one of the other guy's in the company (the lead app coder/engineer/wank/whatever) code, that integrates with mine. Turns out he had written:

                  if ( id == id ) {
                  //do some stuff
                  }
                  else {
                  //do some other REALLY, REALLY important stuff
                  //that should have been flagged in his own testing,
                  //if the retard had ever bothered to do so in the
                  //first place!!!!
                  }

                  So 2:30 AM, I can't actually fix the problem, but I have now wasted ALL my evening and productivity chasing down someone elses lazy coding (I say lazy because the nature of this particular logic error meant that his code NEVER worked right in the first place). Man was I pissed. This same guy, let's call him "Biff", drove so many of the other developers nuts, created so many software problems, that a few months later, we all got together and talked to the CTO. We basically said, either he goes or we all go. So the CTO makes an announcement the following day: Biff was offically promoted to Project Lead. :(( :(( :(( ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!

                  A Offline
                  A Offline
                  AORD
                  wrote on last edited by
                  #34

                  That made me laugh so hard I had to print it out and stick it on my wall! Here come the machines!

                  1 Reply Last reply
                  0
                  • V Vikram A Punathambekar

                    Have you ever compared two constants? Cheers, Vikram.


                    "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.

                    J Offline
                    J Offline
                    Jorgen Sigvardsson
                    wrote on last edited by
                    #35

                    Yes, many times. Especially in tricky code generated SQL queries. :)

                    V 1 Reply Last reply
                    0
                    • G Gary R Wheeler

                      Well, at least I would write it as:

                      if((((a / b) + c) == d) ||
                      (((a * c) + b) == z))

                      I learned C back in the day when operator precedence enforcement was hit-or-miss in some compilers (yes, I'm that freakin' old). I was also programming in FORTRAN, Ada, and LISP at the time. It was just too bloody hard to remember the different rules for each language, so I learned to fully parenthesize. It could be worse. Here's an example of the coding style of one of my coworkers:

                      if (x == 2 || x == 6 && y > 5) for (int i = -1; i < 10; ++i)
                      InvokeMethod(i,x,y); else InvokeMethod2(x);

                      He avoids braces '{}' and parentheses whenever possible, and just strings everything together on one line like a sentence. He's also one of these object-oriented-out-the-wazoo types, who never puts more than four or five lines of code in a single function. His code is almost impossible to follow. The only saving grace is he does adhere to our naming conventions.


                      Software Zen: delete this;

                      Fold With Us![^]

                      J Offline
                      J Offline
                      Jorgen Sigvardsson
                      wrote on last edited by
                      #36

                      Gary R. Wheeler wrote:

                      He avoids braces '{}'

                      That's fine with me, but

                      if (x == 2 || x == 6 && y > 5) for (int i = -1; i < 10; ++i)
                      InvokeMethod(i,x,y); else InvokeMethod2(x);

                      that's just sick! That one just begs for misinterpretation!

                      G 1 Reply Last reply
                      0
                      • R Ryan Binns

                        Shog9 wrote:

                        What is it that you find unnatural?

                        Try saying it out aloud "if i equals 2" versus "if 2 equals i". Yes, semantically it means the same, but in natural speech, you always put the thing you're comparing first, and the standard you're comparing against second. I find code is a lot easier to understand if it reads nicely.

                        Ryan

                        "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                        J Offline
                        J Offline
                        Jorgen Sigvardsson
                        wrote on last edited by
                        #37

                        Is "if 2 is greater than i" just as unnatural? :~

                        R 1 Reply Last reply
                        0
                        • M Marc Clifton

                          Maximilien wrote:

                          set your compiler warning to "level 4"

                          1. I never understood why they even give you different warning levels as an option 2) I've never understood why people don't use the highest warning level possible. 3) STL. Oh yeah. Marc Pensieve
                          J Offline
                          J Offline
                          Jeremy Falcon
                          wrote on last edited by
                          #38

                          Marc Clifton wrote:

                          STL. Oh yeah.

                          LMAO! Jeremy Falcon

                          1 Reply Last reply
                          0
                          • J Jorgen Sigvardsson

                            Is "if 2 is greater than i" just as unnatural? :~

                            R Offline
                            R Offline
                            Ryan Binns
                            wrote on last edited by
                            #39

                            Jörgen Sigvardsson wrote:

                            Is "if 2 is greater than i" just as unnatural?

                            Yes, but perhaps only if you're a native english speaker. I could understand that other languages may naturally lean towards the other way.

                            Ryan

                            "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                            J 1 Reply Last reply
                            0
                            • R Ryan Binns

                              Jörgen Sigvardsson wrote:

                              Is "if 2 is greater than i" just as unnatural?

                              Yes, but perhaps only if you're a native english speaker. I could understand that other languages may naturally lean towards the other way.

                              Ryan

                              "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                              J Offline
                              J Offline
                              Jorgen Sigvardsson
                              wrote on last edited by
                              #40

                              But "if 2 is greater than 1" sounds natural, why doesn't the example above? :~

                              R 1 Reply Last reply
                              0
                              • J Jorgen Sigvardsson

                                But "if 2 is greater than 1" sounds natural, why doesn't the example above? :~

                                R Offline
                                R Offline
                                Ryan Binns
                                wrote on last edited by
                                #41

                                Jörgen Sigvardsson wrote:

                                But "if 2 is greater than 1" sounds natural, why doesn't the example above?

                                Because 'i' is not a literal constant - it's an unknown abstract object that you're comparing against a known reference. In the "if 2 is greater than 1" example, both items in the comparison are known constants, so it makes no difference which way around you put them.

                                Ryan

                                "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                                1 Reply Last reply
                                0
                                • J Jorgen Sigvardsson

                                  Gary R. Wheeler wrote:

                                  He avoids braces '{}'

                                  That's fine with me, but

                                  if (x == 2 || x == 6 && y > 5) for (int i = -1; i < 10; ++i)
                                  InvokeMethod(i,x,y); else InvokeMethod2(x);

                                  that's just sick! That one just begs for misinterpretation!

                                  G Offline
                                  G Offline
                                  Gary R Wheeler
                                  wrote on last edited by
                                  #42

                                  His position is that unnecessary braces and parentheses make it take longer to read his code, because you have to pause to locate the matching brace. He's not big on indentation, either. With his 'object-oriented' madness, his functions rarely include more than one if, for, or while construct. Fortunately for me, his stuff is in a separate part of the product that I don't have to debug into. I debug up to his interface, and then pass issues to him if necessary.


                                  Software Zen: delete this;

                                  Fold With Us![^]

                                  1 Reply Last reply
                                  0
                                  • J Jorgen Sigvardsson

                                    Yes, many times. Especially in tricky code generated SQL queries. :)

                                    V Offline
                                    V Offline
                                    Vikram A Punathambekar
                                    wrote on last edited by
                                    #43

                                    I don't know if you're kidding or not. :~ Why would you want to compare, say, 11 and 42? Cheers, Vikram.


                                    "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.

                                    J 1 Reply Last reply
                                    0
                                    • V Vikram A Punathambekar

                                      I don't know if you're kidding or not. :~ Why would you want to compare, say, 11 and 42? Cheers, Vikram.


                                      "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.

                                      J Offline
                                      J Offline
                                      Jorgen Sigvardsson
                                      wrote on last edited by
                                      #44

                                      If you do SQL queries from environments in which the support for it is rather bad, it is often easier to generate tautologies or contradictions, than it is to generate a whole different subexpression. It also allows for simpler query building code (less branches, etc). I've also seen it being used in clever joins, but I couldn't for my life recite how it helped in the join. (I honestly don't remember the queries, other than I noted the clever use of tautologies and contradictions :)) I've seen other uses for it as well, but I'm unsure why such logical tricks have been used. Could've been because of shortcomings in the SQL language. I generally shy away from SQL, because it really isn't my cup of tea (i.e., it's bloody boring!)

                                      1 Reply Last reply
                                      0
                                      • C code frog 0

                                        Troposphere wrote:

                                        I just spent an hour and a half debugging a problem in C++ that was caused by using the '=' instead of the '=='

                                        I love you! Apparently there are at least 2 mortals who come to this site on a regular basis. Stuff like that burns my butt when I catch myself at it.

                                        I only read CP for the articles. Code-frog System Architects, Inc.

                                        L Offline
                                        L Offline
                                        Lost User
                                        wrote on last edited by
                                        #45

                                        Cool, I'm immortal :laugh: The tigress is here :-D

                                        1 Reply Last reply
                                        0
                                        • J Jim Crafton

                                          Don't feel too bad. A few companies ago, I was working on my code, and it kept crashing. The company was a startup, so we were under the gun, naturally, with an impossible deadline to meet. Needless to say, I'm banging my head against the wall trying to find what I did wrong, and not getting anywhere. Fast forward 3 hours later, it's 2:30 AM and I'm in the debugger, deep in the code of one of the other guy's in the company (the lead app coder/engineer/wank/whatever) code, that integrates with mine. Turns out he had written:

                                          if ( id == id ) {
                                          //do some stuff
                                          }
                                          else {
                                          //do some other REALLY, REALLY important stuff
                                          //that should have been flagged in his own testing,
                                          //if the retard had ever bothered to do so in the
                                          //first place!!!!
                                          }

                                          So 2:30 AM, I can't actually fix the problem, but I have now wasted ALL my evening and productivity chasing down someone elses lazy coding (I say lazy because the nature of this particular logic error meant that his code NEVER worked right in the first place). Man was I pissed. This same guy, let's call him "Biff", drove so many of the other developers nuts, created so many software problems, that a few months later, we all got together and talked to the CTO. We basically said, either he goes or we all go. So the CTO makes an announcement the following day: Biff was offically promoted to Project Lead. :(( :(( :(( ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!

                                          J Offline
                                          J Offline
                                          Joe Woodbury
                                          wrote on last edited by
                                          #46

                                          Jim Crafton wrote:

                                          we all got together and talked to the CTO. We basically said, either he goes or we all go. So the CTO makes an announcement the following day

                                          Just had the exact opposite happen to me. After poking holes in their idiocy, including refusing to say a three to four year project would take a year, my fellow "teammates" made an ultimatim. It's a relief to get out, but.... Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

                                          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