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. if else standards...

if else standards...

Scheduled Pinned Locked Moved The Lounge
wpf
19 Posts 13 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.
  • B BrockVnm

    I was just wondering how everyone does there if else statments. I was looking online and I see alot of this: if (condition) // Comment { } else if (condition) // Comment { } else // Comment { } or this: if (condition) { statements; } else if (condition) { statements; } else { statements; } I dont know why but I just found myself doing the following.... if(condition){ statements; }else{ if(condition){ statements; } } I dont know how or why I started doing that but dont ever remember doing it. I was just wondering what kind of styles people use. Here at work they dont really tell you what kind of style to use and I see it done in all different ways. Thanks :-D


    There are 10 kinds of people in this world. Those who understand binary and those who don't. We shouldn't assume something's debugged just because everyone in the whole world has access to the source code.

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

    The first one. Brackets on the same line are just asking for trouble (ie missed/mismatched brackets) if you ask me. Whitespace is free. cheers, Chris Maunder

    J A B 3 Replies Last reply
    0
    • C Chris Maunder

      The first one. Brackets on the same line are just asking for trouble (ie missed/mismatched brackets) if you ask me. Whitespace is free. cheers, Chris Maunder

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

      Chris Maunder wrote: Whitespace is free. Screen estate isn't. :) Besides, now that VS.NET have caught up with early 90's [X]Emacs technology (matching brackets and smart indentation), mismatched crackets isn't that much of an issue as it was say 2 years ago. :) I am however missing the XEmacs feature "highlight expression". It highlights the expression under the cursor. So if the cursor is on the firs {, the editor would then change the background color on all text between the first { and the matching }. Now that's a killer feature, because it'll help you find mismatched stuff real easy. Why hasn't it been implemented I wonder? I doubt it's possible to hack it as a IDE script either, because I don't think it's possible to manipulate the color attributes of a specific text span. <desperate>Wasn't our friend Nick Hodapp a VS.NET manager kind of guy? Can you hear me Nick? Nick?! Nick!?!? I'm on me knees, begging you man! Please give me "highlight expression". Pretty please with sugar on top!</desperate> -- Oneigaishimasu! I blog too now[^]

      C Z 2 Replies Last reply
      0
      • B BrockVnm

        I was just wondering how everyone does there if else statments. I was looking online and I see alot of this: if (condition) // Comment { } else if (condition) // Comment { } else // Comment { } or this: if (condition) { statements; } else if (condition) { statements; } else { statements; } I dont know why but I just found myself doing the following.... if(condition){ statements; }else{ if(condition){ statements; } } I dont know how or why I started doing that but dont ever remember doing it. I was just wondering what kind of styles people use. Here at work they dont really tell you what kind of style to use and I see it done in all different ways. Thanks :-D


        There are 10 kinds of people in this world. Those who understand binary and those who don't. We shouldn't assume something's debugged just because everyone in the whole world has access to the source code.

        R Offline
        R Offline
        Ray Cassick
        wrote on last edited by
        #6

        I alweays use the first case.. one thign I hate it when people to this:

        if (condition)
        statement;
        else if (condition)
        statement;
        else
        statement;

        That just hacks me off...


        George Carlin wrote: "Don't sweat the petty things, and don't pet the sweaty things." Jörgen Sigvardsson wrote: If the physicists find a universal theory describing the laws of universe, I'm sure the asshole constant will be an integral part of that theory.
        My Blog[^]


        1 Reply Last reply
        0
        • B BrockVnm

          I was just wondering how everyone does there if else statments. I was looking online and I see alot of this: if (condition) // Comment { } else if (condition) // Comment { } else // Comment { } or this: if (condition) { statements; } else if (condition) { statements; } else { statements; } I dont know why but I just found myself doing the following.... if(condition){ statements; }else{ if(condition){ statements; } } I dont know how or why I started doing that but dont ever remember doing it. I was just wondering what kind of styles people use. Here at work they dont really tell you what kind of style to use and I see it done in all different ways. Thanks :-D


          There are 10 kinds of people in this world. Those who understand binary and those who don't. We shouldn't assume something's debugged just because everyone in the whole world has access to the source code.

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

          In VC,I perfet the first stytle. however, c or java, the second one is mostly used.

          1 Reply Last reply
          0
          • B BrockVnm

            I was just wondering how everyone does there if else statments. I was looking online and I see alot of this: if (condition) // Comment { } else if (condition) // Comment { } else // Comment { } or this: if (condition) { statements; } else if (condition) { statements; } else { statements; } I dont know why but I just found myself doing the following.... if(condition){ statements; }else{ if(condition){ statements; } } I dont know how or why I started doing that but dont ever remember doing it. I was just wondering what kind of styles people use. Here at work they dont really tell you what kind of style to use and I see it done in all different ways. Thanks :-D


            There are 10 kinds of people in this world. Those who understand binary and those who don't. We shouldn't assume something's debugged just because everyone in the whole world has access to the source code.

            J Offline
            J Offline
            Jim Crafton
            wrote on last edited by
            #8

            Actually I am surprised you missed one:

            if (condition) {
            statements;
            }
            else if (condition) {
            statements;
            }
            else {
            statements;
            }

            That's my personal preference. People who do the single line

            if (condition)
            statement
            else if (...)
            blah;

            should just be shot outright. it's such a pain to read and frequently debuggers won't show values correctly. Another pet peeve, as long as we are talking about single line nonsense is

            class Foo {
            public:
            int getVal() {return val_;}
            };

            Grrrr :mad: - what does it cost to put a line break in there!!! I know for a fact that VC6 will NOT allow you to properly inspect the val_ variable if you try and step into it, and won't let you do anything! But if it's written as

            class Foo {
            public:
            int getVal() {
            return val_;
            }
            };

            then everything is hunky-dory. ¡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!

            1 Reply Last reply
            0
            • J Jorgen Sigvardsson

              Chris Maunder wrote: Whitespace is free. Screen estate isn't. :) Besides, now that VS.NET have caught up with early 90's [X]Emacs technology (matching brackets and smart indentation), mismatched crackets isn't that much of an issue as it was say 2 years ago. :) I am however missing the XEmacs feature "highlight expression". It highlights the expression under the cursor. So if the cursor is on the firs {, the editor would then change the background color on all text between the first { and the matching }. Now that's a killer feature, because it'll help you find mismatched stuff real easy. Why hasn't it been implemented I wonder? I doubt it's possible to hack it as a IDE script either, because I don't think it's possible to manipulate the color attributes of a specific text span. <desperate>Wasn't our friend Nick Hodapp a VS.NET manager kind of guy? Can you hear me Nick? Nick?! Nick!?!? I'm on me knees, begging you man! Please give me "highlight expression". Pretty please with sugar on top!</desperate> -- Oneigaishimasu! I blog too now[^]

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

              Jörgen Sigvardsson wrote: Chris Maunder wrote: Whitespace is free. Screen estate isn't. There is no way I'm letting you get away that argument. If you're still using a 1024 x 768 monitor then we'll start a New Monitor for Jörgen Fund :) Jörgen Sigvardsson wrote: Wasn't our friend Nick Hodapp a VS.NET manager kind of guy? He was (past tense) Product Manager (ie Marketing person) for Visual C++. He could only wail and gnash his teeth at the Program Manager to get new features implements. He's since headed to greener pastures. cheers, Chris Maunder

              A J 2 Replies Last reply
              0
              • J Jorgen Sigvardsson

                Chris Maunder wrote: Whitespace is free. Screen estate isn't. :) Besides, now that VS.NET have caught up with early 90's [X]Emacs technology (matching brackets and smart indentation), mismatched crackets isn't that much of an issue as it was say 2 years ago. :) I am however missing the XEmacs feature "highlight expression". It highlights the expression under the cursor. So if the cursor is on the firs {, the editor would then change the background color on all text between the first { and the matching }. Now that's a killer feature, because it'll help you find mismatched stuff real easy. Why hasn't it been implemented I wonder? I doubt it's possible to hack it as a IDE script either, because I don't think it's possible to manipulate the color attributes of a specific text span. <desperate>Wasn't our friend Nick Hodapp a VS.NET manager kind of guy? Can you hear me Nick? Nick?! Nick!?!? I'm on me knees, begging you man! Please give me "highlight expression". Pretty please with sugar on top!</desperate> -- Oneigaishimasu! I blog too now[^]

                Z Offline
                Z Offline
                Zdeslav Vojkovic
                wrote on last edited by
                #10

                Jörgen Sigvardsson wrote: So if the cursor is on the firs {, the editor would then change the background color on all text between the first { and the matching } you can achieve something similar with ctrl+shift+]. it doesn't change the color, but selects the expresion. it works on VS6, and most likely on VS.NET, too. i know it's not the same as "highlight expression", but still it can help.

                J 1 Reply Last reply
                0
                • C Chris Maunder

                  Jörgen Sigvardsson wrote: Chris Maunder wrote: Whitespace is free. Screen estate isn't. There is no way I'm letting you get away that argument. If you're still using a 1024 x 768 monitor then we'll start a New Monitor for Jörgen Fund :) Jörgen Sigvardsson wrote: Wasn't our friend Nick Hodapp a VS.NET manager kind of guy? He was (past tense) Product Manager (ie Marketing person) for Visual C++. He could only wail and gnash his teeth at the Program Manager to get new features implements. He's since headed to greener pastures. cheers, Chris Maunder

                  A Offline
                  A Offline
                  Anna Jayne Metcalfe
                  wrote on last edited by
                  #11

                  Chris Maunder wrote: Jörgen Sigvardsson wrote: Wasn't our friend Nick Hodapp a VS.NET manager kind of guy? He was (past tense) Product Manager (ie Marketing person) for Visual C++. He could only wail and gnash his teeth at the Program Manager to get new features implements. He's since headed to greener pastures. That would explain why his column has ground to a dead halt then. Any idea where he's moved on to? Anna :rose: Riverblade Ltd - Software Consultancy Services Anna's Place | Tears and Laughter "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work.

                  1 Reply Last reply
                  0
                  • C Chris Maunder

                    The first one. Brackets on the same line are just asking for trouble (ie missed/mismatched brackets) if you ask me. Whitespace is free. cheers, Chris Maunder

                    A Offline
                    A Offline
                    Anna Jayne Metcalfe
                    wrote on last edited by
                    #12

                    Definitely. Even with the aid of tools such as Visual Assist X the other styles are not something I care to come across. Anna :rose: Riverblade Ltd - Software Consultancy Services Anna's Place | Tears and Laughter "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work.

                    1 Reply Last reply
                    0
                    • C Chris Maunder

                      Jörgen Sigvardsson wrote: Chris Maunder wrote: Whitespace is free. Screen estate isn't. There is no way I'm letting you get away that argument. If you're still using a 1024 x 768 monitor then we'll start a New Monitor for Jörgen Fund :) Jörgen Sigvardsson wrote: Wasn't our friend Nick Hodapp a VS.NET manager kind of guy? He was (past tense) Product Manager (ie Marketing person) for Visual C++. He could only wail and gnash his teeth at the Program Manager to get new features implements. He's since headed to greener pastures. cheers, Chris Maunder

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

                      Chris Maunder wrote: . If you're still using a 1024 x 768 monitor then we'll start a New Monitor for Jörgen Fund I'd be happier if you'd start a "New Eyes for Jörgen Fund". Eventhough I'm using prescribed glasses, my eyesight isn't what it used to be. :) [edit]Meaning: I want to see as much code as possible on one page[edit] Chris Maunder wrote: He's since headed to greener pastures. Good for him :) -- Oneigaishimasu! I blog too now[^]

                      B 1 Reply Last reply
                      0
                      • Z Zdeslav Vojkovic

                        Jörgen Sigvardsson wrote: So if the cursor is on the firs {, the editor would then change the background color on all text between the first { and the matching } you can achieve something similar with ctrl+shift+]. it doesn't change the color, but selects the expresion. it works on VS6, and most likely on VS.NET, too. i know it's not the same as "highlight expression", but still it can help.

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

                        It's too manual and it's a bit too risky with a selection... And yeah, I forgot to mention that "highlight expression" works on (), [] and {}; I *think* it works on case/break too, but I'm unsure as it was quite some time ago I used XEmacs. -- Oneigaishimasu! I blog too now[^]

                        Z 1 Reply Last reply
                        0
                        • J Jorgen Sigvardsson

                          It's too manual and it's a bit too risky with a selection... And yeah, I forgot to mention that "highlight expression" works on (), [] and {}; I *think* it works on case/break too, but I'm unsure as it was quite some time ago I used XEmacs. -- Oneigaishimasu! I blog too now[^]

                          Z Offline
                          Z Offline
                          Zdeslav Vojkovic
                          wrote on last edited by
                          #15

                          this works on (), [] and {} in VS, at least on my machine :) but i agree that it's too manual. maybe we should post a feature request for Visual Assist or Resharper?

                          1 Reply Last reply
                          0
                          • J Jorgen Sigvardsson

                            Chris Maunder wrote: . If you're still using a 1024 x 768 monitor then we'll start a New Monitor for Jörgen Fund I'd be happier if you'd start a "New Eyes for Jörgen Fund". Eventhough I'm using prescribed glasses, my eyesight isn't what it used to be. :) [edit]Meaning: I want to see as much code as possible on one page[edit] Chris Maunder wrote: He's since headed to greener pastures. Good for him :) -- Oneigaishimasu! I blog too now[^]

                            B Offline
                            B Offline
                            Brian Delahunty
                            wrote on last edited by
                            #16

                            Well if you're going to get new eyes then I want some too... I'd settle for the LASIK or LASEK surgery though ;-) Regards, Brian Dela :-) Now Bloging![^]

                            1 Reply Last reply
                            0
                            • C Chris Maunder

                              The first one. Brackets on the same line are just asking for trouble (ie missed/mismatched brackets) if you ask me. Whitespace is free. cheers, Chris Maunder

                              B Offline
                              B Offline
                              Blake Miller
                              wrote on last edited by
                              #17

                              It is funny you mention that, because some of the most OBSCURE programming errors we have encountered here are because someone puts the opening brace on the next line, and a maintenance guy comes along and puts a statement BETWEEN the if line and the opening brace! this: if( x ) { } else { } gets converted into if( x ) y; { }else { } Now that REALLY jacks up your code!

                              D 1 Reply Last reply
                              0
                              • B Blake Miller

                                It is funny you mention that, because some of the most OBSCURE programming errors we have encountered here are because someone puts the opening brace on the next line, and a maintenance guy comes along and puts a statement BETWEEN the if line and the opening brace! this: if( x ) { } else { } gets converted into if( x ) y; { }else { } Now that REALLY jacks up your code!

                                D Offline
                                D Offline
                                David Patrick
                                wrote on last edited by
                                #18

                                This is the first legitimate reason I've seen for not using the first form ... ... but, I'm still sticking to first format anyhow.

                                B 1 Reply Last reply
                                0
                                • D David Patrick

                                  This is the first legitimate reason I've seen for not using the first form ... ... but, I'm still sticking to first format anyhow.

                                  B Offline
                                  B Offline
                                  Blake Miller
                                  wrote on last edited by
                                  #19

                                  In about 20 years of coding C that is the ONLY reason I have been able to accept for not using the first form. Recently, I find it easier to accept because the IDE will match braces for me anyway. Along similar lines, do people prefer this: if( x ) { } or this if ( x ) { } of the one I like: if( x ){ } For some reason my 'processor' is happier if the parenthesis is more closely grouped with the control statement or its close expression than not. I like this: if( x && (y == 1) ){ more than if ( x && ( y == 1 ) ) { for example.

                                  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