• @nous@programming.dev
    link
    fedilink
    English
    192 years ago

    Overall I agree with what the author says, though I have a few further thoughts:

    One might argue that writing types are time consuming, and the bugs are not an issue when programmer can cover those cases with automated tests.

    These two arguments contradict each other and together are an argument for static typing, not against. Which just shows how weak these arguments are.

    but a more powerful type of inference that can actually infer the whole type of a function by analyzing the body of the function.

    This bit I am not convinced by. Inferring the API of a function from its body makes it harder to see breaking changes when you refactor the body. It can be useful for internal private helpers, but IMO public APIs should be explicit about their signature.

    Functional Programming

    I would go one step further here. It should support OOP and procedural paradigms as well. No single programming paradigm is best suited to all problems. Sometimes a mixed approach is best. Any language that heavily leans oneway at the expense of the others limits itself to the problems it can best solve. I do admit the far too many languages lean too much towards OOP at the expense of functional style.

    So it is easy to push for a functional style over OOP in new languages. But I would be weary of purely functional language as well.

      • @eluvatar@programming.dev
        link
        fedilink
        English
        12 years ago

        From some of my own conversations with people they don’t find it useful as a solo dev because they have to read the docs for dependencies even with types, and they only ever have to deal with their own code which they know we’ll enough that they see types as a waste of time.

      • @nous@programming.dev
        link
        fedilink
        English
        42 years ago

        Some things are very easy to do in loosly typed languages - just as letting a function take a string or int, and then parsing that string into an int if a string was passed in. In a loosly typed language you can just call something like if typeof(input) but in a strongly typed language you often need a lot more boiler plate and extra wrapper types to say the function can only take an int or string - for instance in rust you might need to wrap them in a enum first or some how create a trait and implement that for each types.

        This is quite a bit of extra upfront cost some of the time that really rubs people that are used to loosly typed languages the wrong way. So they think it is slow to work with types. But what they never seem to count is the countless hours you save knowing that when you read a value from something and pass it to a function that wants only an int, that the value is an int and you dont end up getting 2 + "2" = "22" and other suprising bugs in your program. Which results in less time debugging and writing tests for weird cases the compiler does not allow.

        But all that extra time if often not counted as that is dissociated from the original problem at hand. And they are already used to this cost - people often notice a new cost, but don’t notice a possibly bigger saving else where.

        • @wasted@programming.dev
          link
          fedilink
          English
          42 years ago

          I never understood this argument. If your function is supposed to take an int, then parse your string before calling it?

          • @nous@programming.dev
            link
            fedilink
            English
            22 years ago

            There are reasons you might want to, such as you are constructing something that has a few different ways to create it. Like maybe a date, can parse it from a string, pass in each bit as a separate argument, take in a Unix timestamp.

            A lot of languages encourage this with constructors as you can often only have one.

            IMO it is far better to just have different functions for each type you want to build something from like how it is done in rust.

            But when you come from a language that encourages the opposite it can seem clunky to have to define separate functions for each. And it can take a while to accept the different way of working.

      • JackbyDev
        link
        fedilink
        English
        32 years ago

        I agree, but I imagine dynamic type fans would say they don’t understand why explicitly stating types can be helpful.

        • @sugar_in_your_tea@sh.itjust.works
          link
          fedilink
          English
          22 years ago

          Optional typing is pretty useful, especially if the tooling is such that it catches most issues. I use Python’s optional typing quite a bit, and my general approach is to add types if the function is intended to be reused or if it took more than three seconds to figure out what it does. We also use Typescript, and typing isn’t necessary there either.

          If your type system is too strict, it can be really annoying to work with and make simple things take longer. If it’s too loose, you’ll introduce stupid bugs.

          • @basskitten@programming.dev
            link
            fedilink
            English
            12 years ago

            If your type system is too strict, it can be really annoying to work with and make simple things take longer.

            Swift has entered the chat.

    • @zygo_histo_morpheus@programming.dev
      link
      fedilink
      English
      12 years ago

      The main argument against strictly typed languages imo isn’t that types are time-consuming to write, it’s that they forbid some otherwise valid programs. When writing down your types you are forced to write down some of the assumptions you make about your data (which is usually a good thing) but all assumptions aren’t necessarily possible or ergonomic to express in your given programming languages type system.

      Overall I have a strong preference for statically typed languages as they (usually) make code more readable and help prevent prevent bugs, but it’s important to not strawman fans of dynamic types either!

      • JackbyDev
        link
        fedilink
        English
        32 years ago

        Can you give any examples of such “otherwise valid programs”? Because a lot of times static typing also has ways to do everything dynamic typing can but it is just more difficult or (obviously) won’t have the benefits of static typing.

        • @zygo_histo_morpheus@programming.dev
          link
          fedilink
          English
          12 years ago

          I think the way some dynamically typed languages use maps is interesting. In most languages if you have a hashmap, all values have to have the same type. In a dynamic language you can have some members be methods, some members be values of potentially different types and so on. Of course, depending on what you want to achieve, you might be able to use a struct for example. A map is more flexible though. You can union two different maps, or you can have a function that takes a map that has either a or b. It’s not necessarily impossible to express this in static types either, but there are many things here that quickly become tedious to do with types that Just Work in dynamically typed languages.