42 ms·
If a type system can be easily escaped, does it really offer you much? If it's still transformed to run in the runtime of a late-bound dynamic typed language w
by cmrdporcupine 11y ago
If a type system can be easily escaped, does it really offer you much?
If it's still transformed to run in the runtime of a late-bound dynamic typed language where the types can't be used by the compiler to produce optimized code with early-bound type function/method dispatch, does it really offer you much?
I guess I don't really see optional static typing as giving the best of both worlds, as it cannot deliver on what a good static type system can give you.
- paulddraper 11y agoIt gives you something. Compare Facebook Flow or Google Closure Compiler. It gives you the flexibility of not having to prove types to the compiler sometimes, but the safety of proving it other times. And yet you can write both programs in a familiar language. You could do early binding. Closure, for example, transforms non-polymorphic functions into static functions. But you are correct that performance is not the primary objective; it is verification. I personally prefer static typing all the way. But it's possible to make a decent argument for optional static typing.
- SwellJoe 11y agoPerl 6 has gradual typing that is used for optimizations at run-time. So, it's possible to use optional types for optimization (even if this particular implementation doesn't do it yet). And, it sounds like that's actually the purpose of this project from the description. It doesn't even seem like it's trying to add types as a method of avoiding errors. And, the benefits of typed languages aren't necessarily all or nothing, and they aren't all performance-related. There are many kinds of error that can be revealed by adding type checks to a program, and just like adding more unit tests to an existing program can reveal existing bugs, adding type information could do the same (with arguably less tedium than writing basic unit tests just to confirm something is behaving correctly with a variety of input). If I can choose to add types to my function rather than writing unit tests that test a bunch of different data inputs, I would definitely prefer to add types. (Now, in the case of some type systems, like Perl 6, you can go crazy with bounds and other things within the type system itself...so you can not only say a function receives an Int, it can also say it receives an Int in the range of -1...43, and nothing else is acceptable). Types are certainly more fun than fuzz testing everything. None of those benefits require a program to be all-in on having typed data.
- chenglou 11y agoHow does Perl's bound check work? If it's compile time then wouldn't you need some form of dependent types?
- dikaiosune 11y agoI agree that a good static typing system gives you a lot more (especially regarding the "correctness" of programs when the type system can be escaped), but regarding your second point there's this quote from the linked page: "Ravi extends Lua with static typing for greater performance under JIT compilation." This project appears to be an optionally-typed superset of Lua WITH a modified runtime to support better typed JIT compilation.
- CyberDildonics 11y agoJulia is statically typed with the most general type being variant. It will run as fast as native code in non dynamic scenarios.
- ioddly 11y ago> If a type system can be easily escaped, does it really offer you much? Yes, see http://julialang.org http://julialang.org for a dynamic language with a rich type system. In many cases, the compiler can indeed optimize and catch errors at compile-time using provided type information. And Julia's methods are a great improvement over most dynamically typed languages reliance on object orientation, IMO. But I would be hesitant to call it "optional static typing," since, as you say, it cannot offer the guarantees of static typing.
- yummyfajitas 11y agoNo, it can actually offer the guarantees of static typing within statically typed functions. function match_books(bids::Array{Bid,1}, asks::Array{Ask,1}) ... end I have static guarantees on the type of bids, asks, and anything else inside `match_books`. Outside, you might attempt to pass nonsense in and get a runtime error. But inside, I can rely on static guarantees and so can the compiler (this is why Julia is fast).
- discreteevent 11y agoStatic types give me three things: Static analysis, safety and performance. With optional static types you get the analysis with some safety and maybe a little performance. Safety is a time saver. Without static types you have to write a lot more code in the form of unit tests than amount of code it takes to put in some type annotations. Static analysis is an even bigger time saver. Suppose I have to decipher someone else's code (or even my own). I can get a machine to definitively show me the call hierarchy of a function. That's not just all the call sites, but the complete call stack for every case. This immediately gives me a huge insight into the design (or lack of it) of the program. To do this with grep or a debugger potentially increases that time exponentially.