3 ms·
> How would you if you can't deternmine type in advance, check for the type it will be ? I don't understand. Compilers do this all the time. Just consider all
by naasking 10y ago
> How would you if you can't deternmine type in advance, check for the type it will be ? I don't understand.
Compilers do this all the time. Just consider all those programs that dynamically generate code based on objects that they haven't seen in advance, like object-relational mappers. Those can all be statically typed and ensure that they generate correct code [1].
> Absolutly not. Those are not linked to typing in any way, and any decent Python editor catch them.
It's all part of compilation, and furthermore, we can type check code generation so that names errors don't even occur in runtime generated code. Sorry, but all of these errors are related to type checking.
> AssertionError ? Serioulsy ? Do you even know what it does in Python ?
http://research.microsoft.com/apps/pubs/default.aspx?id=138696 http://research.microsoft.com/apps/pubs/default.aspx?id=1386...
Just google "static contract checking" to find plenty of work, including compilers already available for Haskell. Heck, code contracts have been widely deployed on .NET for years now.
> And LookupError, unless you got constant sized containers, which has nothing to do with types, you can't check that.
Please read the lightweight static capabilities paper I already provided. It demonstrates using the Haskell and OCaml type systems to statically assure that all array bounds are in range, even for dynamically sized structures. So yes, you can check that, which doesn't even go into dependent typing where checking such dynamic properties is the whole point.
> ArithmeticError ? Come on ! Are you numbers constants ? You need to check the inputs so that they belong to the domain of your problem, at that's it. Nothing to do with types.
You don't seem to realize that types are simply logical propositions about a program. They can be ANY proposition about a program, including that indexing is within bounds, that a concurrent program has no race conditions or deadlocks [2], that programs terminate, that HTML forms correctly serialize/deserialize values from/to structures [1], and more.
Like most dynamic typing enthusiasts, you don't have a proper appreciation for the true scope of static typing. You are correct that typing has its costs that aren't always warranted, but you are incorrect about where you draw that line because I don't think you fully understand how powerful static typing truly is.
[1] http://www.impredicative.com/ur/ http://www.impredicative.com/ur/
[2] http://www.kb.ecei.tohoku.ac.jp/~koba/typical/ http://www.kb.ecei.tohoku.ac.jp/~koba/typical/
- pmoriarty 10y agoJust a minor note that contracts are available in Python too, via PyContracts.[1] They are very useful. [1] - https://andreacensi.github.io/contracts/ https://andreacensi.github.io/contracts/
- sanderjd 10y agoI think there's a reasonable confusion here - people always talk about "static type checking" when what they really mean is a superset that might be more clearly referred to as "static checking" or maybe even "static analysis". It's true that type systems often improve static analysis capabilities, but I don't see why some useful analyses (like catching SyntaxError and probably NameError) couldn't be done for a language like Python. After all, the editors have basically already implemented it.