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 63 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.
  • F Fabio Franco

    PIEBALDconsult wrote:

    Bullpuckey; it was made for Linq.

    I'd just like to add that it was made for Linq because Linq generates a lot of anonymous types. It would be a hell to create classes for all possible result sets.

    PIEBALDconsult wrote:

    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: )

    Yeah, I'd say nothing was made for that so we do workarounds :) Or we could model our own classes that handle trickier business rules, I like to believe everyone is capable of that.

    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 Offline
    S Offline
    Steve 2
    wrote on last edited by
    #45

    ah, you mean the using ^^ Haven't seen this usage of it, wow, yet another meaning of the keyword "using", I think now that's quite an abuse... (language design wise)

    K 1 Reply 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.

      A Offline
      A Offline
      aojepojefpoejafpeoj
      wrote on last edited by
      #46

      And you have to type all that in C# for what reason? You have autocomplete, can't complain about having to type too much.

      S 1 Reply Last reply
      0
      • F Fabio Franco

        PIEBALDconsult wrote:

        Bullpuckey; it was made for Linq.

        I'd just like to add that it was made for Linq because Linq generates a lot of anonymous types. It would be a hell to create classes for all possible result sets.

        PIEBALDconsult wrote:

        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: )

        Yeah, I'd say nothing was made for that so we do workarounds :) Or we could model our own classes that handle trickier business rules, I like to believe everyone is capable of that.

        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 Offline
        S Offline
        Steve 2
        wrote on last edited by
        #47

        [quote]I'd just like to add that it was made for Linq because Linq generates a lot of anonymous types. It would be a hell to create classes for all possible result sets.[/quote] Sounds like it makes sense. But "was made because of LINQ" sounds then more accurate than "made *for* LINQ", since automatic type inference is surely useful in other contexts.

        1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          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

          L Offline
          L Offline
          lewax00
          wrote on last edited by
          #48

          It just seems redundant to me, the dictionary's type should already be known and the key value pair will always have the same types. I don't feel much clarity is lost there, but then again when I use it, it's in code I wrote so hopefully I have a clear understanding to begin with (not always the case of course...).

          1 Reply Last reply
          0
          • A aojepojefpoejafpeoj

            And you have to type all that in C# for what reason? You have autocomplete, can't complain about having to type too much.

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

            sure autocomplete... it's still shorter than that, and actually I don't want to *read* all that much redundancy in a line of code, it's just plain idiotic to mention the type twice when the compiler knows anyway. Actually this is a thing I always hated about C and C++, because it seemed stupid, that I had to repeat myself although the damn compiler *should know* by assignment when creating a variable.

            1 Reply Last reply
            0
            • F Fabio Franco

              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

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

              In what way is "laziness" bad, concerning typing? Who needs typing excercise? I cringe at the sight of redundancy, and mentioning the type twice in an assignment is redundant. "In my opinion var should only be used to infer anonymous types and nothing else" And how do you rationalize that? Because you think it was made for something else, and should be used only there? It's your personal taste, other than "should.. blah blah", "beginners blah blah" I've heard no sensible explanation of you. Now I don't claim to be a genious programmer, but I'm "in the field" as long as you are plus some small extra years, although not knowing every aspect of every language I need to use. Still I'm quite confident that if there was a really dangerous issue with "using var outside of LINQ", I would have noticed it, I guess I'm experienced enough for that. I just don't see any, from none here who commanted about that, just loads of personal taste statements...

              F 1 Reply Last reply
              0
              • E ekolis

                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 Offline
                L Offline
                Lost User
                wrote on last edited by
                #51

                Yes that has bitten me in the past, where I got compile error about multiple variables with the same name that way. It seems strange for C#, where the different cases behave much less like "just labels".

                1 Reply Last reply
                0
                • S Steve 2

                  In what way is "laziness" bad, concerning typing? Who needs typing excercise? I cringe at the sight of redundancy, and mentioning the type twice in an assignment is redundant. "In my opinion var should only be used to infer anonymous types and nothing else" And how do you rationalize that? Because you think it was made for something else, and should be used only there? It's your personal taste, other than "should.. blah blah", "beginners blah blah" I've heard no sensible explanation of you. Now I don't claim to be a genious programmer, but I'm "in the field" as long as you are plus some small extra years, although not knowing every aspect of every language I need to use. Still I'm quite confident that if there was a really dangerous issue with "using var outside of LINQ", I would have noticed it, I guess I'm experienced enough for that. I just don't see any, from none here who commanted about that, just loads of personal taste statements...

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

                  Steve#2 wrote:

                  Who needs typing excercise?

                  Do you really think that Ctrl+C, Ctrl+V is a painful typing exercise. Better yet, do you really think that, Ctrl+C, Ctrl+V is too much for the sake of readability? Most C# people look at the beginning of the line to verify a type (or a base type/interface). Having a var there will not help at all when one is quickly sweeping the code.

                  Steve#2 wrote:

                  And how do you rationalize that? Because you think it was made for something else, and should be used only there?

                  You don't use dynamic keyword for types known at compile type, do you? Somethings are there for a purpose, so that's what we should use them for. Do you use a hammer as a screwdriver? You could bust something open, but I'd rather not brake it while doing so.

                  Steve#2 wrote:

                  "beginners blah blah"

                  I never said you were a beginner, but beginners do tend to abuse the keyword, specially when they are starting now, when the keyword already exists.

                  Steve#2 wrote:

                  I've heard no sensible explanation of you.

                  I think I already made my point about why you should use tools for the jobs they were designed for, unless you don't have the right tool.

                  Steve#2 wrote:

                  just loads of personal taste statements...

                  Even if they look personal, there are very solid reasons for that. As you should know, OriginalGriff has more experience than both of us combined, it's often wise to trust experienced people.

                  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 2 Replies Last reply
                  0
                  • F Fabio Franco

                    PIEBALDconsult wrote:

                    Bullpuckey; it was made for Linq.

                    I'd just like to add that it was made for Linq because Linq generates a lot of anonymous types. It would be a hell to create classes for all possible result sets.

                    PIEBALDconsult wrote:

                    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: )

                    Yeah, I'd say nothing was made for that so we do workarounds :) Or we could model our own classes that handle trickier business rules, I like to believe everyone is capable of that.

                    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

                    D Offline
                    D Offline
                    debo01
                    wrote on last edited by
                    #53

                    The var keyword is best suited for scenarios where the type is not known at design time as in the case of LINQ that uses anonymous types. To use it otherwise can constitute an abuse of the var keyword.

                    1 Reply Last reply
                    0
                    • S sisnaz

                      After coming down off of the "That's pretty cool" factor and as members on my team have increasingly been using anonymous methods, lambda expressions and new Func<> routines embedded in methods. The complexity (IMO) as increased significantly. I've begun to question this seemingly popular approach as; 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.

                      M Offline
                      M Offline
                      Marbry Hardin
                      wrote on last edited by
                      #54

                      There's definitely something to be said for clarity. Not just from the aspect of someone else having to support or extend your code, but sometimes just coming back to your own code after a period. Something about a hammer and nail comes to mind.

                      1 Reply Last reply
                      0
                      • F Fabio Franco

                        Steve#2 wrote:

                        Who needs typing excercise?

                        Do you really think that Ctrl+C, Ctrl+V is a painful typing exercise. Better yet, do you really think that, Ctrl+C, Ctrl+V is too much for the sake of readability? Most C# people look at the beginning of the line to verify a type (or a base type/interface). Having a var there will not help at all when one is quickly sweeping the code.

                        Steve#2 wrote:

                        And how do you rationalize that? Because you think it was made for something else, and should be used only there?

                        You don't use dynamic keyword for types known at compile type, do you? Somethings are there for a purpose, so that's what we should use them for. Do you use a hammer as a screwdriver? You could bust something open, but I'd rather not brake it while doing so.

                        Steve#2 wrote:

                        "beginners blah blah"

                        I never said you were a beginner, but beginners do tend to abuse the keyword, specially when they are starting now, when the keyword already exists.

                        Steve#2 wrote:

                        I've heard no sensible explanation of you.

                        I think I already made my point about why you should use tools for the jobs they were designed for, unless you don't have the right tool.

                        Steve#2 wrote:

                        just loads of personal taste statements...

                        Even if they look personal, there are very solid reasons for that. As you should know, OriginalGriff has more experience than both of us combined, it's often wise to trust experienced people.

                        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 Offline
                        S Offline
                        Steve 2
                        wrote on last edited by
                        #55

                        Fabio Franco wrote:

                        Do you really think that Ctrl+C, Ctrl+V is a painful typing exercise. Better yet, do you really think that, Ctrl+C, Ctrl+V is too much for the sake of readability? Most C# people look at the beginning of the line to verify a type (or a base type/interface). Having a var there will not help at all when one is quickly sweeping the code.

                        Ctrl+C, Ctrl+V and jumping around... come on, it still disrupts the flow and is quite a PITA. Sweeping, well, depends on how quickly, I guess, since my IDE shows the type of a variable when hovering the cursor over it, which happens to be where I read when scrolling. There are languages which don't have something like LINQ but do have automatic type inference, so a lot of people seem to disagree here what such a feature is good for or isn't. But yeah, I can see how that can be annoying - I have the problem with code where people put the opening { brace at the same line instead another one :-D I hate it when I can't identify scope by looking at the exact same column, but have to search for it in variying line widths... With my usual assignment style var use, though, the type is still quite to the left - if there is a very long variable name, I might put the type in the next line, a bit intented.

                        Fabio Franco wrote:

                        You don't use dynamic keyword for types known at compile type, do you?

                        Huh? Var is not dynamic. Bad example? Exactly *because* the type is known at compile time, I do use var in assignments!

                        Fabio Franco wrote:

                        Somethings are there for a purpose, so that's what we should use them for

                        That sounds quite like a priest, talking dogma, not to be questioned. If something turns out to work quite nicely for something else than original intention, why not use it? That something was not originally envisioned to be use for something, alone, is not an argument at all, for refraining from using it that way.

                        Fabio Franco wrote:

                        Do you use a hammer as a screwdriver? You could bust something open, but I'd rather not brake it while doing so.

                        I have not seen an example of this var use busting something open, other than you personally can't read the code as quickly.

                        Fabio Franco wrote:

                        OriginalGriff has more experience than both of us combined, i

                        F 1 Reply Last reply
                        0
                        • F Fabio Franco

                          Steve#2 wrote:

                          Who needs typing excercise?

                          Do you really think that Ctrl+C, Ctrl+V is a painful typing exercise. Better yet, do you really think that, Ctrl+C, Ctrl+V is too much for the sake of readability? Most C# people look at the beginning of the line to verify a type (or a base type/interface). Having a var there will not help at all when one is quickly sweeping the code.

                          Steve#2 wrote:

                          And how do you rationalize that? Because you think it was made for something else, and should be used only there?

                          You don't use dynamic keyword for types known at compile type, do you? Somethings are there for a purpose, so that's what we should use them for. Do you use a hammer as a screwdriver? You could bust something open, but I'd rather not brake it while doing so.

                          Steve#2 wrote:

                          "beginners blah blah"

                          I never said you were a beginner, but beginners do tend to abuse the keyword, specially when they are starting now, when the keyword already exists.

                          Steve#2 wrote:

                          I've heard no sensible explanation of you.

                          I think I already made my point about why you should use tools for the jobs they were designed for, unless you don't have the right tool.

                          Steve#2 wrote:

                          just loads of personal taste statements...

                          Even if they look personal, there are very solid reasons for that. As you should know, OriginalGriff has more experience than both of us combined, it's often wise to trust experienced people.

                          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 Offline
                          S Offline
                          Steve 2
                          wrote on last edited by
                          #56

                          Btw., I just skimmed through the C# 4.0 language specification, and it is littered with examples like:

                          var contacts = new List

                          Do you think the language designers would have used examples like that if they thought using the "var" keyword that way was bad, or against their very own intentions?

                          1 Reply Last reply
                          0
                          • J jschell

                            sisnaz wrote:

                            What's the difference between using embedded functions and a goto statement?

                            Because one is cool and the other isn't. It is of course related to the difference between understanding the syntax of a language and being able to write syntax that is maintainable.

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

                            Good point.

                            1 Reply Last reply
                            0
                            • S Steve 2

                              Fabio Franco wrote:

                              Do you really think that Ctrl+C, Ctrl+V is a painful typing exercise. Better yet, do you really think that, Ctrl+C, Ctrl+V is too much for the sake of readability? Most C# people look at the beginning of the line to verify a type (or a base type/interface). Having a var there will not help at all when one is quickly sweeping the code.

                              Ctrl+C, Ctrl+V and jumping around... come on, it still disrupts the flow and is quite a PITA. Sweeping, well, depends on how quickly, I guess, since my IDE shows the type of a variable when hovering the cursor over it, which happens to be where I read when scrolling. There are languages which don't have something like LINQ but do have automatic type inference, so a lot of people seem to disagree here what such a feature is good for or isn't. But yeah, I can see how that can be annoying - I have the problem with code where people put the opening { brace at the same line instead another one :-D I hate it when I can't identify scope by looking at the exact same column, but have to search for it in variying line widths... With my usual assignment style var use, though, the type is still quite to the left - if there is a very long variable name, I might put the type in the next line, a bit intented.

                              Fabio Franco wrote:

                              You don't use dynamic keyword for types known at compile type, do you?

                              Huh? Var is not dynamic. Bad example? Exactly *because* the type is known at compile time, I do use var in assignments!

                              Fabio Franco wrote:

                              Somethings are there for a purpose, so that's what we should use them for

                              That sounds quite like a priest, talking dogma, not to be questioned. If something turns out to work quite nicely for something else than original intention, why not use it? That something was not originally envisioned to be use for something, alone, is not an argument at all, for refraining from using it that way.

                              Fabio Franco wrote:

                              Do you use a hammer as a screwdriver? You could bust something open, but I'd rather not brake it while doing so.

                              I have not seen an example of this var use busting something open, other than you personally can't read the code as quickly.

                              Fabio Franco wrote:

                              OriginalGriff has more experience than both of us combined, i

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

                              Steve#2 wrote:

                              ince my IDE shows the type of a variable when hovering the cursor over it, which happens to be where I read when scrolling.

                              So you need to hover over it, don't you?

                              Steve#2 wrote:

                              There are languages which don't have something like LINQ but do have automatic type inference, so a lot of people seem to disagree here what such a feature is good for or isn't.

                              Yep, like javascript, I don't think you want a start a discussion that this is a good feature of javascript....

                              Steve#2 wrote:

                              But yeah, I can see how that can be annoying

                              Yes, very much ;)

                              Steve#2 wrote:

                              I hate it when I can't identify scope by looking at the exact same column

                              I hate that as well X| X|

                              Steve#2 wrote:

                              Huh? Var is not dynamic. Bad example?
                              Exactly *because* the type is known at compile time, I do use var in assignments!

                              You're missing the point. The point is, you should use a tool for what it's designed for, not to make your life easy at some point, you gotta think of the consequences.

                              Steve#2 wrote:

                              If something turns out to work quite nicely for something else than original intention, why not use it?

                              That's my point. Using var just because is easier shouldn't be justification at the cost of readability and comprehension. I'm sick of so many times having to look what the type is because I can't deduce it by it's declaration. So, it may work quite nicely for you who does not have to maintain other people's code, but no, it does not work when you do have to.

                              Steve#2 wrote:

                              I have not seen an example of this var use busting something open, other than you personally can't read the code as quickly.

                              You missing the point again, it was just an analogy. And if you haven't seen it, it does not mean it doesn't happen. And it's not just me who can't read as quickly. If you tell me that there is a quicker way to know a variable type other than it's declaration, please enlighten me and the rest of the world.

                              Steve#2 wrote:

                              I don't like just trust, I like compelling explanations.

                              As do I. And that's what I'm doing here in the la

                              S 1 Reply Last reply
                              0
                              • C CPallini

                                I disagree. :)

                                Veni, vidi, vici.

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

                                But bad software engineers do tend to prefer bad languages don't you think? "But it's not working!!!" :confused:

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

                                  K Offline
                                  K Offline
                                  Kevin Marois
                                  wrote on last edited by
                                  #60

                                  Outside of Linq, the only purpose var serves is to save a lazy programm a few keystrokes.

                                  If it's not broken, fix it until it is

                                  1 Reply 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.

                                    K Offline
                                    K Offline
                                    Kevin Marois
                                    wrote on last edited by
                                    #61

                                    Steve#2 wrote:

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

                                    What "scenerio" is that? You don't want to type more than you have to, so you leave it to the next developer to figure out what the type is?

                                    If it's not broken, fix it until it is

                                    S 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

                                      K Offline
                                      K Offline
                                      Kevin Marois
                                      wrote on last edited by
                                      #62

                                      Had a "senior" guy I worked with who asked in a meeting why you couldn't do

                                      var myvariable = null;

                                      If it's not broken, fix it until it is

                                      OriginalGriffO 1 Reply Last reply
                                      0
                                      • M Mycroft Holmes

                                        Actually I liked GOSUB but now I know why!

                                        Never underestimate the power of human stupidity RAH

                                        K Offline
                                        K Offline
                                        Kevin Marois
                                        wrote on last edited by
                                        #63

                                        This [^] was always fun

                                        If it's not broken, fix it until it is

                                        1 Reply Last reply
                                        0
                                        • S Steve 2

                                          I don't think it was made just for LINQ, that's not what I've read in countless introdution texts about new features back then. What do you mean by "Except that generics cme later" ? Generics are there since .NET 2.0, var since 3.5 IIRC.

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

                                          Steve#2 wrote:

                                          not what I've read in countless introdution texts

                                          Which were likely written by they who abuse it.

                                          Steve#2 wrote:

                                          What do you mean by

                                          Generics came after the using directive.

                                          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