3 ms·
The thing that baffles me on this is the idea that static typing is limited to something only the compiler can do. If instead it was merely a form of static an
by taeric 9y ago
The thing that baffles me on this is the idea that static typing is limited to something only the compiler can do.
If instead it was merely a form of static analysis, then it could easily be seen as something that can be added. Which, in many languages, it can be. The forms of analysis the advanced tools can give for C codebases is quite impressive. All without having to rewrite the system with more precise types.
Similarly with LISP. It is widely lauded as a very popular dynamic language. However, there is nothing stopping you from statically analyzing it. Obviously some practices make this more difficult, but sometimes just having an escape hatch for the developer is enough. Just as obviously, these practices that truly make it hard to analyze statically aren't used that often. That is, a decent sized program will almost certainly use the features in a few spots. But only a few and the majority of the code can still be analyzed easily statically.
- always_good 9y ago> there is nothing stopping you from statically analyzing it Well, sure there is. Someone has to decide it's worthwhile to build it, then they have to build it, and polish it to a point where it's usable which generally means a community has to form around that tool. Years of work. Doesn't surprise me that people think it's more worthwhile to just use a statically-typed language.
- taeric 9y agoThat isn't stopping you from doing it. That is just making it more difficult. But, and this is my point, this was effort that had to happen in creating the static languages, too. Just now we locked out the benefits to existing problems to problems that are rewritten in the new languages. Contrast this with hardening existing codebases by running enhanced tooling against them.
- jahewson 9y agoThe analysis tools for C codebases are quite impressive mostly because it’s a statically typed language which is amenable to such analysis.
- taeric 9y agoI challenge that assertion. Some of the most impressive analysis of C is specifically on some stuff that is dynamic in nature. (In particular, showing just that you didn't check for null is easy. Showing how the null could get there takes effort.) This also ignores some of the analysis for lisp languages. I know typed racket comes up every week for this topic. It didn't invent type checking for lisp, either.
- moomin 9y agoThis ignores the benefits that a type system can give you on top of correctness: autocomplete works better with types, so does automated refactoring. Compile-time polymorphism is lovely. Return type polymorphism is awesome.
- guntars 9y agoI think the point is that programs written in a dynamically typed language aren't that dynamic most of the time. With static analysis, you're able to get at least some benefit from autocomplete and automatic refactoring. The parts of the code where it doesn't work - well, the developer has made the tradeoff that it's worth it there. Sometimes I wonder why there aren't more 'empirically' typed languages, i.e., you write a function and some unit tests that exercise it and from that the compiler can determine what are the actual types and values the function sees for every variable.
- taeric 9y agoThat is mostly the point, yes. And I'll note that autocomplete is already challenged in a functional style, since you aren't always dispatching to methods of an object. As an easy example, if you are looking for functions that can return a Foo, autocomplete does little to help you know that you have to call .convertToFoo() on any of the baz instances in scope. There is already more than just basic type mapping going on. (To that end, a graph traversal assuming shortest path from symbols in scope to the desired shape works. So it is doable, of course.) To your question of "empirically typed", that is close to some of the stuff that more advanced tools can do. I liked showing folks that Coverity wouldn't just tell you that you forgot to check for null, but would show you how the null would get there from the call patterns. Quite impressive.