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. Most gratuitous use of 'goto'

Most gratuitous use of 'goto'

Scheduled Pinned Locked Moved The Lounge
question
32 Posts 23 Posters 1 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 Chris Maunder

    What's the most gratuitous, inane, innappropriate or just plain wrong use of the goto keyword you've seen? cheers, Chris Maunder

    C Offline
    C Offline
    ColinDavies
    wrote on last edited by
    #18

    I for one actually don't know how to use 'goto' Nor do I understand why it is used. Regardz Colin J Davies

    *** WARNING *
    This could be addictive
    **The minion's version of "Catch :bob: "

    It's a real shame that people as stupid as you can work out how to use a computer. said by Christian Graus in the Soapbox

    1 Reply Last reply
    0
    • S Stefan de Zeeuw

      I have been programming for 20+ years and never ever found any use for continue or break (except off course break in a switch statement), so to answer your question, no, they cannot. The same goes for the return statement. There can be only 1 entry point for a function and only 1 exit point. We always use a local var (result) to set the return value of a function. Using statements like goto, continue, break and return (the latter used in the wrong place) leads too often to "spaghetti code" IMHO.

      C Offline
      C Offline
      ColinDavies
      wrote on last edited by
      #19

      AgedToPerfection wrote: (except off course break in a switch statement), I won't allow anyone to use sloppy switch statements in my projects. So I can't see the point of having a break at all. Regardz Colin J Davies

      *** WARNING *
      This could be addictive
      **The minion's version of "Catch :bob: "

      It's a real shame that people as stupid as you can work out how to use a computer. said by Christian Graus in the Soapbox

      1 Reply Last reply
      0
      • C Chris Maunder

        What's the most gratuitous, inane, innappropriate or just plain wrong use of the goto keyword you've seen? cheers, Chris Maunder

        J Offline
        J Offline
        Jack Puppy
        wrote on last edited by
        #20

        here: TRACE(_T("I love Code Project and me! hehe haha\n")); goto here; I think the only time I've ever used goto was for "cleanup" purposes within a function. I do remember coming across a Microsoft VC++ sample that used goto - if I'm not mistaken it was one of the multimedia samples.

        My 20 favorite films:
        http://www.ymdb.com/user_top20_view.asp?usersid=8912

        1 Reply Last reply
        0
        • T Tim Ranker

          I have come across quite a few programmers that don't know about continue.

          F Offline
          F Offline
          Frank Olorin Rizzi
          wrote on last edited by
          #21

          Tim Ranker wrote: I have come across quite a few programmers that don't know about continue. ..ehr... I continue to run into gotos... ...(double)ehr... F.O.R.

          1 Reply Last reply
          0
          • C Chris Maunder

            What's the most gratuitous, inane, innappropriate or just plain wrong use of the goto keyword you've seen? cheers, Chris Maunder

            F Offline
            F Offline
            Frank Olorin Rizzi
            wrote on last edited by
            #22

            ANd now, for something completely different... I am currently contemplating sticking a *bunch* of gotos in my next component. It's C, it's an authentication component, and therefore its logic is something like: IF (bad user id) { error=BAD_ID; skip the rest except the last piece; } IF (bad PSW) { error=BAD_PSW; skip the rest except the last piece; } ... last piece: record to log file/DB what happened; return Success/Failure So.. a *big bunch* of nested if's, or a *big bunch* of if-else's, or a *big bunch* of gotos Aside, if no-one notices, I'm sure tempteds to use the gotos just 'cause ! I'd stop only if it would lead to the problems I hit in Assembly, when the label is too far, but I have never seen that problem in C/C++. Geee... they gave use a goto statement... let's use when appropriate ! F.O.R.

            1 Reply Last reply
            0
            • A Alexander M

              wasnt this a non-coding forum!? :cool: Don't try it, just do it! ;-)

              P Offline
              P Offline
              peterchen
              wrote on last edited by
              #23

              c'mon, it's the Maunder. He makes the rules, he breaks the rules.


              "Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
              sighist | Agile Programming | doxygen

              1 Reply Last reply
              0
              • C Chris Maunder

                What's the most gratuitous, inane, innappropriate or just plain wrong use of the goto keyword you've seen? cheers, Chris Maunder

                K Offline
                K Offline
                Kastellanos Nikos
                wrote on last edited by
                #24

                Every instance of goto is a mistage! Exception: in asm you have to move from one place to other but there the instruction is called code>jmp, to distinguise it from goto found at hi-level languages! (conclusion: goto is an instruction which you can avoid under every circumstanced) - - - - - - - - - - - - - - - - - - Memory leaks is the price we pay \0 01234567890123456789012345678901234

                1 Reply Last reply
                0
                • C Chris Maunder

                  What's the most gratuitous, inane, innappropriate or just plain wrong use of the goto keyword you've seen? cheers, Chris Maunder

                  I Offline
                  I Offline
                  Ian Darling
                  wrote on last edited by
                  #25

                  I think that ""goto considered harmful" considered harmful" is the correct approach here. Like all programming constructs, there is an appropriate time and place for it (and that's college). Goto is unfortunate in the respect that it's easier to abuse than most, and has significantly fewer (NOT 0!) sane uses. Two notable uses I can think of are on error goto in pre .NET VB, and in some BASIC variants you could do goto i * 1000 (which was sometimes useful for menus and stuff) but I'm sure everyone will just toast me for reminding them ;p ) After all, goto is just a more general version of gosub, which required more care: 80 let ret=100 90 goto 1000 100 rem Next bit 1000 rem Do something 1010 goto ret :laugh::laugh::laugh: -- Ian Darling If I was any more loopy, I'd be infinite.

                  1 Reply Last reply
                  0
                  • B bryce

                    as long as you're consistant :) i've heard people moan about the use of "goto" but they'll happily use break and continue... bit oxymoronic if you ask me :) Bryce --- Publitor, making Pubmed easy. http://www.sohocode.com/publitor

                    K Offline
                    K Offline
                    Kastellanos Nikos
                    wrote on last edited by
                    #26

                    I like break and continue... :) Please, can someone explain what's so bad about them? Can you really wtite :readable: code without continue and break? - - - - - - - - - - - - - - - - - - Memory leaks is the price we pay \0 01234567890123456789012345678901234

                    B 1 Reply Last reply
                    0
                    • S Stefan de Zeeuw

                      I have been programming for 20+ years and never ever found any use for continue or break (except off course break in a switch statement), so to answer your question, no, they cannot. The same goes for the return statement. There can be only 1 entry point for a function and only 1 exit point. We always use a local var (result) to set the return value of a function. Using statements like goto, continue, break and return (the latter used in the wrong place) leads too often to "spaghetti code" IMHO.

                      P Offline
                      P Offline
                      peterchen
                      wrote on last edited by
                      #27

                      I'm happy I'm not on your team.


                      "Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
                      sighist | Agile Programming | doxygen

                      1 Reply Last reply
                      0
                      • K Kastellanos Nikos

                        I like break and continue... :) Please, can someone explain what's so bad about them? Can you really wtite :readable: code without continue and break? - - - - - - - - - - - - - - - - - - Memory leaks is the price we pay \0 01234567890123456789012345678901234

                        B Offline
                        B Offline
                        bryce
                        wrote on last edited by
                        #28

                        theres nothing wrong with using break, continue OR goto cheers Bryce --- Publitor, making Pubmed easy. http://www.sohocode.com/publitor

                        1 Reply Last reply
                        0
                        • C Chris Maunder

                          What's the most gratuitous, inane, innappropriate or just plain wrong use of the goto keyword you've seen? cheers, Chris Maunder

                          T Offline
                          T Offline
                          Thomas Freudenberg
                          wrote on last edited by
                          #29

                          10 ?"Hello world"
                          20 goto 10

                          Regards Thomas


                          Disclaimer:
                          Because of heavy processing requirements, we are currently using some of your unused brain capacity for backup processing. Please ignore any hallucinations, voices or unusual dreams you may experience. Please avoid concentration-intensive tasks until further notice. Thank you.

                          1 Reply Last reply
                          0
                          • C Chris Maunder

                            What's the most gratuitous, inane, innappropriate or just plain wrong use of the goto keyword you've seen? cheers, Chris Maunder

                            realJSOPR Offline
                            realJSOPR Offline
                            realJSOP
                            wrote on last edited by
                            #30

                            We had a function that contained this:

                            void MyFunction()
                            {
                            start:
                            goto end;

                            //
                            // LOTS of code
                            //

                            end:
                            goto start:
                            }

                            The programmer in question was "experimenting" with different ways to lock up a program. Unfortunately, his short-term memory wasn't the best in the world, and he forgot he had put this into our production code along with this gem:

                            for ( ; ; ) ;

                            and this:

                            bool x = true;
                            do {} while (x==true || x==false);

                            By the way chris, there's a bug in the pre parsing (probably in IE, but I thought you should know). In the for() loop above, I got the winking smiley if i didn't put a space between the characters. ------- signature starts "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 "You won't like me when I'm angry..." - Dr. Bruce Banner Please review the Legal Disclaimer in my bio. ------- signature ends

                            1 Reply Last reply
                            0
                            • C Chris Maunder

                              What's the most gratuitous, inane, innappropriate or just plain wrong use of the goto keyword you've seen? cheers, Chris Maunder

                              D Offline
                              D Offline
                              Dave S
                              wrote on last edited by
                              #31

                              I had a boss once that maintained most of the code of a major application. I ended up with that code 2 years later. He had a single 2000 line function (he was an old Assembly programmer. Also wrote Cobol Compilers) that did most of the work. He had many gotos in this function. My favorites were the 2 that worked together. One Goto broke out of a 2 deep nested while loop. It went to a 5 line block of code inside a for loop 300 lines down. On completion of that 5 lines of code (keep in mind, it never initialized the for loop), it might return through its companion goto back to where it was called from. (goback to original goto and continue processing). If the condition failed, (which it never did, to my knowledge) it would continue processing inside that uninitialized for loop. We ran this function through some complexity mapping software. It generated a text map of each function with a number 1-10 for complexity. (1 being a linear function, and 10 being a complex == bad function). It also returned a graphic map of each line of code (vectors through each statement, conditions, loops, etc). This function returned a complexity of over 2000! The graphic map generated looked like a street map of south FLORIDA!! (To the dirt road level). "It takes a minimum of redesign to turn a crucifix into a pogo stick"

                              1 Reply Last reply
                              0
                              • S Stefan de Zeeuw

                                I have been programming for 20+ years and never ever found any use for continue or break (except off course break in a switch statement), so to answer your question, no, they cannot. The same goes for the return statement. There can be only 1 entry point for a function and only 1 exit point. We always use a local var (result) to set the return value of a function. Using statements like goto, continue, break and return (the latter used in the wrong place) leads too often to "spaghetti code" IMHO.

                                J Offline
                                J Offline
                                jhwurmbach
                                wrote on last edited by
                                #32

                                Fascist. ;P


                                Who is 'General Failure'? And why is he reading my harddisk?!?

                                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