10 ms·
Ravi – Lua 5.3 with optional static typing
- allan_s 11y agoCan projects like prosody (an xmpp server) runs on it ? Would it benefits from it ?
- perlgeek 11y agoAccording to http://the-ravi-programming-language.readthedocs.org/en/latest/ravi-overview.html#ravi-extensions-to-lua-5-3 http://the-ravi-programming-language.readthedocs.org/en/late... it seems to have only type annotations for integers and numbers (which I assume to be floating-point numbers) and arrays thereof. I guess an XMPP server will deal mostly with strings, so the benefits from type annotations will be rather small.
- hellofunk 11y agoI often wonder if the whole idea of "typing" is the wrong decision in language design, if we shouldn't come up with something better. Dynamic languages are often trying to insert some form of typing. Static languages are often trying to inject tools for heterogenous collections. It's clear there are advantages to both approaches, yet a languages is usually definitely one or the other, which seems limiting. Not that I have a solution, but perhaps breaking programs into primitive types or lack thereof isn't the right approach to the abstraction.
- Zergy 11y ago> yet a languages is usually definitely one or the other Not necessarily true. C# has the dynamic keyword that bypasses the static typing and Java has the concept of Dynamic Proxies.
- naasking 11y ago> I often wonder if the whole idea of "typing" is the wrong decision in language design, if we shouldn't come up with something better. 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.
- hellofunk 11y agoWell there is also a fair amount of supportive opinion on the contrary, that "better" is a system without types altogether, hence dynamic languages.
- PicassoCT 11y agotype-safety allows for the generating of far more efficient machine code. And you type your language everywhere, the difference is the time it happens and the consistency of the rules below handling type-conversions. 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
- ersoft 11y agoPlease check crystal [0]. It has syntax inspired from ruby, types are automatically infered, and it supports method overloading and metaprogramming using compile time macros. 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. [0] http://crystal-lang.org/ http://crystal-lang.org/ [1] https://github.com/teodor-pripoae/protokol https://github.com/teodor-pripoae/protokol [2] https://gist.github.com/teodor-pripoae/da785e3985a69555040e https://gist.github.com/teodor-pripoae/da785e3985a69555040e
- jdonaldson 11y agoWhat are you referring to by "inject tools for heterogenous collections?
- meric 11y agoI take it to mean like a map that can take any type as key or value.
- CyberDildonics 11y agoTyping becomes a tool for solving multiple problems and its uses become more vague under these terms. 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.
- hellofunk 11y agoThere is another paper linked in another HN thread at the moment: https://news.ycombinator.com/item?id=10405143 https://news.ycombinator.com/item?id=10405143 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.
- speedkills 11y agoSome static languages do have techniques for dealing with heterogenous lists. It is getting hard to find someone talking about a scala library these days without hearing them mention their use of hlist.
- cmrdporcupine 11y agoIf 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.
- bitmadness 11y agoThis is interesting, but the benchmarks suggest that LuaJIT usually does as good, if not better. So there doesn't seem to be much benefit to the static types, at least performance-wise.
- sundarurfriend 11y agoYeah, and the page itself further mentions additional benefits that LuaJIT has that Ravi doesn't, putting LuaJIT even further ahead. As an outsider to Lua, I assumed I was missing additional context (eg. limitations in applicability of LuaJIT maybe?) that necessitates the existence of Ravi.
- sitkack 11y agoOne reason to use (potentially) Ravi over LuaJIT is that LJ has a 2GB memory limitation.
- sitkack 11y agoSee also http://terralang.org/ http://terralang.org/
- PicassoCT 11y agoLua is a great little language. 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?