4 ms·
The arguments in that threat aren't very good. Everybody makes mistakes[0], types or not, and a type system doesn't prevent all errors. Every system that preven
by mcv 8y ago
The arguments in that threat aren't very good. Everybody makes mistakes[0], types or not, and a type system doesn't prevent all errors. Every system that prevents errors comes with its own overhead.
I think there are situations where explicit types are good, and situations where they're unnecessary or get in the way.
Java's use of generics is a good example of the latter:
ArrayList<String> list = new ArrayList<String>();
One of those just shouldn't be there. (Edit: Java 10 apparently added type inference, which means this is not necessary anymore.)
But in function parameters, it's incredibly useful to be able to ensure that the parameters are of the type you expect (and preferably not null, which most languages don't offer). That prevents a lot of unnecessary boilerplate checking whether you actually have the right type in your hands.
Basically I don't need explicit types for stuff I declare locally, because I can see in the code what type it is. But for parameters and other data I get from other parts of the system (ajax calls, for example), enforced types are incredibly useful.
[0] Except Donald Knuth, who apparently cannot make mistakes.
- woah 8y agoDo you know about type inference?
- mcv 8y agoI do. I thought Java didn't have it, but apparently starting with Java 10, it does. Type inference isn't always good, though. Scala's type system can be quite horrible in places, although I think the idea is generally good, particularly for local variables.
- hocuspocus 8y agoLocal variable type inference was brought to Java with the version 10.
- mcv 8y agoOoh, nice. That sinks that part of my argument, I guess. Still, it doesn't change the fact that some type systems are cumbersome in some places, yet valuable in other places. I think we're currently seeing a movement towards type systems that do more for you while getting in the way less, and that's certainly useful.
- hocuspocus 8y agoI think most modern(ized) languages have reached a fairly good compromise. Full inference is typically infeasible or too expensive unless you stick to the ML family and Haskell. And even then, I believe you want explicit type signatures for self-documenting purposes, also to avoid unwanted generalization.
- mcv 8y agoExactly. Explicit function signatures are very valuable. Having the system check that the object you get fits your expectations is useful. There are other situations where I could do without them.
- weberc2 8y agoThe overhead is typically “a few extra keystrokes”, Java and C++ notwithstanding. There are more complex cases in which standard type systems aren’t expressive and expressive type systems are arguably too difficult, but even then you could use an “untyped” type like interface{} in Go and program that bit just like you would in Python while still enjoying type safety in the other 99% of your application.
- svat 8y agoAbout your footnote: see Knuth's paper "The Errors of TeX", a detailed analysis of 860+ "errors" made during TeX's development. (https://yurichev.com/mirrors/knuth1989.pdf https://yurichev.com/mirrors/knuth1989.pdf or DOI: 10.1002/spe.4380190702) (The current number stands at 947: http://texdoc.net/texmf-dist/doc/generic/knuth/errata/errorlog.pdf http://texdoc.net/texmf-dist/doc/generic/knuth/errata/errorl...)