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. goto [modified]

goto [modified]

Scheduled Pinned Locked Moved The Lounge
questioncom
73 Posts 25 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.
  • R Rei Miyasaka

    Okay, so this isn't 100% a lounge question, but I'm asking this to stir controversy for the sake of entertainment, so I'll post here. Is goto really that bad? I'm beginning to wonder if it's just peer pressure and scariness that's making people avoid it. There are undeniably occasions in which goto enables the most readable code. Making private methods just for the sake of avoiding goto seems more spaghetti to me, as does using more local booleans and if/elses for flagging. If I were a teacher, I might not teach students to use goto, because they'll likely abuse it. But if I was evaluating a student's code and they use goto appropriately, I'd probably give them bonus marks for being bold. So, is it only because you've been taught not to use goto that you don't use it? -- modified at 22:22 Friday 23rd November, 2007 Or... http://xkcd.com/292/[^] By the way, let me restate the question: I know goto isn't necessary, but are there cases in which it's more appropriate?

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

    Goto is a tool that requires care. More so than many others.

    Visit http://www.notreadytogiveup.com/[^] and do something special today.

    1 Reply Last reply
    0
    • F Fernando A Gomez F

      Yep, but Rama's point was that "it is difficult to come up with situations in modern languages like C++, C# Java etc. to use GoTo." What I meant is that since Win32 API was written for C, if you want to use them you'll have to do it the C way, and perhaps mix it with C++ exceptions, such as:

      HANDLE h = FindFirstFile(_T("AVeryImportantFile.txt"), &WIN32_FIND_DATA());
      if (h == INVALID_HANDLE_VALUE)
      throw CException(_T("A very important file is missing."));


      Hope is the negation of reality - Raistlin Majere

      E Offline
      E Offline
      Erik Funkenbusch
      wrote on last edited by
      #64

      An interesting solution to that problem is to create a function object to handle Win32 API calls. Then you can simply pass the function pointer to the object, the parameters, and the expected result code(s) and it can automatically do error handling, throwing exceptions, etc.. It's a bit of advance template code, but once you have it done and debugged, it's a great helper.

      -- Where are we going? And why am I in this handbasket?

      1 Reply Last reply
      0
      • R Rei Miyasaka

        Okay, so this isn't 100% a lounge question, but I'm asking this to stir controversy for the sake of entertainment, so I'll post here. Is goto really that bad? I'm beginning to wonder if it's just peer pressure and scariness that's making people avoid it. There are undeniably occasions in which goto enables the most readable code. Making private methods just for the sake of avoiding goto seems more spaghetti to me, as does using more local booleans and if/elses for flagging. If I were a teacher, I might not teach students to use goto, because they'll likely abuse it. But if I was evaluating a student's code and they use goto appropriately, I'd probably give them bonus marks for being bold. So, is it only because you've been taught not to use goto that you don't use it? -- modified at 22:22 Friday 23rd November, 2007 Or... http://xkcd.com/292/[^] By the way, let me restate the question: I know goto isn't necessary, but are there cases in which it's more appropriate?

        E Offline
        E Offline
        Erik Funkenbusch
        wrote on last edited by
        #65

        no. Let me rephrase that. NO! Wait, i'm not sure i'm quite clear enough *OH MY @#$@#$ GOD #$@$@# NO!!!!!!!" Yes, it's easy to delude oneself into believing that one little goto won't hurt things, and will actually make the code cleaner and easier to use. That might even be true. TODAY. But what about 3 years from now after 50 different people of different programming levels have modified the code? Then you end up with nasty code. NEVER, EVER, EVER shake a goto. Let sleeping control flow constructs lie. Goto's breed more goto's, and they're more prolific than rabbits. If this is your own personal code, and nobody else will ever touch it... do whatever the hell you want, but in a business situation, never ever ever do anything that someone with less skill or wisdom than you might misconstrue. -- modified at 13:50 Saturday 24th November, 2007 On the other hand, this is kind of funny http://damienkatz.net/2006/05/signs_youre_a_c.html[^]

        -- Where are we going? And why am I in this handbasket?

        R 1 Reply Last reply
        0
        • E Erik Funkenbusch

          no. Let me rephrase that. NO! Wait, i'm not sure i'm quite clear enough *OH MY @#$@#$ GOD #$@$@# NO!!!!!!!" Yes, it's easy to delude oneself into believing that one little goto won't hurt things, and will actually make the code cleaner and easier to use. That might even be true. TODAY. But what about 3 years from now after 50 different people of different programming levels have modified the code? Then you end up with nasty code. NEVER, EVER, EVER shake a goto. Let sleeping control flow constructs lie. Goto's breed more goto's, and they're more prolific than rabbits. If this is your own personal code, and nobody else will ever touch it... do whatever the hell you want, but in a business situation, never ever ever do anything that someone with less skill or wisdom than you might misconstrue. -- modified at 13:50 Saturday 24th November, 2007 On the other hand, this is kind of funny http://damienkatz.net/2006/05/signs_youre_a_c.html[^]

          -- Where are we going? And why am I in this handbasket?

          R Offline
          R Offline
          Robert Surtees
          wrote on last edited by
          #66

          Erik Funkenbusch wrote:

          but in a business situation, never ever ever do anything that someone with less skill or wisdom than you might misconstrue.

          so we're left with everyone doing Hello World apps then. Kewl.

          E 1 Reply Last reply
          0
          • R Robert Surtees

            Erik Funkenbusch wrote:

            but in a business situation, never ever ever do anything that someone with less skill or wisdom than you might misconstrue.

            so we're left with everyone doing Hello World apps then. Kewl.

            E Offline
            E Offline
            Erik Funkenbusch
            wrote on last edited by
            #67

            No. I said misconstrued, not "never do anything someone with less skill or wisdom might not understand". Although I have worked at places that outlawed the use of STL because most of the developers didn't understand it, and thus wouldn't b able to maintain it. What I meant was that if you do something that, if used correctly is ok, but if used incorrectly (which is done more often than the other) it's bad, you shouldn't do it.

            -- Where are we going? And why am I in this handbasket?

            1 Reply Last reply
            0
            • R Rei Miyasaka

              Okay, so this isn't 100% a lounge question, but I'm asking this to stir controversy for the sake of entertainment, so I'll post here. Is goto really that bad? I'm beginning to wonder if it's just peer pressure and scariness that's making people avoid it. There are undeniably occasions in which goto enables the most readable code. Making private methods just for the sake of avoiding goto seems more spaghetti to me, as does using more local booleans and if/elses for flagging. If I were a teacher, I might not teach students to use goto, because they'll likely abuse it. But if I was evaluating a student's code and they use goto appropriately, I'd probably give them bonus marks for being bold. So, is it only because you've been taught not to use goto that you don't use it? -- modified at 22:22 Friday 23rd November, 2007 Or... http://xkcd.com/292/[^] By the way, let me restate the question: I know goto isn't necessary, but are there cases in which it's more appropriate?

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

              I've not needed to use goto since assembler/BASIC days, and a lot of code has flowed under the compiler since then. I honestly can't see the need for it in 99.9999999% of situations - unless you already write longwinded spaghetti in the first place (that's the only time I've encountered it in my commercial career, but fortunately for him the guy who wrote it had left by then or else he'd have had an earful from me).

              Anna :rose: Linting the day away :cool: Anna's Place | Tears and Laughter "If mushy peas are the food of the devil, the stotty cake is the frisbee of God"

              R 1 Reply Last reply
              0
              • S Stuart Dootson

                reinux wrote:

                There are undeniably occasions in which goto enables the most readable code.

                But there are one hell of a lot more where it doesn't...that's why the advise is don't use goto (unless you absolutely have to)

                R Offline
                R Offline
                Rei Miyasaka
                wrote on last edited by
                #69

                Sure, but if you were well acquainted enough with your language that you can discern the ones that do and ones that don't, would you let anyone complain to you for using it?

                1 Reply Last reply
                0
                • A Anna Jayne Metcalfe

                  I've not needed to use goto since assembler/BASIC days, and a lot of code has flowed under the compiler since then. I honestly can't see the need for it in 99.9999999% of situations - unless you already write longwinded spaghetti in the first place (that's the only time I've encountered it in my commercial career, but fortunately for him the guy who wrote it had left by then or else he'd have had an earful from me).

                  Anna :rose: Linting the day away :cool: Anna's Place | Tears and Laughter "If mushy peas are the food of the devil, the stotty cake is the frisbee of God"

                  R Offline
                  R Offline
                  Rei Miyasaka
                  wrote on last edited by
                  #70

                  Again it's not the need that I'm talking about; it's the appropriateness.

                  1 Reply Last reply
                  0
                  • G Gary R Wheeler

                    I can't think of any other scenario in which goto would be preferred over a more structured and scoped transfer of control. There might be cases where it is more concise, but I don't think that's sufficient justification compared to its potential for misuse.


                    Software Zen: delete this;

                    Fold With Us![^]

                    R Offline
                    R Offline
                    Rei Miyasaka
                    wrote on last edited by
                    #71

                    Even in skilled and experienced hands, in a language with sufficient safety netting, like C#?

                    G 1 Reply Last reply
                    0
                    • R Rei Miyasaka

                      Even in skilled and experienced hands, in a language with sufficient safety netting, like C#?

                      G Offline
                      G Offline
                      Gary R Wheeler
                      wrote on last edited by
                      #72

                      Yes. My view is that "skilled and experienced hands" don't use it because the other methods of flow control are better. My opinion isn't based upon a particular language, either. Relying on language features to save your ass is just asking for trouble. Too many programmers "play with the net down", which results in poorly-performing, resource-hogging, clumsy, buggy applications.


                      Software Zen: delete this;

                      Fold With Us![^]

                      R 1 Reply Last reply
                      0
                      • G Gary R Wheeler

                        Yes. My view is that "skilled and experienced hands" don't use it because the other methods of flow control are better. My opinion isn't based upon a particular language, either. Relying on language features to save your ass is just asking for trouble. Too many programmers "play with the net down", which results in poorly-performing, resource-hogging, clumsy, buggy applications.


                        Software Zen: delete this;

                        Fold With Us![^]

                        R Offline
                        R Offline
                        Rei Miyasaka
                        wrote on last edited by
                        #73

                        I could likewise argue that not choosing and using the tools available to you just puts you behind. C# offers safer goto just as it does foreach, yield return (which not everyone agrees is necessary), nullable types, even safer switches, and a whole slew of other language specific features. Why would anyone not use them just because they don't want to rely on a single languages's features? I mean, I could understand if you were trying to teach someone programming, you might not give them all the zero-pedagogical-value high-productivity shortcuts; and again, I wouldn't teach anyone to use goto, but in the real world, I'd raise a brow at anyone who avoids foreaches and properties. Also, it would be a long shot to say that no skilled programmers use goto, or that all programmers who use goto are unskilled.

                        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