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. Am I the only one that thinks type inference is a bad thing?

Am I the only one that thinks type inference is a bad thing?

Scheduled Pinned Locked Moved The Lounge
csharpquestion
22 Posts 19 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Ennis Ray Lynch Jr

    I was reading on the features of C# 3.0 and lo and behold it seems as if they have found a way to make C# more accessible to vb programmers. I see the future:

    var c = "String";
    var a = 12345;

    c = a; //Will eventually be legal, if not already.

    On a side not lamda expressions, extension method (only because of the keyword sealed) and the Object initialization are nice.


    File Not Found

    T Offline
    T Offline
    ToddHileHoffer
    wrote on last edited by
    #12

    In vb.net you have the options to turn on Option strict and Option explicit making the example above illegal.

    GameFly free trial

    1 Reply Last reply
    0
    • E Ennis Ray Lynch Jr

      I was reading on the features of C# 3.0 and lo and behold it seems as if they have found a way to make C# more accessible to vb programmers. I see the future:

      var c = "String";
      var a = 12345;

      c = a; //Will eventually be legal, if not already.

      On a side not lamda expressions, extension method (only because of the keyword sealed) and the Object initialization are nice.


      File Not Found

      V Offline
      V Offline
      Vasudevan Deepak Kumar
      wrote on last edited by
      #13

      Explicit casting should always be there.

      Vasudevan Deepak Kumar Personal Homepage Tech Gossips

      1 Reply Last reply
      0
      • E Ennis Ray Lynch Jr

        I was reading on the features of C# 3.0 and lo and behold it seems as if they have found a way to make C# more accessible to vb programmers. I see the future:

        var c = "String";
        var a = 12345;

        c = a; //Will eventually be legal, if not already.

        On a side not lamda expressions, extension method (only because of the keyword sealed) and the Object initialization are nice.


        File Not Found

        S Offline
        S Offline
        Shog9 0
        wrote on last edited by
        #14

        Ennis Ray Lynch, Jr. wrote:

        c = a; //Will eventually be legal, if not already.

        It's already legal in VB (well, sorta). But that's not what type inference is about. Think of it in terms of getting rid of some of the unfortunate side-effects that came from trying to combine C++ syntax with an object reference-centered runtime. Remember, K&R C wasn't anywhere near as strict about type-checking as modern C++ (or C#) is. This is about letting competent programmers get their work done with less redundant typing...

        ----

        It appears that everybody is under the impression that I approve of the documentation. You probably also blame Ken Burns for supporting slavery.

        --Raymond Chen on MSDN

        E 1 Reply Last reply
        0
        • E Ennis Ray Lynch Jr

          I was reading on the features of C# 3.0 and lo and behold it seems as if they have found a way to make C# more accessible to vb programmers. I see the future:

          var c = "String";
          var a = 12345;

          c = a; //Will eventually be legal, if not already.

          On a side not lamda expressions, extension method (only because of the keyword sealed) and the Object initialization are nice.


          File Not Found

          X Offline
          X Offline
          Xiangyang Liu
          wrote on last edited by
          #15

          Ennis Ray Lynch, Jr. wrote:

          var c = "String"; var a = 12345; c = a; //Will eventually be legal, if not already.

          I never tried C# 3.0, but the following is legal in C# (1.0, 1.1):

          object c = "String";
          object a = 12345;
          c = a;

          What is the big difference? Just wondering.

          My .NET Business Application Framework My Home Page

          A L 2 Replies Last reply
          0
          • X Xiangyang Liu

            Ennis Ray Lynch, Jr. wrote:

            var c = "String"; var a = 12345; c = a; //Will eventually be legal, if not already.

            I never tried C# 3.0, but the following is legal in C# (1.0, 1.1):

            object c = "String";
            object a = 12345;
            c = a;

            What is the big difference? Just wondering.

            My .NET Business Application Framework My Home Page

            A Offline
            A Offline
            Andy Brummer
            wrote on last edited by
            #16

            With var, c will still be a string and a will still be an integer, it just saves having to type so much when dealing with really long templated types. It also allows for using variables in templated methods that can't be directly infered from the templated type.


            I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon

            1 Reply Last reply
            0
            • S Shog9 0

              Ennis Ray Lynch, Jr. wrote:

              c = a; //Will eventually be legal, if not already.

              It's already legal in VB (well, sorta). But that's not what type inference is about. Think of it in terms of getting rid of some of the unfortunate side-effects that came from trying to combine C++ syntax with an object reference-centered runtime. Remember, K&R C wasn't anywhere near as strict about type-checking as modern C++ (or C#) is. This is about letting competent programmers get their work done with less redundant typing...

              ----

              It appears that everybody is under the impression that I approve of the documentation. You probably also blame Ken Burns for supporting slavery.

              --Raymond Chen on MSDN

              E Offline
              E Offline
              Ennis Ray Lynch Jr
              wrote on last edited by
              #17

              I think that is they key there. Of course there are quite a number of people able to open visual studio and type that I would not consider in the category of competent programmers. Language candy, while nice, makes maintenance a nightmare.

              Shog9 wrote:

              This is about letting competent programmers get their work done with less redundant typing...


              File Not Found

              1 Reply Last reply
              0
              • E Ennis Ray Lynch Jr

                I was reading on the features of C# 3.0 and lo and behold it seems as if they have found a way to make C# more accessible to vb programmers. I see the future:

                var c = "String";
                var a = 12345;

                c = a; //Will eventually be legal, if not already.

                On a side not lamda expressions, extension method (only because of the keyword sealed) and the Object initialization are nice.


                File Not Found

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

                Type inference != "type free" c and a are still strongly typed - only the type is inferred from initialization. So c=a is not legal. And that's a good thing yes sire, especially since introduction of generics.


                We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
                My first real C# project | Linkify!|FoldWithUs! | sighist

                1 Reply Last reply
                0
                • X Xiangyang Liu

                  Ennis Ray Lynch, Jr. wrote:

                  var c = "String"; var a = 12345; c = a; //Will eventually be legal, if not already.

                  I never tried C# 3.0, but the following is legal in C# (1.0, 1.1):

                  object c = "String";
                  object a = 12345;
                  c = a;

                  What is the big difference? Just wondering.

                  My .NET Business Application Framework My Home Page

                  L Offline
                  L Offline
                  Luis Alonso Ramos
                  wrote on last edited by
                  #19

                  In your example, c is a reference to a string object, while a a reference to a (boxed) integer. Since c is declared as a reference to an object (and all types derive from object), you don't have a problem. But try casting c to a string and you'll see...

                  Luis Alonso Ramos Intelectix Chihuahua, Mexico

                  Not much here: My CP Blog!

                  1 Reply Last reply
                  0
                  • E Ennis Ray Lynch Jr

                    I was reading on the features of C# 3.0 and lo and behold it seems as if they have found a way to make C# more accessible to vb programmers. I see the future:

                    var c = "String";
                    var a = 12345;

                    c = a; //Will eventually be legal, if not already.

                    On a side not lamda expressions, extension method (only because of the keyword sealed) and the Object initialization are nice.


                    File Not Found

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

                    Replace var with object and you can pretty much do that already. Excellent for those who think strongly typed languages are for bed-wetting types. Terrible for those who need to debug their programs. I appreciate the concept of a non-typed language but unfortunately we're still using bits to represent our data. Because of this I want to be sure that my fixed point and floating point values remain fixed point and floating point values. I also want to know when a numerical value gets converted to a string because sometimes I really, really don't need the overhead of that conversion. I spend(spent) way too much time with VBScript and Javascript to appreciate weakly-typed languages and their subtle bugs. Much easier having specific types than littering your code with cast operators to force your data into a given type. It makes me sad that applications are now aimed at the lowest common denominator, and sadder still that our development tools are following suit.

                    cheers, Chris Maunder

                    CodeProject.com : C++ MVP

                    J 1 Reply Last reply
                    0
                    • M Michael Dunn

                      No, C# isn't suddenly going to become JavaScript. The point of var is to replace this:

                      Dictionary<String, MyBigObjectClassName> dict = new Dictionary<String, MyBigObjectClassName>();

                      with this:

                      var dict = new Dictionary<String, MyBigObjectClassName>();

                      Or in C++, replace:

                      std::vector<std::pair<std::string, int>>::const_iterator it = someVector.begin();

                      with:

                      auto it = someVector.begin();

                      --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?

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

                      Ah. An excellent shortcut for development. And one which is going to be seriously abused...

                      cheers, Chris Maunder

                      CodeProject.com : C++ MVP

                      1 Reply Last reply
                      0
                      • C Chris Maunder

                        Replace var with object and you can pretty much do that already. Excellent for those who think strongly typed languages are for bed-wetting types. Terrible for those who need to debug their programs. I appreciate the concept of a non-typed language but unfortunately we're still using bits to represent our data. Because of this I want to be sure that my fixed point and floating point values remain fixed point and floating point values. I also want to know when a numerical value gets converted to a string because sometimes I really, really don't need the overhead of that conversion. I spend(spent) way too much time with VBScript and Javascript to appreciate weakly-typed languages and their subtle bugs. Much easier having specific types than littering your code with cast operators to force your data into a given type. It makes me sad that applications are now aimed at the lowest common denominator, and sadder still that our development tools are following suit.

                        cheers, Chris Maunder

                        CodeProject.com : C++ MVP

                        J Offline
                        J Offline
                        Jasmine2501
                        wrote on last edited by
                        #22

                        Chris Maunder wrote:

                        littering your code with cast operators

                        Don't you mean "Runtime Conversion Errors"? And yeah, you're right. Programming languages should be harder to use. The easier it gets, the worse the worldwide codebase becomes. I've written about this before, this degradation in the worldwide collection of code. Eventually, we're going to have massive failures, and then people with experience might finally get paid what we deserve, but we'll hate it. The problem is that schools (and literature) are not teaching concepts, they are teaching languages. When you do that, it's like trying to describe a duck to someone who's never seen a bird before. Students need at least a full semester of concept stuff before they even touch a programming language. I don't understand why experienced college professors, who have probably worked in the industry, don't understand that. My intern is going through this... learning C#, but he doesn't know the basic concepts, so he has to ask me a lot of really basic questions. I'm tempted to go down there and ask the guy what the hell he's teaching, but I'm not this kid's mom :) It is a big waste of time to teach a language unless you use it only as a context for learning the basic concepts. No language that I used in the 1980s is still around today. If I didn't know the concepts, I wouldn't have been able to learn new languages without help. Because I know those concepts, I can look at code in a language I've never seen before, and usually figure it out (with things like LISP and SQL being notable exceptions to that rule)... I don't know if we could teach that ability in schools, but that doesn't mean we shouldn't try.

                        "Quality Software since 1983!"
                        http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.

                        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