I second this. Explicit type declaration should be optional, not mandatory. Type inference isn’t exactly new technology.
105363 items (97572 unread) in 19 feeds
Friends
(1021 unread)
Build
(68091 unread)
Heads
(716 unread)
News
(27537 unread)
fun
(207 unread)
I second this. Explicit type declaration should be optional, not mandatory. Type inference isn’t exactly new technology.
I’d like to see more languages outside of the “purely” functional space (Haskell, OCaml) using type inference. Typed, but no types to type. Boo and hAxe are the only imperative/oop language I know of that do this.
Thanks for chiming in Matt — actually part of the reason I wrote this entry was in hopes that you’d offer your insight about it. I think that with a combination of the strategies you mention as well as just a tiny bit of metaprogramming that only lets you assign to a predefined list of keys, I can get enough of what I need that I’ll be satisfied that the compiler can grow but stay understandable. Or maybe I’m just telling myself that because I have no other real choice at this point.
A statically-typed language that lets you load run code on the fly as easily as today’s scripting languages seems totally possible, especially now that LLVM is getting so good. I think there’d be a market for this, especially if it was paired with a dynamic language that worked together with it (a la Java and Groovy, but without the enormous and high-overhead virtual machine).
I haven’t worked in Lua, but I’m writing hundreds of lines a week in JavaScript, which is essentially another “table-based” language.
For avoiding the “prediction[1]” problem, I think the best discipline is: never use integer-indexed arrays in place of structs or tuples. You can use a same table, but always use meaningful names as keys:
prediction = {edge=predicted_edge, dest=predicted_dest_state}
If you start losing track of which keys are available for which object, simulating classical OOP can be useful. I see you’re already doing this in gzlc for some objects, but not for smaller structs like “prediction” above. It looks like Lua also supports Lisp-style closures-as-data-hiding, which I often use for small bits of data in JavaScript where setting up a “real” class or protytype isn’t worth it.
One more thing I’ve done is use JSDoc (in your case, LuaDoc) to document function and variable types. It gives some of the readability benefits of static typing, but of course with no real guarantees since it’s not enforced by the compiler.
I’m definitely with you on static typing, even though I’m a long-time JS/Ruby/Python user. Especially after playing with Haskell recently, I’m pretty unsatisfied by the lack of static analysis in those languages.