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. just curious

just curious

Scheduled Pinned Locked Moved The Lounge
helpquestionphpcsstutorial
20 Posts 12 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 James Pullicino

    A good compiler will issue a warning telling you that you may have used assignment instead of comparison. Therefore I think that the style you mentioned makes code unreadable and is not worth it. Drinking In The Sun Forgot Password?

    M Offline
    M Offline
    Maxwell Chen
    wrote on last edited by
    #8

    Visual C++ .NET 2002 doesn't warn unless Warning Level-4 is set. Maxwell Chen

    1 Reply Last reply
    0
    • A alex barylski

      How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? It was just a while back while reading a PHP article the author suggests ALWAYS using a fixed number/value (if you can) then the == operator then another variable or fixed value so instead of:

      if(a==2)

      you get:

      if(2==a)

      Remembering to always use this method when using == will prevent you from ever making and assignment error, becuz obviously the complier catches 2=a as an invalid assignment, whereas 2==a is cool. Personally I can honeslty say i've never made that mistake yet...it was one of the first things I read when I was learning how to program...becareful with assigment and equality operators...and I always have been since then...however I still want to try and get into the habit o fusing this technique...just becuz it's one less bug to ever have to worry about...which is great news, cuz I hate getting stuck for more then 10 mins on a bug. Anyways, just curious...how many of you actually have made that mistake before...??? How do I print my voice mail?

      H Offline
      H Offline
      Hans Dietrich
      wrote on last edited by
      #9

      Set the warning level to 4 and you will always get a warning.

      A 1 Reply Last reply
      0
      • J James Pullicino

        A good compiler will issue a warning telling you that you may have used assignment instead of comparison. Therefore I think that the style you mentioned makes code unreadable and is not worth it. Drinking In The Sun Forgot Password?

        A Offline
        A Offline
        alex barylski
        wrote on last edited by
        #10

        [James Pullicino] wrote: Therefore I think that the style you mentioned makes code unreadable and is not worth it. Visual C++ 6 doesn't....or atleast mine... :) For interpreted languages like PHP it makes sense...i'm just not accustomed to reading code that way... How do I print my voice mail?

        M 1 Reply Last reply
        0
        • H Hans Dietrich

          Set the warning level to 4 and you will always get a warning.

          A Offline
          A Offline
          alex barylski
          wrote on last edited by
          #11

          Ahhh...is that how you do it... :) Cooly i'll try that... How do I print my voice mail?

          1 Reply Last reply
          0
          • A alex barylski

            [James Pullicino] wrote: Therefore I think that the style you mentioned makes code unreadable and is not worth it. Visual C++ 6 doesn't....or atleast mine... :) For interpreted languages like PHP it makes sense...i'm just not accustomed to reading code that way... How do I print my voice mail?

            M Offline
            M Offline
            Maxwell Chen
            wrote on last edited by
            #12

            Hockey wrote: Visual C++ 6 doesn't....or atleast mine... You need Warning Level-4 turned on in VC++6 project setting. Maxwell Chen

            1 Reply Last reply
            0
            • M Maxwell Chen

              Actually there is such feature in C++, see page 829 in Appendix C in the book "The C++ Programming Language, 3rd", except operator==. We can write our C++ code this way by turning on /Za.

              bool bFlag = false;
              if(not bFlag) { /* Do something... */ }

              Regarding to the *missing* alternative keyword, we may define this

              #define equal ==

              for

              if(bFlag equal true) { }

              Maxwell Chen

              J Offline
              J Offline
              Jeff Varszegi
              wrote on last edited by
              #13

              This is the best solution, IMHO. Regards, Jeff Varszegi EEEP!  An Extensible Expression Evaluation Package

              1 Reply Last reply
              0
              • A alex barylski

                How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? It was just a while back while reading a PHP article the author suggests ALWAYS using a fixed number/value (if you can) then the == operator then another variable or fixed value so instead of:

                if(a==2)

                you get:

                if(2==a)

                Remembering to always use this method when using == will prevent you from ever making and assignment error, becuz obviously the complier catches 2=a as an invalid assignment, whereas 2==a is cool. Personally I can honeslty say i've never made that mistake yet...it was one of the first things I read when I was learning how to program...becareful with assigment and equality operators...and I always have been since then...however I still want to try and get into the habit o fusing this technique...just becuz it's one less bug to ever have to worry about...which is great news, cuz I hate getting stuck for more then 10 mins on a bug. Anyways, just curious...how many of you actually have made that mistake before...??? How do I print my voice mail?

                D Offline
                D Offline
                David Wulff
                wrote on last edited by
                #14

                Very occasionally if I haven't had enough coke in the mornings I'll slip one of those in, but the compiler warns me about a possible mistake and lets me fix it before it gets anywhere. Like Jeff, my causing problem is not registering two key presses successfully - my brain works faster than my fingers!


                David Wulff The Royal Woofle Museum

                Putting the laughter back into slaughter

                1 Reply Last reply
                0
                • A alex barylski

                  How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? It was just a while back while reading a PHP article the author suggests ALWAYS using a fixed number/value (if you can) then the == operator then another variable or fixed value so instead of:

                  if(a==2)

                  you get:

                  if(2==a)

                  Remembering to always use this method when using == will prevent you from ever making and assignment error, becuz obviously the complier catches 2=a as an invalid assignment, whereas 2==a is cool. Personally I can honeslty say i've never made that mistake yet...it was one of the first things I read when I was learning how to program...becareful with assigment and equality operators...and I always have been since then...however I still want to try and get into the habit o fusing this technique...just becuz it's one less bug to ever have to worry about...which is great news, cuz I hate getting stuck for more then 10 mins on a bug. Anyways, just curious...how many of you actually have made that mistake before...??? How do I print my voice mail?

                  P Offline
                  P Offline
                  ProffK
                  wrote on last edited by
                  #15

                  Coming from a VB background, I have never made that mistake since my third year C++ COS module, but now I work in C#, and nearly always use the constant first format. The funny thing is, on Friday just after I explained its use to my colleague, I found one such error in a piece of my code which I had too hastily added. Fortunately I spotted in even before compiling, but it did make me slow down a bit. After all, this was code calling the RegistryKey.DeleteSubKeyTree method. My blog.

                  1 Reply Last reply
                  0
                  • A alex barylski

                    How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? It was just a while back while reading a PHP article the author suggests ALWAYS using a fixed number/value (if you can) then the == operator then another variable or fixed value so instead of:

                    if(a==2)

                    you get:

                    if(2==a)

                    Remembering to always use this method when using == will prevent you from ever making and assignment error, becuz obviously the complier catches 2=a as an invalid assignment, whereas 2==a is cool. Personally I can honeslty say i've never made that mistake yet...it was one of the first things I read when I was learning how to program...becareful with assigment and equality operators...and I always have been since then...however I still want to try and get into the habit o fusing this technique...just becuz it's one less bug to ever have to worry about...which is great news, cuz I hate getting stuck for more then 10 mins on a bug. Anyways, just curious...how many of you actually have made that mistake before...??? How do I print my voice mail?

                    C Offline
                    C Offline
                    Chris Losinger
                    wrote on last edited by
                    #16

                    Hockey wrote: How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? i have. and, i can't stand putting the const on the left because i sometimes like to use the old C-style trick of doing an assignment inside a conditional test:

                    if ((res = testSomething(foo)) == 100)
                    {
                    // alert the authorities
                    }

                    Cleek | Losinger Designs | ClickPic | ThumbNailer

                    1 Reply Last reply
                    0
                    • A alex barylski

                      How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? It was just a while back while reading a PHP article the author suggests ALWAYS using a fixed number/value (if you can) then the == operator then another variable or fixed value so instead of:

                      if(a==2)

                      you get:

                      if(2==a)

                      Remembering to always use this method when using == will prevent you from ever making and assignment error, becuz obviously the complier catches 2=a as an invalid assignment, whereas 2==a is cool. Personally I can honeslty say i've never made that mistake yet...it was one of the first things I read when I was learning how to program...becareful with assigment and equality operators...and I always have been since then...however I still want to try and get into the habit o fusing this technique...just becuz it's one less bug to ever have to worry about...which is great news, cuz I hate getting stuck for more then 10 mins on a bug. Anyways, just curious...how many of you actually have made that mistake before...??? How do I print my voice mail?

                      C Offline
                      C Offline
                      Chris Maunder
                      wrote on last edited by
                      #17

                      Hockey wrote: How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? Not once since I started working in C# :P (yeah, yeah - I know the new compiler will trap this potential error but I felt the need to spout some MS kool-aid this morning ;)) cheers, Chris Maunder

                      1 Reply Last reply
                      0
                      • A alex barylski

                        How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? It was just a while back while reading a PHP article the author suggests ALWAYS using a fixed number/value (if you can) then the == operator then another variable or fixed value so instead of:

                        if(a==2)

                        you get:

                        if(2==a)

                        Remembering to always use this method when using == will prevent you from ever making and assignment error, becuz obviously the complier catches 2=a as an invalid assignment, whereas 2==a is cool. Personally I can honeslty say i've never made that mistake yet...it was one of the first things I read when I was learning how to program...becareful with assigment and equality operators...and I always have been since then...however I still want to try and get into the habit o fusing this technique...just becuz it's one less bug to ever have to worry about...which is great news, cuz I hate getting stuck for more then 10 mins on a bug. Anyways, just curious...how many of you actually have made that mistake before...??? How do I print my voice mail?

                        T Offline
                        T Offline
                        Tim Smith
                        wrote on last edited by
                        #18

                        The question is how many times have people made this mistake and never caught it. Tim Smith I'm going to patent thought. I have yet to see any prior art.

                        1 Reply Last reply
                        0
                        • A alex barylski

                          How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? It was just a while back while reading a PHP article the author suggests ALWAYS using a fixed number/value (if you can) then the == operator then another variable or fixed value so instead of:

                          if(a==2)

                          you get:

                          if(2==a)

                          Remembering to always use this method when using == will prevent you from ever making and assignment error, becuz obviously the complier catches 2=a as an invalid assignment, whereas 2==a is cool. Personally I can honeslty say i've never made that mistake yet...it was one of the first things I read when I was learning how to program...becareful with assigment and equality operators...and I always have been since then...however I still want to try and get into the habit o fusing this technique...just becuz it's one less bug to ever have to worry about...which is great news, cuz I hate getting stuck for more then 10 mins on a bug. Anyways, just curious...how many of you actually have made that mistake before...??? How do I print my voice mail?

                          W Offline
                          W Offline
                          wrykyn
                          wrote on last edited by
                          #19

                          I do it very very often but I almost always catch myself when im closing the braces ) :) I read about 2==a in Deitel a few years back but don't like it since I like to execute something inside my condition and then check if it's equal ot something. " Why oh why didn't I take the blue pill ? "

                          1 Reply Last reply
                          0
                          • A alex barylski

                            How many people actually have had a bug in their code caused by an incorrect assignment; = instead of ==??? It was just a while back while reading a PHP article the author suggests ALWAYS using a fixed number/value (if you can) then the == operator then another variable or fixed value so instead of:

                            if(a==2)

                            you get:

                            if(2==a)

                            Remembering to always use this method when using == will prevent you from ever making and assignment error, becuz obviously the complier catches 2=a as an invalid assignment, whereas 2==a is cool. Personally I can honeslty say i've never made that mistake yet...it was one of the first things I read when I was learning how to program...becareful with assigment and equality operators...and I always have been since then...however I still want to try and get into the habit o fusing this technique...just becuz it's one less bug to ever have to worry about...which is great news, cuz I hate getting stuck for more then 10 mins on a bug. Anyways, just curious...how many of you actually have made that mistake before...??? How do I print my voice mail?

                            T Offline
                            T Offline
                            Terry ONolley
                            wrote on last edited by
                            #20

                            That sounds so simple! It just feels so weird to write it like that. I guess my ingrained habits are going to cost me time spent debugging (because yes - I have had these bugs).


                            Glano perictu com sahni delorin!

                            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