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... Who uses it?

goto... Who uses it?

Scheduled Pinned Locked Moved The Lounge
questionlearning
131 Posts 66 Posters 5 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.
  • D Offline
    D Offline
    DanielSheets
    wrote on last edited by
    #1

    This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.

    OriginalGriffO M K L C 48 Replies Last reply
    0
    • D DanielSheets

      This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      DanielSheets wrote:

      This isn't a programming question.

      DanielSheets wrote:

      t can make for cleaner code if used correctly

      How can it not be?

      If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • D DanielSheets

        This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #3

        I've not used it in a long time. There are a few of them in our legacy code, but no new code have them; they are mostly used for quick exit of a function to do cleanup.

        Nihil obstat

        J H 2 Replies Last reply
        0
        • D DanielSheets

          This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.

          K Offline
          K Offline
          Keith Barrow
          wrote on last edited by
          #4

          I can't ever remember needing it in c#. That said, it's been so long I doubt I'd spot a place where it might make things better.

          Sort of a cross between Lawrence of Arabia and Dilbert.[^]
          -Or-
          A Dead ringer for Kate Winslett[^]

          M 1 Reply Last reply
          0
          • D DanielSheets

            This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.

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

            DanielSheets wrote:

            It can make for cleaner code if used correctly.

            Your definition of "cleaner code" is quite odd then. There is no "correct" usage of it in modern high level languages. It simply creates an unmaintainable ball of string.

            Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

            J 1 Reply Last reply
            0
            • D DanielSheets

              This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.

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

              DanielSheets wrote:

              I find it useful

              I am not ashamed to admit that I use it all the time. I goto the store I goto the bar I goto the office. Many other uses too :-)

              B 1 Reply Last reply
              0
              • D DanielSheets

                This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.

                A Offline
                A Offline
                Andrew Torrance
                wrote on last edited by
                #7

                If we are talking of C# then I cant think of a time I would ever use it , although I am somewhat biased as I have told everyone in my team that I would slaughter a family member if I ever found it in any code .

                S 1 Reply Last reply
                0
                • D DanielSheets

                  This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.

                  C Offline
                  C Offline
                  Chris Maunder
                  wrote on last edited by
                  #8

                  In SQL - fairly often to jump to the error handler at the end of our sprocs. I'll admit there's no good reason we do this, since it's easy enough for us to avoid this with if statements, but it's a pattern used in our original code and so for consistency we stuck with it:

                  Create Procedure MyProc as

                  Begin Tran
                  
                  -- Do stuff...
                  
                  if @@error <> 0 goto errorHandler
                  
                  Commit Tran
                  Return 0
                  

                  errorHandler:
                  Rollback Tran
                  Return 1

                  cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                  B G D J J 9 Replies Last reply
                  0
                  • D DanielSheets

                    This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.

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

                    Who uses it?

                    N00bs.

                    DanielSheets wrote:

                    It can make for cleaner code if used correctly.

                    Do you have an example? After years in the trade, I have still to see the first instance where it actually improves readability/maintainability.

                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                    D M 3 Replies Last reply
                    0
                    • C Chris Maunder

                      In SQL - fairly often to jump to the error handler at the end of our sprocs. I'll admit there's no good reason we do this, since it's easy enough for us to avoid this with if statements, but it's a pattern used in our original code and so for consistency we stuck with it:

                      Create Procedure MyProc as

                      Begin Tran
                      
                      -- Do stuff...
                      
                      if @@error <> 0 goto errorHandler
                      
                      Commit Tran
                      Return 0
                      

                      errorHandler:
                      Rollback Tran
                      Return 1

                      cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                      B Offline
                      B Offline
                      Bergholt Stuttley Johnson
                      wrote on last edited by
                      #10

                      burn the heretic

                      You cant outrun the world, but there is no harm in getting a head start Real stupidity beats artificial intelligence every time.

                      1 Reply Last reply
                      0
                      • D DanielSheets

                        This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.

                        D Offline
                        D Offline
                        dusty_dex
                        wrote on last edited by
                        #11

                        Not without being forced to. Futzing around with an old 8-bit BASIC - ATARI. It was a shockingly poor implementation of the language. Otherwise I can't recall using goto in any C-like language at all. ever!

                        Q. Hey man! have you sorted out the finite soup machine? A. Why yes, it's celery or tomato.

                        1 Reply Last reply
                        0
                        • L Lost User

                          DanielSheets wrote:

                          I find it useful

                          I am not ashamed to admit that I use it all the time. I goto the store I goto the bar I goto the office. Many other uses too :-)

                          B Offline
                          B Offline
                          BobJanova
                          wrote on last edited by
                          #12

                          Isyourspacebarfaulty? 'Go to' is two words.

                          S M 2 Replies Last reply
                          0
                          • D DanielSheets

                            This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.

                            B Offline
                            B Offline
                            BobJanova
                            wrote on last edited by
                            #13

                            I don't use it in high level languages where there is a structured alternative. The only time I'm tempted is the 'double break', i.e. wanting to escape from two levels of nested looping; to do this you have to create a method to do the double loop and use return, which often feels like overkill.

                            1 Reply Last reply
                            0
                            • D DanielSheets

                              This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.

                              D Offline
                              D Offline
                              Dalek Dave
                              wrote on last edited by
                              #14

                              I have used it for some lazy error handling.

                              --------------------------------- I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave CCC Link[^]

                              1 Reply Last reply
                              0
                              • L Lost User

                                Who uses it?

                                N00bs.

                                DanielSheets wrote:

                                It can make for cleaner code if used correctly.

                                Do you have an example? After years in the trade, I have still to see the first instance where it actually improves readability/maintainability.

                                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                                D Offline
                                D Offline
                                DanielSheets
                                wrote on last edited by
                                #15
                                    public static void SaveChartData(List dataList)
                                    {
                                        int totalDelays = 0;
                                        int value = 0;
                                        string errorString = "";
                                        // Use a temporary file in case there are any parse errors.
                                        string tmpFilePath = applicationPath + "TmpChartData.csv";
                                        using (StreamWriter sw = new StreamWriter(tmpFilePath))
                                        {
                                            foreach (DataGridClass dgc in dataList)
                                            {
                                                if (!int.TryParse((dgc.MATL.Equals("") ? "0" : dgc.MATL), out value))
                                                {
                                                    errorString = dgc.MATL;
                                                    goto ParseError;
                                                }
                                                totalDelays += value;
                                                if (!int.TryParse((dgc.EQUIP.Equals("") ? "0" : dgc.EQUIP), out value))
                                                {
                                                    errorString = dgc.EQUIP;
                                                    goto ParseError;
                                                }
                                                totalDelays += value;
                                                if (!int.TryParse((dgc.People.Equals("") ? "0" : dgc.People), out value))
                                                {
                                                    errorString = dgc.People;
                                                    goto ParseError;
                                                }
                                                totalDelays += value;
                                                if (!int.TryParse((dgc.Defects.Equals("") ? "0" : dgc.Defects), out value))
                                                {
                                                    errorString = dgc.Defects;
                                                    goto ParseError;
                                                }
                                                totalDelays += value;
                                                if (!int.TryParse((dgc.Other.Equals("") ? "0" : dgc.Other), out value))
                                                {
                                                    errorString = dgc.Other;
                                                    goto ParseError;
                                                }
                                                totalDelays += value;
                                                sw.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}",
                                                    dgc.Year, dgc.Month, dgc.Goal, dgc.Completions, totalDelays, dgc.to,
                                                    dgc.MATL, dgc.EQUIP, dgc.People, dgc.Defects, dgc.Other);
                                
                                                totalDelays = 0;
                                                value = 0;
                                            }
                                        }
                                        // If we got this far then there were no parse errors.
                                        File.Copy(tmpFilePath, chartData, true);
                                        return;
                                    ParseError:
                                        string msg = string.Format("Unable to parse data. Verify its entered correctly.\\r\\nValue = {0}", errorString);
                                        MessageBox.Sho
                                
                                L B R 3 Replies Last reply
                                0
                                • L Lost User

                                  Who uses it?

                                  N00bs.

                                  DanielSheets wrote:

                                  It can make for cleaner code if used correctly.

                                  Do you have an example? After years in the trade, I have still to see the first instance where it actually improves readability/maintainability.

                                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                                  M Offline
                                  M Offline
                                  Mauro Leggieri
                                  wrote on last edited by
                                  #16

                                  Eddy Vluggen wrote:

                                  Do you have an example? After years in the trade, I have still to see the first instance where it actually improves readability/maintainability.

                                  Hi, In C/C++ for e.g. in a switch statement where you must share some portion of code. Although one can put that shared part inside another function, for visibility & tracking purposes, some times is better to have the code in the same screen avoiding scrolling up and down to follow the code. Believe it, is real but I cannot show company code. I don't remember which old Pascal guru told that but sometimes a goto is preferable instead of doing a lot of work to avoid its usage and make the code difficult to read. For the other side, as an assembly programmer... I see JMPs everywhere hehehe. Regards, Mauro.

                                  L 1 Reply Last reply
                                  0
                                  • D DanielSheets
                                        public static void SaveChartData(List dataList)
                                        {
                                            int totalDelays = 0;
                                            int value = 0;
                                            string errorString = "";
                                            // Use a temporary file in case there are any parse errors.
                                            string tmpFilePath = applicationPath + "TmpChartData.csv";
                                            using (StreamWriter sw = new StreamWriter(tmpFilePath))
                                            {
                                                foreach (DataGridClass dgc in dataList)
                                                {
                                                    if (!int.TryParse((dgc.MATL.Equals("") ? "0" : dgc.MATL), out value))
                                                    {
                                                        errorString = dgc.MATL;
                                                        goto ParseError;
                                                    }
                                                    totalDelays += value;
                                                    if (!int.TryParse((dgc.EQUIP.Equals("") ? "0" : dgc.EQUIP), out value))
                                                    {
                                                        errorString = dgc.EQUIP;
                                                        goto ParseError;
                                                    }
                                                    totalDelays += value;
                                                    if (!int.TryParse((dgc.People.Equals("") ? "0" : dgc.People), out value))
                                                    {
                                                        errorString = dgc.People;
                                                        goto ParseError;
                                                    }
                                                    totalDelays += value;
                                                    if (!int.TryParse((dgc.Defects.Equals("") ? "0" : dgc.Defects), out value))
                                                    {
                                                        errorString = dgc.Defects;
                                                        goto ParseError;
                                                    }
                                                    totalDelays += value;
                                                    if (!int.TryParse((dgc.Other.Equals("") ? "0" : dgc.Other), out value))
                                                    {
                                                        errorString = dgc.Other;
                                                        goto ParseError;
                                                    }
                                                    totalDelays += value;
                                                    sw.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}",
                                                        dgc.Year, dgc.Month, dgc.Goal, dgc.Completions, totalDelays, dgc.to,
                                                        dgc.MATL, dgc.EQUIP, dgc.People, dgc.Defects, dgc.Other);
                                    
                                                    totalDelays = 0;
                                                    value = 0;
                                                }
                                            }
                                            // If we got this far then there were no parse errors.
                                            File.Copy(tmpFilePath, chartData, true);
                                            return;
                                        ParseError:
                                            string msg = string.Format("Unable to parse data. Verify its entered correctly.\\r\\nValue = {0}", errorString);
                                            MessageBox.Sho
                                    
                                    L Offline
                                    L Offline
                                    Lost User
                                    wrote on last edited by
                                    #17

                                    Read up on exception-handling.

                                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                                    D 1 Reply Last reply
                                    0
                                    • L Lost User

                                      Who uses it?

                                      N00bs.

                                      DanielSheets wrote:

                                      It can make for cleaner code if used correctly.

                                      Do you have an example? After years in the trade, I have still to see the first instance where it actually improves readability/maintainability.

                                      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                                      D Offline
                                      D Offline
                                      DanielSheets
                                      wrote on last edited by
                                      #18

                                      Its all relative I suppose.

                                      1 Reply Last reply
                                      0
                                      • M Mauro Leggieri

                                        Eddy Vluggen wrote:

                                        Do you have an example? After years in the trade, I have still to see the first instance where it actually improves readability/maintainability.

                                        Hi, In C/C++ for e.g. in a switch statement where you must share some portion of code. Although one can put that shared part inside another function, for visibility & tracking purposes, some times is better to have the code in the same screen avoiding scrolling up and down to follow the code. Believe it, is real but I cannot show company code. I don't remember which old Pascal guru told that but sometimes a goto is preferable instead of doing a lot of work to avoid its usage and make the code difficult to read. For the other side, as an assembly programmer... I see JMPs everywhere hehehe. Regards, Mauro.

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

                                        Mauro Leggieri wrote:

                                        For the other side, as an assembly programmer... I see JMPs everywhere hehehe.

                                        ..simply because there's little alternative in assembly. Assumed we weren't talking about assembly, but higher-level languages - there are few people still working professionally with assembly.

                                        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                                        M 1 Reply Last reply
                                        0
                                        • L Lost User

                                          Read up on exception-handling.

                                          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                                          D Offline
                                          D Offline
                                          DanielSheets
                                          wrote on last edited by
                                          #20

                                          For what part? Why would I need to use exception handling when thats exactly what TryParse is used for (assuming thats what you're talking about)?

                                          L 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