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. The new GOTO Statement?

The new GOTO Statement?

Scheduled Pinned Locked Moved The Lounge
questionlinqhardwarealgorithmscollaboration
82 Posts 29 Posters 52 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.
  • L Lost User

    Yes, you can abuse lambda's and make a mess. You can abuse goto and make a mess. You can abuse boolean variables to simulate some forms of goto and make just as big a mess. You can abuse operator overloading and make a mess, and when James Gosling says you can't have operator overloading in Java, you can make just as big a mess with method overloading and virtual methods if you set your mind to it. You can abuse switch in atrocious ways in C and C++ (case goes pretty much anywhere, it doesn't even look like valid syntax but it is), which is like a goto where you don't even know for sure where it will go. You can abuse pretty much every aspect of a general purpose programming language.

    E Offline
    E Offline
    ekolis
    wrote on last edited by
    #20

    harold aptroot wrote:

    You can abuse switch in atrocious ways in C and C++ (case goes pretty much anywhere, it doesn't even look like valid syntax but it is)

    Are you saying that you can have a case statement without an enclosing switch? :wtf: What does THAT look like, and what would one use it for?

    L 1 Reply Last reply
    0
    • OriginalGriffO OriginalGriff

      Yes, I agree. Every element of a language has it's use - even goto and var in C#- it's just that if you use them inappropriately you get less readable code instead of more. Personally, I find lambdas are useful in their place, but I avoid using them most of the time. var should be banned outside Linq!

      Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

      S Offline
      S Offline
      sisnaz
      wrote on last edited by
      #21

      YES! I completely agree. I have a team member that declares EVERYTHING as var. He says it's because it makes it loosely coupled and also C Sharpner tells him too.

      S F 2 Replies Last reply
      0
      • L Lost User

        sisnaz wrote:

        What's the difference between using embedded functions and a goto statement? It seems to me it's no different and just as difficult to follow and maintain. I'd be curious on other opinions of this practice.

        :doh: A GoTo breaks the flow where as a embedded function becomes part of the flow. Here is some psuedo code to show you the difference

        bool flag = GetFlag() //Embedded but the point is made elsewhere

        if flag
        GOTO: SomeLabel

        EmbeddedMethod();

        SomeOtherEmbeddedMethod();

        OK, so this code will ONLY run the EmbeddedMethod if the flag is false. One would think in that case it will also run the SomeOtherEmbeddedMethod and here is lies the evil of GoTo. What if the EmbeddedMehtod is defined in the same manner using a GoTo? i.e.

        bool flag = GetSomeOtherFlag()
        if flag
        GoTo: SomeOtherLabel

        Now as a user when I am looking at the first code snippet I have to account for that extra GoTo that could happen. Maybe I must run some logic if the EmbeddedMethod runs. How do I ensure it in the most simple manner? Solution, Dont't use GoTo!

        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.

        S Offline
        S Offline
        sisnaz
        wrote on last edited by
        #22

        Perhaps embedded method is a loose term. This is what I'm referring to. In my opinion it reflects the same goto example you posted.

        public string ReturnSomething()
        {
        // ... some logic
        // ...
        var compare = new Func<string, string, string, string, bool>((compare1, compare2, compare3, compare4) =>
        {
        return (compare1.Equals(compare2, StringComparison.InvariantCultureIgnoreCase) &&
        compare3.Equals(compare4, StringComparison.InvariantCultureIgnoreCase));
        });

                // some more logic flow
                // ....
        
                if (compare("a", "b", "c", "d")) {
                    // some logic
                }
        
                return "Something";
            }
        
        B B 2 Replies Last reply
        0
        • OriginalGriffO OriginalGriff

          Yes, I agree. Every element of a language has it's use - even goto and var in C#- it's just that if you use them inappropriately you get less readable code instead of more. Personally, I find lambdas are useful in their place, but I avoid using them most of the time. var should be banned outside Linq!

          Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

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

          OriginalGriff wrote:

          var should be banned outside Linq!

          Oh you CAN use them elsewhere!

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          • B Bassam Abdul Baki

            I fell in love with Goto when I first learned it. What can I say, I was able to follow it rationally. :)

            Web - BM - RSS - Math - LinkedIn

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

            Actually I liked GOSUB but now I know why!

            Never underestimate the power of human stupidity RAH

            K 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              Yes, I agree. Every element of a language has it's use - even goto and var in C#- it's just that if you use them inappropriately you get less readable code instead of more. Personally, I find lambdas are useful in their place, but I avoid using them most of the time. var should be banned outside Linq!

              Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

              B Offline
              B Offline
              Brady Kelly
              wrote on last edited by
              #25

              I, for one, welcome our new var overlord. Use it all the time, except in non-assignment declarations.

              1 Reply Last reply
              0
              • S sisnaz

                Perhaps embedded method is a loose term. This is what I'm referring to. In my opinion it reflects the same goto example you posted.

                public string ReturnSomething()
                {
                // ... some logic
                // ...
                var compare = new Func<string, string, string, string, bool>((compare1, compare2, compare3, compare4) =>
                {
                return (compare1.Equals(compare2, StringComparison.InvariantCultureIgnoreCase) &&
                compare3.Equals(compare4, StringComparison.InvariantCultureIgnoreCase));
                });

                        // some more logic flow
                        // ....
                
                        if (compare("a", "b", "c", "d")) {
                            // some logic
                        }
                
                        return "Something";
                    }
                
                B Offline
                B Offline
                Brady Kelly
                wrote on last edited by
                #26

                I fail to see anything like goto in your example. Flow branching into a function when it is called is all I see, and that happens all over, every second in C#. The key difference here is that without using goto in your function body, you are still guaranteed a return to just after the line that calls the function.

                1 Reply Last reply
                0
                • L Lost User

                  Yes, you can abuse lambda's and make a mess. You can abuse goto and make a mess. You can abuse boolean variables to simulate some forms of goto and make just as big a mess. You can abuse operator overloading and make a mess, and when James Gosling says you can't have operator overloading in Java, you can make just as big a mess with method overloading and virtual methods if you set your mind to it. You can abuse switch in atrocious ways in C and C++ (case goes pretty much anywhere, it doesn't even look like valid syntax but it is), which is like a goto where you don't even know for sure where it will go. You can abuse pretty much every aspect of a general purpose programming language.

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

                  Then some guru comes along and declares any one of those language features dangerous and unsafe. The followers of the guru create a cult around that and go a little further by creating the sacred commandment 'Thou shalt not use (whatever)'. The following crusade will take years, but in the end we have nagging code checking tools that assume to know better than that overpaid code monkey in front of the machine.

                  harold aptroot wrote:

                  You can abuse pretty much every aspect of a general purpose programming language.

                  That's exactly why the gurus will never run out of work. In the wrong direction, if you ask me. Coders who have been trained to follow rules blindly are very helpless when something goes wrong. That costs time and money instead of making anything safer or more productive. If you, my special Java friends, happen to read this: Your current problems will end the day you finally start thinking, throw out the holy commandment not to manage memory and analyze your code. Or you can spend some more years trying to beat the garbage collection into submission. :)

                  At least artificial intelligence already is superior to natural stupidity

                  1 Reply Last reply
                  0
                  • L Lost User

                    Bad Software languages breed bad software engineers....

                    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.

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

                    I disagree. :)

                    Veni, vidi, vici.

                    F 1 Reply Last reply
                    0
                    • L lewax00

                      var is great for foreach loops when you have long types like KeyValuePairs with a generic type for the value. I don't use it often outside that.

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

                      It's easier to type - but it doesn't make the code more readable! You have to check the type of the IEnumerable that the variable is declared from in order to find out what type you are using within the loop:

                      foreach (var v in MyClass.Items)
                      {
                      ...
                      }

                      Or

                      foreach (KeyValuePair<Guid, List<string>> kvp in MyClass.Items)
                      {
                      ...
                      {

                      (Not that I'm advocating using KeyValuePair<Guid, List<string>> directly anyway, you understand)

                      Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

                      "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

                      P L 2 Replies Last reply
                      0
                      • OriginalGriffO OriginalGriff

                        Yes, I agree. Every element of a language has it's use - even goto and var in C#- it's just that if you use them inappropriately you get less readable code instead of more. Personally, I find lambdas are useful in their place, but I avoid using them most of the time. var should be banned outside Linq!

                        Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

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

                        I quite like the use of 'var' when the thing to the right is clearly typed, e.g.

                        var map = new Dictionary<string, int>();

                        It was rather a failing in all C family languages that you had to write the type twice before when it's clearly there in the initialiser, and using var here is not hiding anything. I don't actually like it in Linq, it's too hard to see by inspection what the type of a Linq expression is. I quite like declaring those as IQueryable<whatever>.

                        P 1 Reply Last reply
                        0
                        • E ekolis

                          harold aptroot wrote:

                          You can abuse switch in atrocious ways in C and C++ (case goes pretty much anywhere, it doesn't even look like valid syntax but it is)

                          Are you saying that you can have a case statement without an enclosing switch? :wtf: What does THAT look like, and what would one use it for?

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

                          Well it doesn't really go that far, but the case statements don't define any sort of block (they behave much the same way as labels) and (as long as it's somewhere in a switch) you can mix them with other control flow. For example, Duff's device[^], which mixes a switch and a do/while.

                          E 1 Reply Last reply
                          0
                          • S sisnaz

                            Perhaps embedded method is a loose term. This is what I'm referring to. In my opinion it reflects the same goto example you posted.

                            public string ReturnSomething()
                            {
                            // ... some logic
                            // ...
                            var compare = new Func<string, string, string, string, bool>((compare1, compare2, compare3, compare4) =>
                            {
                            return (compare1.Equals(compare2, StringComparison.InvariantCultureIgnoreCase) &&
                            compare3.Equals(compare4, StringComparison.InvariantCultureIgnoreCase));
                            });

                                    // some more logic flow
                                    // ....
                            
                                    if (compare("a", "b", "c", "d")) {
                                        // some logic
                                    }
                            
                                    return "Something";
                                }
                            
                            B Offline
                            B Offline
                            BobJanova
                            wrote on last edited by
                            #32

                            compare is nothing more or less than a local method; this example is no less readable than the boring alternative:

                            public string ReturnSomething()
                            {
                            // ... some logic
                            // ...

                                    // some more logic flow
                                    // ....
                            
                                    if (compare("a", "b", "c", "d")) {
                                        // some logic
                                    }
                            
                                    return "Something";
                                }
                            

                            private boolean compare(string compare1, string compare2, string compare3, string compare4) {
                            return (compare1.Equals(compare2, StringComparison.InvariantCultureIgnoreCase) &&
                            compare3.Equals(compare4, StringComparison.InvariantCultureIgnoreCase));
                            }

                            ... and arguably more so, if the method is only used in one place, because you're not gumming up the class scope with methods that are not relevant to any of it apart from one function. compare cannot affect the control flow of the containing function, it is a normal function which takes arguments and returns a result – it is just declared as a dynamic Func type for technical reasons. Delphi allows you to declare local methods statically for exactly this kind of situation, and (like so much in Delphi) that is a really good idea.

                            1 Reply Last reply
                            0
                            • S sisnaz

                              YES! I completely agree. I have a team member that declares EVERYTHING as var. He says it's because it makes it loosely coupled and also C Sharpner tells him too.

                              S Offline
                              S Offline
                              Steve 2
                              wrote on last edited by
                              #33

                              haha sounds like me. var is certainly not only nice for foreach loops or LINQ. I find it rather stupid to type something like:

                              Dictionary>> stuff = /*sigh*/ new Dictionary>>();

                              Yes, stupid indeed. And it's exactly that type of scenario the "var" keyword was made for.

                              P F A K 4 Replies Last reply
                              0
                              • L Lost User

                                Well it doesn't really go that far, but the case statements don't define any sort of block (they behave much the same way as labels) and (as long as it's somewhere in a switch) you can mix them with other control flow. For example, Duff's device[^], which mixes a switch and a do/while.

                                E Offline
                                E Offline
                                ekolis
                                wrote on last edited by
                                #34

                                Hmm, come to think of it, I recently discovered that in C#, you can declare a variable in one case block and use it in a subsequent case block!

                                L 1 Reply Last reply
                                0
                                • OriginalGriffO OriginalGriff

                                  Yes, I agree. Every element of a language has it's use - even goto and var in C#- it's just that if you use them inappropriately you get less readable code instead of more. Personally, I find lambdas are useful in their place, but I avoid using them most of the time. var should be banned outside Linq!

                                  Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

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

                                  OriginalGriff wrote:

                                  var should be banned outside Linq!

                                  There should be a compiler warning for using var anywhere else. The thing that bothers me the most is to read code that the lazy programmer put var everywhere. It is one of those language features that I really question whether it came for bad or for good. It's too much abused, specially by beginners that don't understand the porpose of var. In my opinion var should only be used to infer anonymous types and nothing else.

                                  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

                                  OriginalGriffO S 2 Replies Last reply
                                  0
                                  • S Steve 2

                                    haha sounds like me. var is certainly not only nice for foreach loops or LINQ. I find it rather stupid to type something like:

                                    Dictionary>> stuff = /*sigh*/ new Dictionary>>();

                                    Yes, stupid indeed. And it's exactly that type of scenario the "var" keyword was made for.

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

                                    Steve#2 wrote:

                                    type of scenario the "var" keyword was made for.

                                    Bullpuckey; it was made for Linq. That's exactly the scenario the using directive was made for:

                                    using MyDic = Dictionary<int, List<Vec3<float>>> ;
                                    ...
                                    MyDic stuff = new MyDic() ;

                                    (Except that generics cme later. :sigh: )

                                    F S J 3 Replies Last reply
                                    0
                                    • S Steve 2

                                      haha sounds like me. var is certainly not only nice for foreach loops or LINQ. I find it rather stupid to type something like:

                                      Dictionary>> stuff = /*sigh*/ new Dictionary>>();

                                      Yes, stupid indeed. And it's exactly that type of scenario the "var" keyword was made for.

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

                                      Steve#2 wrote:

                                      And it's exactly that type of scenario the "var" keyword was made for.

                                      You're either joking or don't understand the purpose of var.

                                      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
                                      • S sisnaz

                                        YES! I completely agree. I have a team member that declares EVERYTHING as var. He says it's because it makes it loosely coupled and also C Sharpner tells him too.

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

                                        sisnaz wrote:

                                        He says it's because it makes it loosely coupled

                                        :doh:

                                        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

                                        1 Reply Last reply
                                        0
                                        • B BobJanova

                                          I quite like the use of 'var' when the thing to the right is clearly typed, e.g.

                                          var map = new Dictionary<string, int>();

                                          It was rather a failing in all C family languages that you had to write the type twice before when it's clearly there in the initialiser, and using var here is not hiding anything. I don't actually like it in Linq, it's too hard to see by inspection what the type of a Linq expression is. I quite like declaring those as IQueryable<whatever>.

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

                                          BobJanova wrote:

                                          it's too hard to see by inspection what the type of a Linq expression is

                                          And that's why var was created -- for times when you can't know the type when writing the code.

                                          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