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. Pet Peeve

Pet Peeve

Scheduled Pinned Locked Moved The Lounge
tutorialquestion
102 Posts 51 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 Jeremy Falcon

    Chris, you can't BS me, come on man. You honestly expect me to buy that not using brackets for a single-line if condition makes code harder to maintain? Seriously? Where's the joke icon?

    Jeremy Falcon

    Sander RosselS Offline
    Sander RosselS Offline
    Sander Rossel
    wrote on last edited by
    #23

    Sure it's easy, until another developer adds a second line and forgets to add brackets. I've been working in some source code that didn't use brackets for single statements. I introduced a few bugs by not adding them when I had to and I've been wondering more than once if the original developer REALLY meant not to add brackets....

    if (condition)
    DoThis();
    else
    DoThat();
    DoAnotherThing();

    is really weird to look at and at the very least makes you wonder if it was intended... Especially if DoAnotherThing(); isn't properly in/outdented!

    My blog[^]

    public class SanderRossel : Lazy<Person>
    {
    public void DoWork()
    {
    throw new NotSupportedException();
    }
    }

    J C 2 Replies Last reply
    0
    • Sander RosselS Sander Rossel

      Sure it's easy, until another developer adds a second line and forgets to add brackets. I've been working in some source code that didn't use brackets for single statements. I introduced a few bugs by not adding them when I had to and I've been wondering more than once if the original developer REALLY meant not to add brackets....

      if (condition)
      DoThis();
      else
      DoThat();
      DoAnotherThing();

      is really weird to look at and at the very least makes you wonder if it was intended... Especially if DoAnotherThing(); isn't properly in/outdented!

      My blog[^]

      public class SanderRossel : Lazy<Person>
      {
      public void DoWork()
      {
      throw new NotSupportedException();
      }
      }

      J Offline
      J Offline
      Jeremy Falcon
      wrote on last edited by
      #24

      Ok, you have a good point with that, but it's still not worth the trade off of having really extra long files / routines. Besides, it gives you something to spot the new guys with so you can give them a hard time.

      Jeremy Falcon

      Sander RosselS D S 3 Replies Last reply
      0
      • K kmoorevs

        IMHO the latter is easier to read. I've recently had to resort to cheap reading glasses as { started looking like (! (even at 125%} :laugh: I don't always use {}, but when I do, I also prefer then on their own lines for readability. :thumbsup:

        "Go forth into the source" - Neal Morse

        J Offline
        J Offline
        Jeremy Falcon
        wrote on last edited by
        #25

        kmoorevs wrote:

        I don't always use {}, but when I do, I also prefer then on their own lines for readability.

        Click Me[^]

        Jeremy Falcon

        K 1 Reply Last reply
        0
        • J Jeremy Falcon

          Ok, you have a good point with that, but it's still not worth the trade off of having really extra long files / routines. Besides, it gives you something to spot the new guys with so you can give them a hard time.

          Jeremy Falcon

          Sander RosselS Offline
          Sander RosselS Offline
          Sander Rossel
          wrote on last edited by
          #26

          Jeremy Falcon wrote:

          it's still not worth the trade off of having really extra long files / routines

          It's really very much worth it. Look at it this way, if (it prevents a subtle bug from going into production (and dependent on your internal processes that chance may be a considerable risk)) { you may have saved that company downtime or wrong data and dependent on the size of that company a whole lot of money! } else { you just scroll a bit extra (it's negligable) and no one gets hurt... }

          Jeremy Falcon wrote:

          so you can give them a hard time.

          If the new guy screws up I'm the one responsible and I can get to fix whatever he broke, so that joke's on me ;)

          My blog[^]

          public class SanderRossel : Lazy<Person>
          {
          public void DoWork()
          {
          throw new NotSupportedException();
          }
          }

          J B 2 Replies Last reply
          0
          • Sander RosselS Sander Rossel

            Jeremy Falcon wrote:

            it's still not worth the trade off of having really extra long files / routines

            It's really very much worth it. Look at it this way, if (it prevents a subtle bug from going into production (and dependent on your internal processes that chance may be a considerable risk)) { you may have saved that company downtime or wrong data and dependent on the size of that company a whole lot of money! } else { you just scroll a bit extra (it's negligable) and no one gets hurt... }

            Jeremy Falcon wrote:

            so you can give them a hard time.

            If the new guy screws up I'm the one responsible and I can get to fix whatever he broke, so that joke's on me ;)

            My blog[^]

            public class SanderRossel : Lazy<Person>
            {
            public void DoWork()
            {
            throw new NotSupportedException();
            }
            }

            J Offline
            J Offline
            Jeremy Falcon
            wrote on last edited by
            #27

            Not being able to see your code as a whole can also cause much harder to spot subtle bugs as well. Still not worth the trade off. Besides, you're forgetting this[^].

            Jeremy Falcon

            1 Reply Last reply
            0
            • J Jeremy Falcon

              kmoorevs wrote:

              I don't always use {}, but when I do, I also prefer then on their own lines for readability.

              Click Me[^]

              Jeremy Falcon

              K Offline
              K Offline
              kmoorevs
              wrote on last edited by
              #28

              High five! :laugh:

              "Go forth into the source" - Neal Morse

              1 Reply Last reply
              0
              • Sander RosselS Sander Rossel

                if (condition) { this.DoThis(); } else { this.DoThat(); }

                You probably meant

                Ian Shlasko wrote:

                It's not properly formatted until there's only one token per line in the entire application.

                I guess it's theoretically possible... :~

                My blog[^]

                public class SanderRossel : Lazy<Person>
                {
                public void DoWork()
                {
                throw new NotSupportedException();
                }
                }

                G Offline
                G Offline
                glennPattonWork3
                wrote on last edited by
                #29

                Way back in my College days the Software Lecturer told us (the class) it wasn't possible to do the above. I proved her wrong by writing a short Pascal (I think) program with no returns all on one line, ah Youth :)

                _ P 2 Replies Last reply
                0
                • G glennPattonWork3

                  Way back in my College days the Software Lecturer told us (the class) it wasn't possible to do the above. I proved her wrong by writing a short Pascal (I think) program with no returns all on one line, ah Youth :)

                  _ Offline
                  _ Offline
                  _Damian S_
                  wrote on last edited by
                  #30

                  The end of the story - "...and that's how I got to repeat introduction to programming!!"

                  Quad skating his way through the world since the early 80's... Booger Mobile - My bright green 1964 Ford Falcon - check out the blog here!! | If you feel generous - make a donation to Camp Quality!!

                  1 Reply Last reply
                  0
                  • J Jeremy Falcon

                    Chris, you can't BS me, come on man. You honestly expect me to buy that not using brackets for a single-line if condition makes code harder to maintain? Seriously? Where's the joke icon?

                    Jeremy Falcon

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

                    it certainly is harder to maintain. i can't count how many times i've had to fix something in code that only uses brackets when one or more statements are being controlled. so you get stuff like:

                    for (i=0;i<10;i++)
                    for (x=0;x<10;x++)
                    if (xyz) foo()
                    else for (z=0;z<10;z++)
                    bazinga();
                    bar();

                    and then you have to spend precious brain wattage figuring out that bar(); has nothing to do with any of the rest of it. this isn't 1967, 3 bytes for a bracket and an CR/NL isn't going to run you out of punch cards. make the code readable!

                    image processing toolkits | batch image processing

                    A B 2 Replies Last reply
                    0
                    • R R Giskard Reventlov

                      Why are people so lazy? For example, how hard is it to

                      if (condition)
                      {
                      DoThis();
                      }
                      else
                      {
                      DoThat();
                      }

                      as opposed to:

                      if (condition)
                      DoThis();
                      else
                      DoThat();

                      Pedants :sigh:

                      M Offline
                      M Offline
                      Mladen Jankovic
                      wrote on last edited by
                      #32

                      The decision which to use is simple: - follow the coding standard - if you don't have it, use whichever style is used in file/project - new project/file, use whatever you find more atheistically pleasing to you Personal atheistic preference is one of very few arguments that I can accept as valid in this "debate" (like in any other debate on any kind of style). The only argument that is supported by concrete numbers is saved on-screen space by the second style. All other arguments are largely unsubstantiated (maybe I'm wrong, but let me see some numbers) So don't go around calling people lazy just because they don't conform to your preference, it can make you look obnoxious. <edit> My preference: ?:. What' you gonna do now? <edit>

                      Commodore 64 emulator for Windows Phone

                      enhzflepE R 2 Replies Last reply
                      0
                      • R R Giskard Reventlov

                        Why are people so lazy? For example, how hard is it to

                        if (condition)
                        {
                        DoThis();
                        }
                        else
                        {
                        DoThat();
                        }

                        as opposed to:

                        if (condition)
                        DoThis();
                        else
                        DoThat();

                        Pedants :sigh:

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

                        Do you really require 8 lines to convey 4 lines worth of information? Perhaps "begin" and "end" would be even more clear? How about "then"? :)

                        if (condition) then
                        begin
                        DoThis();
                        end
                        else
                        begin
                        DoThat();
                        end;

                        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                        X S 2 Replies Last reply
                        0
                        • R R Giskard Reventlov

                          Why are people so lazy? For example, how hard is it to

                          if (condition)
                          {
                          DoThis();
                          }
                          else
                          {
                          DoThat();
                          }

                          as opposed to:

                          if (condition)
                          DoThis();
                          else
                          DoThat();

                          Pedants :sigh:

                          N Offline
                          N Offline
                          Nemanja Trifunovic
                          wrote on last edited by
                          #34

                          I am not lazy (well, I may be, but that's not the point) and the reason I prefer the latter is to reduce the noise. Less noise, more readability.

                          utf8-cpp

                          1 Reply Last reply
                          0
                          • R R Giskard Reventlov

                            Why are people so lazy? For example, how hard is it to

                            if (condition)
                            {
                            DoThis();
                            }
                            else
                            {
                            DoThat();
                            }

                            as opposed to:

                            if (condition)
                            DoThis();
                            else
                            DoThat();

                            Pedants :sigh:

                            M Offline
                            M Offline
                            Marc Clifton
                            wrote on last edited by
                            #35

                            Personally, for one line this-or-that... condition.IfTrue(()=>DoThis()).Else(()=>DoThat()); ;P Marc

                            Imperative to Functional Programming Succinctly Higher Order Programming

                            B 1 Reply Last reply
                            0
                            • G glennPattonWork3

                              Way back in my College days the Software Lecturer told us (the class) it wasn't possible to do the above. I proved her wrong by writing a short Pascal (I think) program with no returns all on one line, ah Youth :)

                              P Offline
                              P Offline
                              PIEBALDconsult
                              wrote on last edited by
                              #36

                              :thumbsup: Quite. The maturity of a programming language may (in part) be calculated by how many newlines are required. A proper language requires none.

                              S 1 Reply Last reply
                              0
                              • Sander RosselS Sander Rossel

                                And why couldn't you write

                                if (condition)
                                {
                                this.DoThis();
                                }
                                else
                                {
                                this.DoThat();
                                }

                                Now this code is totally unambiguous :) Although I know some people who really hate this...

                                My blog[^]

                                public class SanderRossel : Lazy<Person>
                                {
                                public void DoWork()
                                {
                                throw new NotSupportedException();
                                }
                                }

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

                                That looks good to me :-)

                                Regards, Nish


                                Blog: voidnish.wordpress.com

                                1 Reply Last reply
                                0
                                • M Mladen Jankovic

                                  The decision which to use is simple: - follow the coding standard - if you don't have it, use whichever style is used in file/project - new project/file, use whatever you find more atheistically pleasing to you Personal atheistic preference is one of very few arguments that I can accept as valid in this "debate" (like in any other debate on any kind of style). The only argument that is supported by concrete numbers is saved on-screen space by the second style. All other arguments are largely unsubstantiated (maybe I'm wrong, but let me see some numbers) So don't go around calling people lazy just because they don't conform to your preference, it can make you look obnoxious. <edit> My preference: ?:. What' you gonna do now? <edit>

                                  Commodore 64 emulator for Windows Phone

                                  enhzflepE Offline
                                  enhzflepE Offline
                                  enhzflep
                                  wrote on last edited by
                                  #38

                                  Mladen Janković wrote:

                                  So don't go around calling people lazy just because they don't conform to your preference, it can make you look obnoxious.

                                  :thumbsup: ++Mladen.rep;

                                  1 Reply Last reply
                                  0
                                  • L Lost User

                                    I know what you're saying; however, there are times I find the second one easier to read. For example, if I have several of those on a page the extra symbols spread stuff out. I still do it the first way, but there are times when the second is easier for me to read.

                                    P Offline
                                    P Offline
                                    Paulo Zemek
                                    wrote on last edited by
                                    #39

                                    I agree with you. And I am actually the kind of person that when has to modify something like:

                                    if (something)
                                    {
                                    DoA();
                                    DoB();
                                    }

                                    To only call a DoAB(), I will go there and kill the extra { and }. So, I have more work doing that, but I keep consistency. So, it becomes:

                                    if (something)
                                    DoAB();

                                    B O T S 4 Replies Last reply
                                    0
                                    • M Mladen Jankovic

                                      The decision which to use is simple: - follow the coding standard - if you don't have it, use whichever style is used in file/project - new project/file, use whatever you find more atheistically pleasing to you Personal atheistic preference is one of very few arguments that I can accept as valid in this "debate" (like in any other debate on any kind of style). The only argument that is supported by concrete numbers is saved on-screen space by the second style. All other arguments are largely unsubstantiated (maybe I'm wrong, but let me see some numbers) So don't go around calling people lazy just because they don't conform to your preference, it can make you look obnoxious. <edit> My preference: ?:. What' you gonna do now? <edit>

                                      Commodore 64 emulator for Windows Phone

                                      R Offline
                                      R Offline
                                      R Giskard Reventlov
                                      wrote on last edited by
                                      #40

                                      Mladen Janković wrote:

                                      it can make you look obnoxious.

                                      But I am obnoxious

                                      M 1 Reply Last reply
                                      0
                                      • L Lost User

                                        Do you really require 8 lines to convey 4 lines worth of information? Perhaps "begin" and "end" would be even more clear? How about "then"? :)

                                        if (condition) then
                                        begin
                                        DoThis();
                                        end
                                        else
                                        begin
                                        DoThat();
                                        end;

                                        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                                        X Offline
                                        X Offline
                                        Xmen Real
                                        wrote on last edited by
                                        #41

                                        oh dear lord :laugh: :laugh: :laugh:

                                        TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia>

                                        ----------------------------------------------- 128 bit encrypted signature, crack if you can

                                        1 Reply Last reply
                                        0
                                        • P Paulo Zemek

                                          I agree with you. And I am actually the kind of person that when has to modify something like:

                                          if (something)
                                          {
                                          DoA();
                                          DoB();
                                          }

                                          To only call a DoAB(), I will go there and kill the extra { and }. So, I have more work doing that, but I keep consistency. So, it becomes:

                                          if (something)
                                          DoAB();

                                          B Offline
                                          B Offline
                                          Brady Kelly
                                          wrote on last edited by
                                          #42

                                          I prefer

                                          if (something) DoAB();

                                          for the latter. I never use it, but have recently come across it. It seems more readable to me.

                                          No object is so beautiful that, under certain conditions, it will not look ugly. - Oscar Wilde

                                          P D S 3 Replies 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