6 ms·
I don't see why anyone would want runtime type checking the way AtScript does it. With static typing, the compiler can catch type errors early, at the cost of
by lars 12y ago
I don't see why anyone would want runtime type checking the way AtScript does it.
With static typing, the compiler can catch type errors early, at the cost of rejecting some otherwise valid programs.
With dynamic typing, that type checking is delayed until execution time. More programs are valid, but type errors are caught late.
With AtScript-style late type checking, they took the dynamic type system and introduced more type errors. This decreases the amount of valid programs, yet catches no errors at compile time. It does nothing but increase the amount of bugs.
- nawitus 12y agoYou want both. Compile-time checking is necessary but not sufficient. Applications are not monoliths anymore, and web applications especially will interact with multiple other processes and services. For these you really need dynamic type checking. You can either try to do it in an ad hoc way in the application code, or building the check into the language.
- mintplant 12y agoYou might be interested in this paper. http://www.cs.umd.edu/~aseem/safets.pdf http://www.cs.umd.edu/~aseem/safets.pdf It describes an extension to TypeScript that includes efficient runtime type checking. They encode type information only in situations where checks are necessary, and only information that cannot be otherwise deduced from the context.
- hderms 12y agoare you talking about the typing of data received from outside sources?
- nawitus 12y agoExactly. And even when you receive data from your "own" services that you have type definitions automatically generated for, maybe there's a version mismatch in a deployment somewhere and so on.
- smrtinsert 12y agoCompletely agree 100%. Hopefully Typescript isn't merging any sort of runtime type checking.
- the_gipsy 12y agoI think angular is not after runtime type checking, like the TypeScript compiler. I think what they're after is keeping type information beyond `instanceof`, like keeping information about interfaces and the ability to access type properties beyond `Foo.prototype.bar`. Edit: to clarify, runtime type information should not be used to check for types again, but rather to do things similar to Java's reflection.
- xxgreg 12y agoThe angular team designed atscript. Have a look at their doc. It does contain runtime type checking and it looks like this: var length = rtts.type(name.length, rtts.int); https://docs.google.com/document/d/11YUzC-1d0V1-Q3V0fQ7KSit97HnZoKVygDxpWzEYW0U/edit https://docs.google.com/document/d/11YUzC-1d0V1-Q3V0fQ7KSit9...
- the_gipsy 12y agoYou're right, sorry.
- bceagle 12y agoYou would almost never use the runtime checking in production. This is an optional feature that you would only use in development.