Ravi – Lua 5.3 with optional static typing
ravilang.github.io
ravilang.github.io
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.
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.
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.
"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.
It will run as fast as native code in non dynamic scenarios.
Yes, see 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.
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).
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.
Not necessarily true. C# has the dynamic keyword that bypasses the static typing and Java has the concept of Dynamic Proxies.
Not sure what you mean by "better". A "type" is a proposition about the program. You can't get more general than that. Any static checking system will have an interpretation in terms of types, so it's hard to see what could possibly be better than a type system. There are just different type systems with different properties.
lua sets the type depending on the value assigned at run-time. There are a lot of non-dynamic lanugages who pretend to have dynamic types (var)but actually just let the compiler deduce at compile time the assigned valuetype
Simple Crystal programs are valid Ruby scripts. I recently implemented a protobuf library in Crystal[1], and while the code for benchmark[2] is 100% valid code (no explicit typing), it runs 10 times faster due to Crystal beeing compiled instead of interpreted.
[1] https://github.com/teodor-pripoae/protokol
[2] https://gist.github.com/teodor-pripoae/da785e3985a69555040e
In the most basic sense, types can offer the size in bytes of the data.
They can also be used to verify that certain data can be used in certain ways.
If you look at C++ you can use polymorphism if you want a uniform interface and generality elsewhere. You can use templates if you want uniform data size and interface.
It's worth a read for anyone interested in this topic. I'm not sure why all the downvotes, but it seems like typing in general is not a concept that has stabilized among languages, is the point I'm trying to make. That languages are often adding or loosening typing notions is an interesting indication to me that it is a bit fickle.
But as the article I linked here points out, a lot depends also on what your particular definition of "type" is.
You gain the most from this, if you stay lua-native for the entire time- doing all calculations in the lua-vm, and are not depending to much on calls into the underlying c-programm (happy cache misses :( ).
Is there a optimization, that starting from the calls, creates dependancy trees, which allow to bundle away the calculation and calling of the call into seperate (pre-existing Tasks), in such a way, that the Result for simple-calls is in when the programm reaches the call?
I guess an XMPP server will deal mostly with strings, so the benefits from type annotations will be rather small.