• Traister101@lemmy.today
      link
      fedilink
      arrow-up
      6
      arrow-down
      2
      ·
      2 months ago

      No python is statically typed. You have type hints, which makes the language tolerable but like their name implies it’s a hint at the type. You can perfectly legally pass in something completely different that doesn’t conform whatsoever.

      The primary thing static languages provide is static typing, that being the ability to determine before runtime that all the types are valid. A good example of this is how C++ programs will refuse to compile if you try to invoke a method that doesn’t exist on the type. That’s because it’s statically typed. At compile time you know that the code is wrong. Dynamic languages fundamentally don’t work like that. You cannot know until runtime if the method you called or the field you are trying to touch exists or not. Again type hints help a lot with this but that doesn’t change how the language actually operates.

      • skulbuny
        link
        fedilink
        English
        arrow-up
        1
        arrow-down
        2
        ·
        2 months ago

        All static typing means is that types don’t change, eg you can’t declare a var as a string and later assign a number to it.

          • skulbuny
            link
            fedilink
            English
            arrow-up
            1
            arrow-down
            1
            ·
            2 months ago

            Name one statically typed language that doesn’t have that property. Name one non statically typed language that has that property.

            • JackbyDev@programming.dev
              link
              fedilink
              English
              arrow-up
              1
              ·
              2 months ago

              It’s much more involved than that. For example, static type systems involve checking that the functions you call accept the types of parameters you’re supplying then. It’s a necessary part of static typing but alone is not sufficient.

              If this code were a valid program in some hypothetical language but only failed at runtime then that would be an example of dynamic typing because the types cannot be verified statically (e.g., at compile time).

              var a = 1
              a = "a"
              

              But you’re right, I don’t really know of any languages like that. I could’ve sworn I heard this called strong typing but I can’t easily find a source. And strong/weak typing are a mess of definitions nobody agrees on.