views:

680

answers:

5

Lua occupies a good place in the space of languages that can be embedded. Is this a result of interesting new ideas the implementors had, or is it a result of good execution of well-established ideas?

Comparison of properties and features of Lua to other PLs are particularly appropriate.

+1  A: 

Lua is small, the total code is only tens of thousands lines in ANSI C. (Python has ten times mores lines of code).

Lua is very stable, or say, the language is fixed now.

Lua has good engineering. Its code is easy to read and hack. (also because small)

Its license permits you do whatever you want.

Writing C extensions in Lua is easier than other languages, say Python.

Yin Zhu
So this all counts as good engineering, rather than anything to do with language design?
Charles Stewart
No, there's much good engineering, but there are innovative design decisions, as Norman pointed out. Read the HOPL paper.
lhf
+1  A: 

I think this is because Lua is relatively simple and pragmatic. It doesn't try to be the language to build the next operating system, Crysis 3 or a SAP clone, but what it does, it does well, i.e. serving as a scripting language.

ammoQ
+1  A: 

Lua supports functional programming and it's based on Prototype-based programming style, which is flexible and powerful.

IMO it's an interesting language.

If you want to read some thoughts about prototype inheritance, I suggest you to
read Steve Yegge's The Universal Design Pattern blog post.

Nick D
Thanks: the link is interesting. Work on Lua began in 1993, 3 years after the release of Self, and 7 years after Borning's "Classes versus prototypes in object-oriented languages". Did Lua introduce new to prototype-based programming?
Charles Stewart
@Charles, I've only experimented with prototypes in Lua and I don't really know the answer to your question. Maybe someone else can shade some light on that.
Nick D
Sure. It's certainly interests me that I can't think of an earlier prototype-based language that gained wide usage.
Charles Stewart
+28  A: 

Is Lua interesting, from a programming language design perspective?

Yes! My day job is to study programming languages, and Lua will repay careful study. I would say that about very few other languages (perhaps Icon and CLU). Please note that it is the language as a whole, not the individual features, which makes Lua so worthy of study.

Is this a result of interesting new ideas the implementors had, or is it a result of good execution of well-established ideas?

Both. For the details, your best source for an answer to this question is the paper The Evolution of Lua, which appeared at the Third ACM Symposium on the History of Programming Languages. But I will add a few comments.

  • The use of Lua tables as the only mutable, non-atomic type of data was invented by the Lua team. They were inspired by developments in CLU, and I believe they were aware of similar work in Awk and Icon, but the refinement to this degree is an important contribution of the Lua team.

    Tables also have a very efficient implementation, which was invented by the Lua team.

  • The functional features of Lua have the same semantics as Scheme, but Lua has a unique implementation of first-class functions, which I think they ought to submit for publication in the Journal of Functional Programming.

  • The API for embedding has been greatly refined over the years. Its main distinguishing characteristic is that user-defined abstract types can participate fully in the embedding. This is the property that makes the Lua API superior to the Tcl API, for example. The Lua API has undergone a great deal of refinement over the years, including since its first publication at version 2.5. The Lua designers deserve a great deal of credit here.

  • The garbage-collection technology is standard.

  • Lua coroutines represent a new take on some very old ideas. The new take was considered worthy of publication in ACM Transactions on Programming Languages and Systems, so again I think the Lua team get credit for originality.

  • Lua metatables are related to the Common Lisp metaobject protocol.

I think that Lua's success result from a unique combination of strengths of the Lua team:

  • If you read the HOPL paper, you'll see that the Lua team were well aware of many developments in programming languages and were able to choose from among the best ideas. Most designers of popular scripting languages have been amateurs and have not been nearly so well informed.

  • Lua is superbly designed so that the pieces fit together very nicely, with an excellent power-to-weight ratio. This is the result of a lot of refinement over time, and PUC-Rio was willing for the Lua team to work on the language design and implementation instead of grinding out a huge number of papers. This work could not have been done at a North American university.

  • Lua is superbly engineered. The implementation is just staggeringly good. That's partly great work by great engineers and partly the opportunity to keep revising the design over a 15-year period.

I'll close by asking readers not to underestimate the difficulty of choosing and refining well-established ideas to form a coherent whole. This is extremely difficult work and is seldom recognized as it should be.

Norman Ramsey
+1: very good answer
Nick D
For the time being, see "The implementation of Lua 5.0" at http://www.lua.org/doc/jucs05.pdfWe're working on that paper, Norman, but Lua 5.2 is getting our attention right now...
lhf
The TOPLAS paper, Revisiting Coroutines, was discussed on LtU, which for some reason I didn't pay attention to : http://lambda-the-ultimate.org/node/2868
Charles Stewart
A: 

There's a Lambda the Ultimate story, Small is Beautiful: the design of Lua, discussing Robert Ierusalimschy's recent talk at Stanford of the same name. The discussion currently focusses on the merits of having tables as the only container data structure; so far, little has been said on the other part of the talk, dealing with Lua's C interface.

Charles Stewart