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. Clever Code
  4. Another 2:00am one

Another 2:00am one

Scheduled Pinned Locked Moved Clever Code
comtoolsquestion
9 Posts 7 Posters 2 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.
  • R Offline
    R Offline
    Ravi Bhavnani
    wrote on last edited by
    #1

    if (x == y);
    doSomething();
    doSomethingElse();

    Although I suspect pre VS2005 will also draw your attention to this one. /ravi

    My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

    N 1 Reply Last reply
    0
    • R Ravi Bhavnani

      if (x == y);
      doSomething();
      doSomethingElse();

      Although I suspect pre VS2005 will also draw your attention to this one. /ravi

      My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      That's caught by most compilers. But this one won't be :-

      if (x == y)
      doSomethingPart1();
      doSomethingPart2();
      . . .

      when you meant to do

      if (x == y)
      {
      doSomethingPart1();
      doSomethingPart2();
      }
      . . .

      Regards, Nish


      Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
      Currently working on C++/CLI in Action for Manning Publications. Also visit the Ultimate Toolbox blog

      C 1 Reply Last reply
      0
      • N Nish Nishant

        That's caught by most compilers. But this one won't be :-

        if (x == y)
        doSomethingPart1();
        doSomethingPart2();
        . . .

        when you meant to do

        if (x == y)
        {
        doSomethingPart1();
        doSomethingPart2();
        }
        . . .

        Regards, Nish


        Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
        Currently working on C++/CLI in Action for Manning Publications. Also visit the Ultimate Toolbox blog

        C Offline
        C Offline
        Cees Meijer
        wrote on last edited by
        #3

        That's why you ALWAYS, ALWAYS should enclose the statement (even a single one) in braces. Even if omit them because you're 100% sure that only one statement is required in the if() or else body, it will bite you somewhere in the future (Sure, 100%...)

        Cees Meijer Software / Hardware Engineer QMetrix BV Specialists in River and Sea flow measurements.

        N E 2 Replies Last reply
        0
        • C Cees Meijer

          That's why you ALWAYS, ALWAYS should enclose the statement (even a single one) in braces. Even if omit them because you're 100% sure that only one statement is required in the if() or else body, it will bite you somewhere in the future (Sure, 100%...)

          Cees Meijer Software / Hardware Engineer QMetrix BV Specialists in River and Sea flow measurements.

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #4

          Cees Meijer wrote:

          That's why you ALWAYS, ALWAYS should enclose the statement (even a single one) in braces. Even if omit them because you're 100% sure that only one statement is required in the if() or else body, it will bite you somewhere in the future (Sure, 100%...)

          Yep, I always use braces even if it's just one statement. The code looks cleaner too.

          Regards, Nish


          Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
          Currently working on C++/CLI in Action for Manning Publications. Also visit the Ultimate Toolbox blog

          P 1 Reply Last reply
          0
          • N Nish Nishant

            Cees Meijer wrote:

            That's why you ALWAYS, ALWAYS should enclose the statement (even a single one) in braces. Even if omit them because you're 100% sure that only one statement is required in the if() or else body, it will bite you somewhere in the future (Sure, 100%...)

            Yep, I always use braces even if it's just one statement. The code looks cleaner too.

            Regards, Nish


            Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
            Currently working on C++/CLI in Action for Manning Publications. Also visit the Ultimate Toolbox blog

            P Offline
            P Offline
            PJ Arends
            wrote on last edited by
            #5

            ditto


            You may be right
            I may be crazy
            -- Billy Joel --

            Within you lies the power for good, use it!!!

            G 1 Reply Last reply
            0
            • P PJ Arends

              ditto


              You may be right
              I may be crazy
              -- Billy Joel --

              Within you lies the power for good, use it!!!

              G Offline
              G Offline
              Guffa
              wrote on last edited by
              #6

              ditto

              --- b { font-weight: normal; }

              J 1 Reply Last reply
              0
              • G Guffa

                ditto

                --- b { font-weight: normal; }

                J Offline
                J Offline
                Jon Rista
                wrote on last edited by
                #7

                ditto...except in the case of throws ;) if (errorcase) throw blahblah;

                G 1 Reply Last reply
                0
                • J Jon Rista

                  ditto...except in the case of throws ;) if (errorcase) throw blahblah;

                  G Offline
                  G Offline
                  Guffa
                  wrote on last edited by
                  #8

                  Why? I would definietly write that as: if (errorcase) { throw blahblah; }

                  --- b { font-weight: normal; }

                  1 Reply Last reply
                  0
                  • C Cees Meijer

                    That's why you ALWAYS, ALWAYS should enclose the statement (even a single one) in braces. Even if omit them because you're 100% sure that only one statement is required in the if() or else body, it will bite you somewhere in the future (Sure, 100%...)

                    Cees Meijer Software / Hardware Engineer QMetrix BV Specialists in River and Sea flow measurements.

                    E Offline
                    E Offline
                    Egon_Freeman
                    wrote on last edited by
                    #9

                    Cees Meijer wrote:

                    it will bite you somewhere in the future (Sure, 100%...)

                    Yeah, especialy when you forget about it and add more to it. :/ You're lucky if there was an ELSE (the compiler should spit out an error about ELSE without an IF statement)...

                    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