I'd like to create a language that is as much like Lua as possible, but adds just enough to make it static and type-safe. Specifically:
- all variables must be defined before use.
- all variables and function parameters must have a type specified. though it would support "auto" that can infer the type from the initializer. there would be typenames for all of lua's built-in types, and classes would have names too.
- there would be a "class" construct. just enough to let you specify the class name, parent class, maybe abstract interfaces you implement, and then a class definition inside curlies.
- inside a class definition, you would define your instance methods with the same syntax that you declare faux instance methods in Lua today.
- inside a class definition you can also put instance variables.
- class methods and instance variables can be public, private, protected, etc.
- objects would show up as a "userdata" in Lua, which would let you use them just like regular Lua faux classes, except that referencing nonexistent fields would throw an error.
The benefits would be:
- Static Lua and Lua could operate seamlessly.
- Static Lua would have much better performance because (1) type checks would be performed at compile time instead of runtime, (2) property accesses could be array offsets instead of hash table lookups, and (3) all types are known at compile time so the compiler could generate much more optimized code.
- Static Lua would have all the benefits of static languages, and Lua would have all the benefits of dynamic languages. But they would both be runtime-loadable, and could both be JITted using LLVM.
And to Java people who would say that I'm re-inventing the JVM, I would like to remind you that I happen to actually care about memory footprint, startup time (scroll all the way to the bottom to find Groovy), and having a lightweight (small, easy-to-distribute) runtime embeds nicely and plays well with others. Maybe the right implementation of Java would be what I'm looking for, but I'm not that interested in a joining a language community that has demonstrated for 15 years that it has no regard for such things.
I'm a die-hard minimalist, and will never be satisfied building on top of runtimes that do not have the same appreciation for minimalism. There's a reason zlib (for example) is absolutely everywhere you look today. It's the tiniest and most unobtrusive C library you could possibly imagine for doing compression. There is absolutely nothing about it that can make anybody say "it has great functionality, but [I only have 64k of RAM]/[I need to compress 1TB streams with much less than 1TB of RAM]/[I need to have control over all memory allocation]/[I need to be able to impose hard limits on its resource usage].". No matter what you're doing, zlib is there for you, because it imposes the absolutely minimal amount of requirements on whatever is embedding it.
I want the same to be true for Gazelle, my protobuf implementation, and pretty any software I'm writing for the ages.