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

    I'm not lazy, but I'll still use the latter. There's no point in always having to use a bracket so I don't, unless it makes things easier to read. Which in your example it doesn't. Wasting space just makes a source code file longer anyway and harder to navigate. Concise wins, unless it's hard to read.

    Jeremy Falcon

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

    it doesn't make anything easier to read, and it definitely makes things harder to maintain.

    image processing toolkits | batch image processing

    J 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:

      D Offline
      D Offline
      Dan Neely
      wrote on last edited by
      #11

      In a coding standard that put's {'s on their own line I prefer this:

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

      If you're putting the { on the previous line, IMO they're easy enough to overlook that the explicit closing } is needed. And if you're writing javascript :(( the opening { is obligate and this:

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

      or this:

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

      are obscenities. X|

      Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

      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:

        I Offline
        I Offline
        Ian Shlasko
        wrote on last edited by
        #12

        It's not laziness. The second one is quicker and easier to read IF the condition and the branched commands are short. As soon as any of those lines gets the slightest bit complicated, or if there's any nesting at all, I add the braces.

        Proud to have finally moved to the A-Ark. Which one are you in?
        Author of the Guardians Saga (Sci-Fi/Fantasy novels)

        J 1 Reply Last reply
        0
        • J Jeremy Falcon

          I'm not lazy, but I'll still use the latter. There's no point in always having to use a bracket so I don't, unless it makes things easier to read. Which in your example it doesn't. Wasting space just makes a source code file longer anyway and harder to navigate. Concise wins, unless it's hard to read.

          Jeremy Falcon

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

          I have to { disagree. } I prefer the verbosity and clarity that the braces bring to the code.

          Jeremy Falcon wrote:

          Concise wins, unless it's hard to read.

          Which is usually what happens. People that use the latter form also tend to be the ones that crush every line together so that you first have to separate to properly understand. Is there a lack of space on your screen? In any case a method bigger than a screen is just plain fugly. :)

          J 1 Reply Last reply
          0
          • R R Giskard Reventlov

            I have to { disagree. } I prefer the verbosity and clarity that the braces bring to the code.

            Jeremy Falcon wrote:

            Concise wins, unless it's hard to read.

            Which is usually what happens. People that use the latter form also tend to be the ones that crush every line together so that you first have to separate to properly understand. Is there a lack of space on your screen? In any case a method bigger than a screen is just plain fugly. :)

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

            Karel Čapek wrote:

            I prefer the verbosity and clarity that the braces bring to the code.

            You should try VB then.

            Jeremy Falcon

            R 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();
              }
              }

              I Offline
              I Offline
              Ian Shlasko
              wrote on last edited by
              #15

              That's not good enough...

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

              It's not properly formatted until there's only one token per line. :)

              Proud to have finally moved to the A-Ark. Which one are you in?
              Author of the Guardians Saga (Sci-Fi/Fantasy novels)

              J Sander RosselS M 3 Replies Last reply
              0
              • C Chris Losinger

                it doesn't make anything easier to read, and it definitely makes things harder to maintain.

                image processing toolkits | batch image processing

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

                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 C 2 Replies Last reply
                0
                • I Ian Shlasko

                  It's not laziness. The second one is quicker and easier to read IF the condition and the branched commands are short. As soon as any of those lines gets the slightest bit complicated, or if there's any nesting at all, I add the braces.

                  Proud to have finally moved to the A-Ark. Which one are you in?
                  Author of the Guardians Saga (Sci-Fi/Fantasy novels)

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

                  Ian Shlasko wrote:

                  As soon as any of those lines gets the slightest bit complicated, or if there's any nesting at all, I add the braces.

                  :thumbsup:

                  Jeremy Falcon

                  1 Reply Last reply
                  0
                  • J Jeremy Falcon

                    Karel Čapek wrote:

                    I prefer the verbosity and clarity that the braces bring to the code.

                    You should try VB then.

                    Jeremy Falcon

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

                    Heathen! Blasphemer! How do you even know that VB uses braces???

                    J 1 Reply Last reply
                    0
                    • I Ian Shlasko

                      That's not good enough...

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

                      It's not properly formatted until there's only one token per line. :)

                      Proud to have finally moved to the A-Ark. Which one are you in?
                      Author of the Guardians Saga (Sci-Fi/Fantasy novels)

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

                      Oooooooo, look at how easy that is to maintain now!! :drool:

                      Jeremy Falcon

                      1 Reply Last reply
                      0
                      • R R Giskard Reventlov

                        Heathen! Blasphemer! How do you even know that VB uses braces???

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

                        Ha. Well you see... I work for the devil, but it's only because I'm evil.

                        Jeremy Falcon

                        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:

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

                          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 1 Reply Last reply
                          0
                          • I Ian Shlasko

                            That's not good enough...

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

                            It's not properly formatted until there's only one token per line. :)

                            Proud to have finally moved to the A-Ark. Which one are you in?
                            Author of the Guardians Saga (Sci-Fi/Fantasy novels)

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

                            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 X J 3 Replies 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

                              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
                                          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