54 points · by ihnorton · 12y ago · 70 comments
Why have we not seen an effort to build a solid ecosystem around it the way node has with JS? Lua with equivalent libraries to Python/Ruby/Javascript/PHP would be superior to any of them.
One thing that I think people get confused about Lua is that its simultaneously a VM, a language, and a very minimal framework, around which many, many things can be glommed. The glomming of those things is so flexible and versatile that - indeed perhaps we see too much diversity in the Lua appliance world, for there to be any common centralized traction around promoting it, as has happened with node.
If you want to see how Lua really has a solid ecosystem, then you have to look for projects that have embedded the VM and are using it as the basis for their application run loop. And indeed, there are plenty of projects out there doing this, that it can't really be said Lua doesn't have traction; it just doesn't attract as much hype. Lua has plenty of libraries; its just that the "FFI all the things!" approach means that you can, pretty much, indeed FFI all the things. No standards committee required!
Lua really ought to be considered JS done right and Eich should really have been given enough time to bring scheme to the browser (syntax could have been negotiable). Another interesting project is Typed Racket http://docs.racket-lang.org/ts-guide/index.html?q=typed and Guile http://wingolog.org if this sort of things interests you.
[4] http://www.keplerproject.org/
[5] http://luvit.io/
3. http://www.techempower.com/benchmarks/#section=data-r7&hw=i7...
Typed Lua says it only works with Lua >= 5.2. LuaJIT runs a language that is somewhere between Lua 5.1 and Lua 5.2, so it's not clear whether it will work with Typed Lua. The 5.2 requirement may just be to run tlc (and not the code it outputs), in which case you could run LuaJIT + Typed Lua + nice C libraries.
Language adoption is a very social thing though. Maybe if Rails was a Lua framework we would be wondering why Ruby never made it big.
Lua is embedded in things like Redis, and is often uses as an extension/configuration language for small projects.
I based my mail client(http://lumail.org/) around Lua as a configuration language because I kept getting annoyed by the almost-configuration-language used in mutt.
Actually writing applications in Lua is also possible, for example the chat/Jabber server Prosody.
Note though it does lack some syntactical sugar, and arguments not passed are silently 'nil', so it is not strictly superior.
Re: foreign libraries, as long as you are using TSD / DefinitelyTyped (http://definitelytyped.org/tsd/), that burden is crowdsourced. I've written a few library type declarations, but used many more from others. The flipside of the complaint is that I've found it really quite nice to have type checking for libraries I don't know inside and out. And you can always cheat and declare your external libraries as "any" for the sake of making the compiler happy, if you don't want to go through the effort to get the reward.
Obviously, to get something like DefinitelyTyped going, you need a critical mass of developers, so that may or may not work out for Typed Lua.
(There's also the whole external/internal module confusion in TS, but that's not related to the general theme of gradual typing per se, so it's not really relevant to non-TS contexts.)
This is also true of other systems like GradualTalk, and other systems like Typed Clojure have much more expressive type systems than TypeScript, even if they don't guarantee soundness in the presence of untyped code.
The designers of TypeScript went for simplicity first. This has real advantages, but also disadvantages, which you seem to be running into.
I know it's my own failing, but I've also had a lot of trouble with the incredible amount of parens and symbols in TR/TC -- I'm used to the near-math notation of Haskell dammit! :). It's just one of those things -- I have actually written non-trivial code in Scheme, but I've been spoiled by Haskell. Intellectually, I deeply appreciate the value of homoiconicity, but sadly I just can't get past the aesthetics.
EDIT: FWIW, if I were to go with gradual typing, I think TR would probably be close to ideal. It's an amazingly well thought-through language in terms of module system, integration of the macro system with modules, the syntax-parse macro system, etc. Kudos!
When combat happens, the attacker's triggered abilities will happen, then the defender's triggered abilities, then the attacker will attack the defender. Lots of triggered abilities interact with the attacker or defender, and some may cause it to die (it dies immediately, not at the end of combat). Subsequent triggered abilities might crash if they depend on the attacker or defender existing.
In my implementation, these triggered abilities are functions with signature
triggered_ability(player: Player, my_idx: number, my_card: Card,
skill_idx: number, other_idx: number, other_card: Card?)
Having the type system enforce null checks on uses of other_card (and also on all uses of cards from other zones, like the opponent's battlefield or the player's hand) would have saved me a lot of trouble. As it is, I use a fuzzer to play lots of games between AI players and look for errors, but most of the errors I look for could have been caught by a compiler instead.This includes things like typos (wrong method names, etc) but where types really shine is refactoring. If you want to add or remove a parameter from a function or change a string field to an integer then you can use guidance from the type checker to be sure that you didn't forget to update anything. Its a bit like adding bumpers to the side of the bowling lane - it lets you be more reckless, updating things until the compiler shuts up without needing to carefully go through each line.
---
Also, don't forget that gradual typing solutions such as Typed Lua are all about letting you program dynamically if you want. The idea is that you would only convert to the typed dialect in the parts of your program where that would suit you.
Also, projects written in statically typed languages are easier to read and navigate for humans and it's also easier to write static analysis tools for them.
Or build your large systems as compositions of smaller systems. If dynamically typed languages are really okay for smaller systmes, than avoiding bad architecture of large tightly-coupled systems in favor of loosely coupled compositions of smaller subsystems means that it is also okay for large systems.
> Also, projects written in statically typed languages are easier to read and navigate for humans
This is not my experience.
> and it's also easier to write static analysis tools for them.
Well, yes, since you have to write a static analysis tool for a statically typed language (since the compiler must include such a tool), its not at all surprising that the structure of statically-typed languages is always designed specifically to serve static analysis tools.
IME, that's why they've historically been harder to read and navigate for humans, though some exceptional modern statically typed languages have largely closed that gap (but not reversed it, IMO.)
It doesn't mean that at all. You might as well say "if shoes are good enough for going to the corner store, then multiple pairs of shoes are good enough for going to the moon". The notion that large systems are no more complex than small systems if you simply make the large system out of small systems is not supported by anything I can find.
>IME, that's why they've historically been harder to read and navigate for humans
That doesn't make any sense at all. How is having information written down instead of having to constantly remember and/or deduce it an impediment to reading?
You realize that you just planted a good solid troll magnet of the "I never make any type errors" variety. Some people get annoyed by the notion that you can enlist the compiler (using succinct syntax) to write and validate tests that they ought to be writing. They would rather write the tedious tests themselves.
@spankalee They had a blogpost along those lines, sadly not bookmarked, but you might be able to find it.
The VM basically throws the type annotations away. In production mode, the type annotations can be completely wrong and your program will still function, and still be just as fast.
What makes a language 'okay for smaller projects' but suddenly unsuitable when it gets larger? Having a minimal set of types doesn't necessarily mean you're going to have 'more bugs as the codebase grows' - the only place it really makes sense to say that dynamically-typed languages 'break' is when they don't have the types that the application needs.
In Lua's case, the only thing I can think of it missing is native floating-point support, and that's really it. Everything else: you can get there with nil, number, string, function, CFunction, userdata, and table. (But CFunction and userdata should be enough for anyone! :)
As projects get larger the benefits of tooling (automated testing, automated type checking, efficient compilation, etc) become more relevant and the costs of using the tools become less relevant compared to the costs of writing the program itself.
> the only place it really makes sense to say that dynamically-typed languages 'break' is when they don't have the types that the application needs
Actually, I don't think any dynamic languages used in practice actually do this right now. Most dynamic languages only check base types (numbers, null, "object") but fail to check for higher order types (functions and objects). For example if you code
MyClass x = new OtherClass();
x.foo();
wouldn't it be better to get an error in the first line than an error on the second line? Specially when you consider that the method call can be delayed and only happen much latter, in some other function and without the true guilty line even showing up in the stack trace.I think you're missing the point; static typing doesn't let you write more programs, it specifically lets you write fewer programs, by ruling out ill-typed programs. If I see a Haskell variable of type "Int -> String" then I can be quite confident that it's a function turning Ints into Strings; in, say, Python I can't be confident of much without analysing the entire codebase.
What makes it okay? This Python program will not throw an exception when ran
def f(x):
return x
if False:
f(1,2)
even though the types are wrong. Are you 100% certain that you will never make a bug like this even when there are 10^13 conditions and the call stack is deeper than the Mariana trench? Note that that this is not the only type of bugs that static typing prevents.One and one makes two. Two and two makes four. Four multiplied by eighteen is seventy-two.
Compare to:
1+1=2
2+2=4
4*18=72
Notation, aka language, has scaleability as a feature, whether the designers intended it or not. Dynamically typed languages are nice, I love them for prototyping, and some of them, I think, are suitable for large scale applications. But not all of them. The notations made available in some languages just make large scale development easier or harder (for various reasons). Consider using maps/json objects to produce data constructs, this is a sort of duck typing unless you add some sort of schema checker to it. At which point it's either a runtime error or you're running your code through a static analysis tool. Why not use an actual type system for this that the compiler checks at compile time?I feel like a broken record this past week.
Dynamic languages are good, I can't imagine doing the sort of exploratory/prototyping stuff I've done in them with typical statically typed languages. I wouldn't even object to using erlang for a large scale project (actually, I'd love to do this), it's got features in both syntax (bit syntax, I love it) and semantics (concurrency) that make it ideal for certain problem domains. It's got dialyzer which gets back a lot of the static analysis that statically typed languages offer. On the other hand, javascript offers duck typing, weak typing, dynamic typing, it's fine for certain applications (and essential for anything living in a web browser these days), but it's type system holds it back for large scale work. Experienced programmers may be able to get passed it with relatively few errors, but it's still going to suffer huge performance issues because there's only so much that can be known about the values passing through a block of code. Does `a + b` mean we're adding two numbers? A number and a string? two strings? The result changes depending on those circumstances and the interpreter/compiler just doesn't know enough to optimize it significantly. Similarly, it doesn't know that one is an error right away, the actual error may start here, but only appear in some function that's a child/parent/cousin in the call tree, obfuscating the cause and creating a great deal of work for the developer and tester.
Lua 5.3 (work 2 already available) introduces integer subtypes so now you can have both floating point and integers.
About the dynamic vs Static typing debate, I think it progresses firmly along Upton Sinclair'ish lines,
"It is difficult to get a man to understand something, when his salary depends upon his not understanding it!"
But googling something like static vs dynamic typing will give you enough results to choose from. Or go to your local Haskell user group meetup :-).