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. do you use goto? [modified]

do you use goto? [modified]

Scheduled Pinned Locked Moved The Lounge
phphtmldatabaseoraclecom
65 Posts 41 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.
  • C Christian Graus

    I've never used goto, not once in 8 years of being paid for my code. More important, I've never once written code where I set out to avoid a use of goto. I've seen where it's used in error handling code, and it seems valid enough to me there, but I've alwaysh handled errors differently, and never felt that goto would make my code more readable. I've removed my share of gotos from code, I've never written one.

    Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

    G Offline
    G Offline
    Graham Bradshaw
    wrote on last edited by
    #17

    Christian Graus wrote:

    I've never used goto

    Not explicitly, anyway. If you've ever used a C break or continue, implicitly you have, since break and continue are simply goto's with an implicit label that is just outside or inside the current end of scope.

    G 1 Reply Last reply
    0
    • P Patrick Klug

      Hey guys, My former team mate used goto's quite often (to my despair). I just published a small post on when to (not) use goto on my blog[^] where I try to look at this in a pragmatic way. I am interested if you are using goto's (or know someone who does?). Opinions? cheers, Pakl PS: This is just a blunt advertisment for my blog so I can lure you into it and become rich and famous. :-\

      Listen to the toad! www.dotnettoad.com[^]

      modified on Monday, May 19, 2008 4:44 AM

      J Offline
      J Offline
      Jorgen Andersson
      wrote on last edited by
      #18

      I don't use Goto and I get rashes when I see one. So, how about Exit/Break? Is that justifiable?

      L 1 Reply Last reply
      0
      • A Alsvha

        A few times for some testing/debuging purpose when I wanted to bypass code blocks. Never in production code (although I do feel it could be fun to litter some code with it, just for the heck of it :D)

        --------------------------- Blogging about SQL, Technology and many other things

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

        Alsvha wrote:

        although I do feel it could be fun to litter some code with it, just for the heck of it

        There is an evil person in there somewhere. If I found one of my guys using a Goto I'd haul them out into the light and display it a a case of what NOT to do. I thought it had been retired when we went to .net and was disgusted to see that it is in C#, and I thought VB was the only language inflicted with the bloody Goto.

        Never underestimate the power of human stupidity RAH

        1 Reply Last reply
        0
        • P Patrick Klug

          Hey guys, My former team mate used goto's quite often (to my despair). I just published a small post on when to (not) use goto on my blog[^] where I try to look at this in a pragmatic way. I am interested if you are using goto's (or know someone who does?). Opinions? cheers, Pakl PS: This is just a blunt advertisment for my blog so I can lure you into it and become rich and famous. :-\

          Listen to the toad! www.dotnettoad.com[^]

          modified on Monday, May 19, 2008 4:44 AM

          R Offline
          R Offline
          Rajesh R Subramanian
          wrote on last edited by
          #20

          In a situation like this[^], I *will* use goto. And yes, I know what I'm doing.

          Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

          M 1 Reply Last reply
          0
          • P Patrick Klug

            Hey guys, My former team mate used goto's quite often (to my despair). I just published a small post on when to (not) use goto on my blog[^] where I try to look at this in a pragmatic way. I am interested if you are using goto's (or know someone who does?). Opinions? cheers, Pakl PS: This is just a blunt advertisment for my blog so I can lure you into it and become rich and famous. :-\

            Listen to the toad! www.dotnettoad.com[^]

            modified on Monday, May 19, 2008 4:44 AM

            P Offline
            P Offline
            Philip Laureano
            wrote on last edited by
            #21

            Pakl wrote:

            I am interested if you are using goto's (or know someone who does?). Opinions?

            I only use GOTOs in IL or ILASM where it is absolutely necessary. Otherwise, a standard 'if' statement is the simplest way to get things done.

            Do you know...LinFu?

            1 Reply Last reply
            0
            • M Mustafa Ismail Mustafa

              A wise man once told me that if I used goto (and this was back during the day) then I had to rethink my solution. He was right.

              "Every time Lotus Notes starts up, somewhere a puppy, a kitten, a lamb, and a baby seal are killed. Lotus Notes is a conspiracy by the forces of Satan to drive us over the brink into madness. The CRC-32 for each file in the installation includes the numbers 666." Gary Wheeler "You're an idiot." John Simmons, THE Outlaw programmer "I realised that all of my best anecdotes started with "So there we were, pissed". Pete O'Hanlon

              R Offline
              R Offline
              Rajesh R Subramanian
              wrote on last edited by
              #22

              Actually, goto isn't *that* bad. In fact, MFC Framework code uses goto for handling initialization failures. But, I'll agree if you say that one will need goto very very very rarely. :)

              Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

              M 1 Reply Last reply
              0
              • V Vasudevan Deepak Kumar

                Rephrasing it, "

                If you plan using GOTO, you ought to GO-BACK and think again

                ".

                Vasudevan Deepak Kumar Personal Homepage
                Tech Gossips
                A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

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

                Quoted from Wikipedia:

                "...In defense of GOTO statements, others have noted that the restrained use of GOTO does not necessarily lead to poor quality code, and also argue that there are some tasks that cannot be straightforwardly accomplished in many programming languages without the use of one or more GOTO statements, such as implementing finite state machines, breaking out of nested loops and exception handling."

                The good old GOTO has not been eliminated from modern languages because it's useful. The quality and readability of any code does not stand and fall with the use of GOTO or any other thing. Both depend more on the knowledge, skill and dicipline of the programmer. Rules like not to use GOTO are supposed to help us with reaching those goals, but they are not religious dogmas and should therefore not be seen as such. Often I have seen really clumsy code when somebody went out of his way to obey some rule at all cost. But there should be one more rule: Think about what you are doing, use whatever suits the task best and give the rest of the world some hints by providing documentation and / or meaningful code comments. Then to use or not to use GOTOs would be less of an issue.

                A while ago he asked me what he should have printed on my business cards. I said 'Wizard'. I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.

                1 Reply Last reply
                0
                • P Patrick Klug

                  Hey guys, My former team mate used goto's quite often (to my despair). I just published a small post on when to (not) use goto on my blog[^] where I try to look at this in a pragmatic way. I am interested if you are using goto's (or know someone who does?). Opinions? cheers, Pakl PS: This is just a blunt advertisment for my blog so I can lure you into it and become rich and famous. :-\

                  Listen to the toad! www.dotnettoad.com[^]

                  modified on Monday, May 19, 2008 4:44 AM

                  C Offline
                  C Offline
                  CPallini
                  wrote on last edited by
                  #24

                  Yes, sometimes, writing C code. IMHO:"You must never use goto!" maybe a rule for the newbie, experienced developers can safely drop it. :)

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                  1 Reply Last reply
                  0
                  • P Patrick Klug

                    Hey guys, My former team mate used goto's quite often (to my despair). I just published a small post on when to (not) use goto on my blog[^] where I try to look at this in a pragmatic way. I am interested if you are using goto's (or know someone who does?). Opinions? cheers, Pakl PS: This is just a blunt advertisment for my blog so I can lure you into it and become rich and famous. :-\

                    Listen to the toad! www.dotnettoad.com[^]

                    modified on Monday, May 19, 2008 4:44 AM

                    H Offline
                    H Offline
                    hairy_hats
                    wrote on last edited by
                    #25

                    Yes, but I didn't inhale.

                    1 Reply Last reply
                    0
                    • P Patrick Klug

                      Hey guys, My former team mate used goto's quite often (to my despair). I just published a small post on when to (not) use goto on my blog[^] where I try to look at this in a pragmatic way. I am interested if you are using goto's (or know someone who does?). Opinions? cheers, Pakl PS: This is just a blunt advertisment for my blog so I can lure you into it and become rich and famous. :-\

                      Listen to the toad! www.dotnettoad.com[^]

                      modified on Monday, May 19, 2008 4:44 AM

                      V Offline
                      V Offline
                      Vikram A Punathambekar
                      wrote on last edited by
                      #26

                      Rule #1: Don't use goto. Rule #2: Know when to break Rule #1. Personally, I haven't come across an instance where I had to follow Rule #2.

                      Cheers, Vikram.


                      The hands that help are holier than the lips that pray.

                      R P 2 Replies Last reply
                      0
                      • R Rajesh R Subramanian

                        Actually, goto isn't *that* bad. In fact, MFC Framework code uses goto for handling initialization failures. But, I'll agree if you say that one will need goto very very very rarely. :)

                        Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

                        M Offline
                        M Offline
                        Mustafa Ismail Mustafa
                        wrote on last edited by
                        #27

                        So rare that its basically extinct?

                        "Every time Lotus Notes starts up, somewhere a puppy, a kitten, a lamb, and a baby seal are killed. Lotus Notes is a conspiracy by the forces of Satan to drive us over the brink into madness. The CRC-32 for each file in the installation includes the numbers 666." Gary Wheeler "You're an idiot." John Simmons, THE Outlaw programmer "I realised that all of my best anecdotes started with "So there we were, pissed". Pete O'Hanlon

                        R 1 Reply Last reply
                        0
                        • V Vikram A Punathambekar

                          Rule #1: Don't use goto. Rule #2: Know when to break Rule #1. Personally, I haven't come across an instance where I had to follow Rule #2.

                          Cheers, Vikram.


                          The hands that help are holier than the lips that pray.

                          R Offline
                          R Offline
                          Rajesh R Subramanian
                          wrote on last edited by
                          #28

                          I know I owe you an email. It's still in my drafts folder. Will send it off. :)

                          Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

                          V 1 Reply Last reply
                          0
                          • R Rajesh R Subramanian

                            In a situation like this[^], I *will* use goto. And yes, I know what I'm doing.

                            Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

                            M Offline
                            M Offline
                            Mustafa Ismail Mustafa
                            wrote on last edited by
                            #29

                            Yes, but the rules (as Vikram so adequately pointed out in his post below) is not for the exceptions but for the general case. Besides, Personally, I'd go for Judy's method (following the link you posted) as opposed to the goto method. Ugly as sin it may be but I find it readable and it maintains "the rule".

                            "Every time Lotus Notes starts up, somewhere a puppy, a kitten, a lamb, and a baby seal are killed. Lotus Notes is a conspiracy by the forces of Satan to drive us over the brink into madness. The CRC-32 for each file in the installation includes the numbers 666." Gary Wheeler "You're an idiot." John Simmons, THE Outlaw programmer "I realised that all of my best anecdotes started with "So there we were, pissed". Pete O'Hanlon

                            1 Reply Last reply
                            0
                            • J Jorgen Andersson

                              I don't use Goto and I get rashes when I see one. So, how about Exit/Break? Is that justifiable?

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

                              Justify? Before whom? If something serves the task at hand better than anything else then use it. How about letting those who try to enforce some rules at all price let do the justifying for a change? You might discover that many just howl with the wolves, but don't actually know why. In my opinion many of the rules are not written in stone. They are supposed to help us, but chaos does not automatically break lose if you decide to ignore them.

                              A while ago he asked me what he should have printed on my business cards. I said 'Wizard'. I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.

                              1 Reply Last reply
                              0
                              • V Vikram A Punathambekar

                                Rule #1: Don't use goto. Rule #2: Know when to break Rule #1. Personally, I haven't come across an instance where I had to follow Rule #2.

                                Cheers, Vikram.


                                The hands that help are holier than the lips that pray.

                                P Offline
                                P Offline
                                Philip Laureano
                                wrote on last edited by
                                #31

                                Vikram A Punathambekar wrote:

                                Rule #1: Don't use goto. Rule #2: Know when to break Rule #1.

                                Rule #3: Never goto #2.

                                Do you know...LinFu?

                                V R 2 Replies Last reply
                                0
                                • R Rajesh R Subramanian

                                  I know I owe you an email. It's still in my drafts folder. Will send it off. :)

                                  Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

                                  V Offline
                                  V Offline
                                  Vikram A Punathambekar
                                  wrote on last edited by
                                  #32

                                  Rajesh R Subramanian wrote:

                                  I know I owe you an email.

                                  The PHB thing? :~ Anyway, send it off; I'll read it tonight.

                                  Cheers, Vikram.


                                  The hands that help are holier than the lips that pray.

                                  1 Reply Last reply
                                  0
                                  • P Patrick Klug

                                    Hey guys, My former team mate used goto's quite often (to my despair). I just published a small post on when to (not) use goto on my blog[^] where I try to look at this in a pragmatic way. I am interested if you are using goto's (or know someone who does?). Opinions? cheers, Pakl PS: This is just a blunt advertisment for my blog so I can lure you into it and become rich and famous. :-\

                                    Listen to the toad! www.dotnettoad.com[^]

                                    modified on Monday, May 19, 2008 4:44 AM

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

                                    No. I've simply never found a need for it in any reasonably coherant programming language.

                                    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"

                                    1 Reply Last reply
                                    0
                                    • P Philip Laureano

                                      Vikram A Punathambekar wrote:

                                      Rule #1: Don't use goto. Rule #2: Know when to break Rule #1.

                                      Rule #3: Never goto #2.

                                      Do you know...LinFu?

                                      V Offline
                                      V Offline
                                      Vikram A Punathambekar
                                      wrote on last edited by
                                      #34

                                      :groaaaaan: But that warranted a 5! :-D

                                      Cheers, Vikram.


                                      The hands that help are holier than the lips that pray.

                                      1 Reply Last reply
                                      0
                                      • P Patrick Klug

                                        Hey guys, My former team mate used goto's quite often (to my despair). I just published a small post on when to (not) use goto on my blog[^] where I try to look at this in a pragmatic way. I am interested if you are using goto's (or know someone who does?). Opinions? cheers, Pakl PS: This is just a blunt advertisment for my blog so I can lure you into it and become rich and famous. :-\

                                        Listen to the toad! www.dotnettoad.com[^]

                                        modified on Monday, May 19, 2008 4:44 AM

                                        F Offline
                                        F Offline
                                        fboule
                                        wrote on last edited by
                                        #35

                                        My opinion in using gotos is like C programming: it is up to the programmer to code properly. Some are so skilled to write ugly C code. If used properly, goto can could may might have a place in our hearts. E.g. the MS-DOS batch script below (tested on WinXP):

                                        @echo off
                                        set i=0
                                        

                                        :loop
                                        set /a i=%i%+1
                                        echo Loop %i%
                                        if not %i% == 10 goto :loop

                                        R 1 Reply Last reply
                                        0
                                        • P Patrick Klug

                                          Hey guys, My former team mate used goto's quite often (to my despair). I just published a small post on when to (not) use goto on my blog[^] where I try to look at this in a pragmatic way. I am interested if you are using goto's (or know someone who does?). Opinions? cheers, Pakl PS: This is just a blunt advertisment for my blog so I can lure you into it and become rich and famous. :-\

                                          Listen to the toad! www.dotnettoad.com[^]

                                          modified on Monday, May 19, 2008 4:44 AM

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

                                          As in "go to h***" when I see someone using goto. Marc

                                          Thyme In The Country Interacx My Blog

                                          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