• KairuByte@lemmy.dbzer0.com
      link
      fedilink
      English
      arrow-up
      1
      ·
      4 months ago

      Not… really. I can kinda see where you’re coming from, but if you are assigning a .ToString() to a variable, the only type it could be is a string.

      It’s not guessing, it’s inference. You’ve provided enough information to know what the type is, so it is now that type. The moment you introduce ambiguity, such as var test = 1 there are many things that variable could be, so you can no longer infer its type.

      Inference is not guessing. Can it go wrong? Certainly! But its quite rare. And the solution in those rare cases is explicit typing.

        • KairuByte@lemmy.dbzer0.com
          link
          fedilink
          English
          arrow-up
          1
          ·
          4 months ago

          Er… okay, yes. That would be quite the annoyance, but thats a bit of an edge case in this instance. I’d also wager that current implementations of IDEs would allow you to intelligently replace int with Int16/Int32/Int64 depending on the context before migration. I believe Visual Studio proper has that as an option in its code analysis and cleanup tool. You can also do the same for var => string typing if I remember correctly.

            • KairuByte@lemmy.dbzer0.com
              link
              fedilink
              English
              arrow-up
              1
              ·
              4 months ago

              You do realize that in C# at least, these compile to strongly typed variables? Barring a major change, such as migrating from 16 to 32 bit, you know what those value types are, you’re just not having to write them out. It saves you from having to type “LongDescriptiveTypeDescriptionBecauseSomeoneWasOverlyVerboseInTheirNaming” which is a small but nice thing to have. We arent talking about dynamics here.