3 ms·
This sentence deserves to be examined for alternatives: "To make all this work, you have to insert runtime checks between the typed and untyped portions of the
by susan_hall 11y ago
This sentence deserves to be examined for alternatives:
"To make all this work, you have to insert runtime checks between the typed and untyped portions of the program."
That makes it sounds as if there are 2 choices:
1.) insert runtime checks
2.) don't insert runtime checks
I'll point out that many platforms (in particular, the JVM) allow us to pursue a 3rd option:
3.) insert runtime checks in development and whenever you are debugging, but strip them out when you are in production and things are going well
You can fill your code pre and post assertions on functions. These slow your software but they give you most of the benefits of gradual typing. You can run your code with these assertions whenever you need to debug. But if you ever want a speed boost, and you feel like your software is stable and bug-free, then you can simply pass a flag to the JVM compiler, and it will strip out the assertions for you.
- lindig 11y agoShort of a formal proof (or a sound type system), you can't be sure that you never hit a type error in production that now wouldn't be caught.
- whoisthemachine 11y agoTypescript (an extension to JS that adds type-safety) essentially does option 3 as well. As the sibling noted, there are instances during runtime where the type checking fails, especially because Typescript is compiling to Javascript. I have had moments where a numeric observable in KnockoutJS had to be forced to a number when receiving a new value; the form that the observable is bound to is simply returning a string, and while the TS interface for KnockoutJS says the observable is a number, the actual JS doesn't care and just returns what the form gives it. In some ways this is a failing of Typescript; it shouldn't allow strongly-type interfaces to be wrapped around JS that can return varying types.
- spankalee 11y agoTypescript doesn't insert any runtime type checks at all. It also can't know that interfaces for raw JS are typed wrong, because Typescript is only a static checker. Dart in checked mode does insert runtime type checks, but leaves them out in production mode.