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. I just used a goto!

I just used a goto!

Scheduled Pinned Locked Moved The Lounge
csharpcom
66 Posts 45 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.
  • S swampwiz

    I think the only time that exception handling should be used is when the current code section does not have any control over the code that is throwing the exception - i.e., it is preferable to check and control something than to rely on an exception that simply does a goto the catch branch.

    R Offline
    R Offline
    raddevus
    wrote on last edited by
    #31

    agreed. I'm thinking of calls to another library where it throws a specific exception after being configured properly. In that case all inputs are set to valid values but then something happens which causes the exception - network not available or something.

    1 Reply Last reply
    0
    • S Super Lloyd

      I know "it's bad" and I will be shun by all good developers and rich employers for a thousands years... But I look at it.. I can't find of anything better.. mm, maybe a private inner function (i.e. function inside a method).... followed by misplaced return.... mm....

      A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

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

      while ( true ) { ... break ... }

      C 1 Reply Last reply
      0
      • P PIEBALDconsult

        while ( true ) { ... break ... }

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

        also

        for (;;) { break; }

        do { break; } while(0);

        that's just pretending. everyone knows that break is a goto. own it!

        K 1 Reply Last reply
        0
        • S Super Lloyd

          I know "it's bad" and I will be shun by all good developers and rich employers for a thousands years... But I look at it.. I can't find of anything better.. mm, maybe a private inner function (i.e. function inside a method).... followed by misplaced return.... mm....

          A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

          D Offline
          D Offline
          Dr Walt Fair PE
          wrote on last edited by
          #34

          Everytime, I thought I needed a goto, I found I could just put a return inthe middle of a loop. That's a more better way to make things sucky.

          CQ de W5ALT

          Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

          1 Reply Last reply
          0
          • S Super Lloyd

            I know "it's bad" and I will be shun by all good developers and rich employers for a thousands years... But I look at it.. I can't find of anything better.. mm, maybe a private inner function (i.e. function inside a method).... followed by misplaced return.... mm....

            A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

            S Offline
            S Offline
            Slacker007
            wrote on last edited by
            #35

            Gotos are fine. Like, "I will be back in 30 minutes. I have to GOTO the store." I have to GOTO the baseball game. :thumbsup: :laugh:

            D 1 Reply Last reply
            0
            • S Super Lloyd

              I know "it's bad" and I will be shun by all good developers and rich employers for a thousands years... But I look at it.. I can't find of anything better.. mm, maybe a private inner function (i.e. function inside a method).... followed by misplaced return.... mm....

              A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

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

              1. Create a workflow manager using generics, interfaces, class abstraction, enums for state and continuation. 2. Break up your code into small workflow steps. 3. On each step, check for termination. 4. Or to get really fancy, return a code that says what step in the workflow to skip to. 5. If you really want to be cool, allow for async workflow steps! ;)

              Latest Article - A 4-Stack rPI Cluster with WiFi-Ethernet Bridging Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

              B 1 Reply Last reply
              0
              • S Slacker007

                Gotos are fine. Like, "I will be back in 30 minutes. I have to GOTO the store." I have to GOTO the baseball game. :thumbsup: :laugh:

                D Offline
                D Offline
                Daniel Pfeffer
                wrote on last edited by
                #37

                Slacker007 wrote:

                I have to GOTO the store

                Except that's really a function call - you do intend to RETURN from the grocery store, don't you?

                Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                F 1 Reply Last reply
                0
                • S Super Lloyd

                  I know "it's bad" and I will be shun by all good developers and rich employers for a thousands years... But I look at it.. I can't find of anything better.. mm, maybe a private inner function (i.e. function inside a method).... followed by misplaced return.... mm....

                  A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                  D Offline
                  D Offline
                  Daniel Pfeffer
                  wrote on last edited by
                  #38

                  :omg: :wtf: Nuke the location in which the GOTO was used, sow the glass crater with salt, and plow it in. Then scatter biological and chemical agents all around the area, making it inaccessible for 10,000 years!

                  Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                  1 Reply Last reply
                  0
                  • S Super Lloyd

                    I know "it's bad" and I will be shun by all good developers and rich employers for a thousands years... But I look at it.. I can't find of anything better.. mm, maybe a private inner function (i.e. function inside a method).... followed by misplaced return.... mm....

                    A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                    M Offline
                    M Offline
                    markrlondon
                    wrote on last edited by
                    #39

                    It4 seems to me that in a language with no local functions or lacking in structured error handling, gotos have a useful place. A limited place, but a place all the same.

                    1 Reply Last reply
                    0
                    • D DRHuff

                      To avoid this you can put the entire code block in a try. Put the catch at the go to label and throw an exception where you call the goto. Because that’s different somehow!

                      Socialism is the Axe Body Spray of political ideologies: It never does what it claims to do, but people too young to know better keep buying it anyway. (Glenn Reynolds)

                      D Offline
                      D Offline
                      David ONeil
                      wrote on last edited by
                      #40

                      DRHuff wrote:

                      Because that’s different somehow!

                      Yes! Stack unwinding is SO MUCH MORE EFFICIENT than a 'jmp'! :laugh: :rolleyes: :rolleyes: :rolleyes: :laugh:

                      The forgotten roots of science | C++ Programming | DWinLib

                      1 Reply Last reply
                      0
                      • S Super Lloyd

                        I know "it's bad" and I will be shun by all good developers and rich employers for a thousands years... But I look at it.. I can't find of anything better.. mm, maybe a private inner function (i.e. function inside a method).... followed by misplaced return.... mm....

                        A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                        M Offline
                        M Offline
                        Mark_Wallace
                        wrote on last edited by
                        #41

                        I use goto all the time. Every loop and conditional expression you use calls it to their hearts' content; there's no avoiding it.

                        I wanna be a eunuchs developer! Pass me a bread knife!

                        1 Reply Last reply
                        0
                        • S Super Lloyd

                          I know "it's bad" and I will be shun by all good developers and rich employers for a thousands years... But I look at it.. I can't find of anything better.. mm, maybe a private inner function (i.e. function inside a method).... followed by misplaced return.... mm....

                          A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                          M Offline
                          M Offline
                          Mycroft Holmes
                          wrote on last edited by
                          #42

                          I started coding in SuperBase, GOTO and GOSUB were standard and recommended constructs. Transitioning to VB in the 90's was no benefit. It was only when I started using c# that I abandoned them completely. Some of us have shameful pasts.

                          Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

                          1 Reply Last reply
                          0
                          • S Super Lloyd

                            I know "it's bad" and I will be shun by all good developers and rich employers for a thousands years... But I look at it.. I can't find of anything better.. mm, maybe a private inner function (i.e. function inside a method).... followed by misplaced return.... mm....

                            A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                            D Offline
                            D Offline
                            Delphi 7 Solutions
                            wrote on last edited by
                            #43

                            These days the "goto" is back, I find this very unfortunate. Every time someone writes a RETURN or a BREAK statement, he/she is actually writing a GOTO And the worse thing about it is that this is encouraged these days...

                            S 1 Reply Last reply
                            0
                            • D Delphi 7 Solutions

                              These days the "goto" is back, I find this very unfortunate. Every time someone writes a RETURN or a BREAK statement, he/she is actually writing a GOTO And the worse thing about it is that this is encouraged these days...

                              S Offline
                              S Offline
                              Super Lloyd
                              wrote on last edited by
                              #44

                              he's back, and he's angry! ;P however I do believe that while do jump the code pointer, they are their own assembly instruction! ;P

                              A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                              1 Reply Last reply
                              0
                              • L Lost User

                                goto is NOT the enemy, it's only when it's used wrongly. but also ... contrary to popular belief disguising it fixes nothing ... if you really need to GOTO, just do it - hiding it only increases the bullshit level. unfortunatelly, there are teachers that tell the kids "GOTO is bad," but then "to do the same thing..." they then go on and teach the kids how to disguise them, i.e. instead use THROW, or stick the [inner] code in a method and return early (i.e. still in an indefinite state). ffs, really! I've got no problems with goto, but I do have issues with (1) shit code, and even more (2) attempts to hide shit code

                                Message Signature (Click to edit ->)

                                M Offline
                                M Offline
                                Mike Winiberg
                                wrote on last edited by
                                #45

                                Well said! Not using GOTO has become a matter of faith rather than good programming practice. I've seen some totally impenetrable code that has a indeterminate state, all because of the convoluted efforts the devs went through to avoid a GOTO. (Including rafts of local variables called things like a, aa, aaa, aaaa, x, xx, xxx, xxxx etc!) GOTO is just another tool - it can be used appropriately or badly, just like any other...

                                1 Reply Last reply
                                0
                                • P PeejayAdams

                                  I'm sure it was the week after your cat died but I'll have the Casio just in case!

                                  Whenever you find yourself on the side of the majority, it is time to pause and reflect. - Mark Twain

                                  F Offline
                                  F Offline
                                  Fueled By Decaff
                                  wrote on last edited by
                                  #46

                                  Phew, just in time.

                                  1 Reply Last reply
                                  0
                                  • D Daniel Pfeffer

                                    Slacker007 wrote:

                                    I have to GOTO the store

                                    Except that's really a function call - you do intend to RETURN from the grocery store, don't you?

                                    Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                                    F Offline
                                    F Offline
                                    Fueled By Decaff
                                    wrote on last edited by
                                    #47

                                    Ah, a GOSUB

                                    1 Reply Last reply
                                    0
                                    • S Super Lloyd

                                      I know "it's bad" and I will be shun by all good developers and rich employers for a thousands years... But I look at it.. I can't find of anything better.. mm, maybe a private inner function (i.e. function inside a method).... followed by misplaced return.... mm....

                                      A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                                      F Offline
                                      F Offline
                                      Fueled By Decaff
                                      wrote on last edited by
                                      #48

                                      The GOTO statement used to be pure evil. In BASIC it used to go to a line number. Not very easy to understand what it is intended to be doing at the best of times. Add in the fact that you could renumber every line in the program with the RENUMBER command and the GOTO statements would not update to reflect the line number changes and you have GOTO hell. (Not to mention that a lot of versions of BASIC at the time had missing features, for example procedures, functions, while loops, repeat loops.) These days with the GOTO statement going to a label it has had it's teeth filed and, while not a common feature is nothing to be afraid of.

                                      1 Reply Last reply
                                      0
                                      • S Super Lloyd

                                        I know "it's bad" and I will be shun by all good developers and rich employers for a thousands years... But I look at it.. I can't find of anything better.. mm, maybe a private inner function (i.e. function inside a method).... followed by misplaced return.... mm....

                                        A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                                        F Offline
                                        F Offline
                                        Fabio Franco
                                        wrote on last edited by
                                        #49

                                        What language?

                                        To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia

                                        S 1 Reply Last reply
                                        0
                                        • M Marc Clifton

                                          1. Create a workflow manager using generics, interfaces, class abstraction, enums for state and continuation. 2. Break up your code into small workflow steps. 3. On each step, check for termination. 4. Or to get really fancy, return a code that says what step in the workflow to skip to. 5. If you really want to be cool, allow for async workflow steps! ;)

                                          Latest Article - A 4-Stack rPI Cluster with WiFi-Ethernet Bridging Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                                          B Offline
                                          B Offline
                                          BillWoodruff
                                          wrote on last edited by
                                          #50

                                          When can I read the article ?

                                          «Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot

                                          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