It also makes me mad, because by every metric save the what-you-already-know, Lua is at least comparable, if not outright superior.
If you're not worried about being "web scale", it's not hard to write an async socket server using luasocket's sockets for nonblocking TCP IO and luasocket.select for scanning for active connections. It gets bogged down once you have > 100 or so idle connections (the usual trade-offs with select apply), but it's easy to write, very portable, and (on x86) LuaJIT is amazingly fast. Contact me if you want example code.
I've been working on an actual framework for async servers (libev-based), but haven't had much free time lately.
Much of the complexity comes from error handling, not just the async IO. Erlang gets that right, too. I don't know how much error handling node.js does. (I plan on checking it out eventually, since my framework will be compared to it.)
I don't have a time frame yet. I'm also working on a compiler and a bunch of other stuff, and I'm really not a web developer, so it's been a fairly low priority.
The advantage is that you get to use the same tools for client-side development and server-side development. Testing tools, interactive development tools, editor tools, etc. When you don't have to build your toolchain twice, you can make your toolchain twice as good.
In theory. Javascript needs namespaces and modules before it will be useful for real work.
It's easy to slow the code down with "obvious" coding - which is a bad thing in a language.
Some other operations like metatable lookup might not be always the fastest.
But overall the convenience of having a 700K source tarball that compiles on any ANSI C into a modern language blows all these concerns away for my use. And the performance-critical parts can be easily pushed down to C. If they are not premature optimizations to begin with.
$ time lua -e 's="";for i=1,100000 do s=s.."-";end'
real 0m1.292s user 0m1.029s sys 0m0.108s
$ time lua -e 't={};for i=1,100000 do table.insert(t,"-");end; s=table.concat(t,"")'
real 0m0.284s user 0m0.062s sys 0m0.077s
times are somewhat bogus since it is cygwin under win7, but they give the impression of what I am talking about.
I do not argue it is a feature very coherent with the design of the language, and the immutable strings have other good properties. But if you do intensive string ops you need to watch out not to fall into the trap of treating the strings as mutable objects.
Don't get me wrong - I like Lua a lot and use it almost on a daily basis. Just that I think the posts like this may attract some new folks to try Lua out - and they deserve to know the obvious ways they can shoot themselves in the foot in order to avoid some disappointment.
$ time lua -e 't={};for i=1,100000 do table.insert(t,"-");end; s=table.concat(t,"")'
0m0.05s real 0m0.05s user 0m0.01s system
0m0.05s real 0m0.05s user 0m0.00s system
0m0.05s real 0m0.04s user 0m0.02s system
(Times on OpenBSD/amd64 4.7, Lua 5.1.4.)table.insert checks the table's length on each iteration, which dominates the string-handling time - len is O(lg n). If you just use the loop index (or otherwise cache it), it cuts the time in half:
$ time lua -e 't={};for i=1,100000 do t[i] = "-"; end; s=table.concat(t,"")'
0m0.02s real 0m0.02s user 0m0.00s system
0m0.02s real 0m0.02s user 0m0.01s system
0m0.02s real 0m0.03s user 0m0.00s system
Changing to i=1,1000000 gave me an avg. of 0.54s and 0.22s respectively. LuaJIT is probably also considerably better. (You could also just do t = string.rep('-', 100000), but that's not the point of your benchmark.)Lots of people write robust, real world code in languages they are only casually familiar with. That is how you learn a language well.
The other reality you're facing here is your career. While it is gradually slowing, our field moves quickly. You need to be constantly studying and reading and learning to be any good at it at all. The reality is: grow and keep up or stop and be left behind.
To me, a new language is an opportunity. “What insights do these people have?” “What new design patterns will I learn?” “What can I take from this to my daily coding jobs?” They excite me.
Lua feels like a simpler, cleaner Javascript.
--
You have lexical scope, anonymous and first class functions, and dynamic typing.
The parser is as simple as possible (LL(1), ie top down, without backtracking), and doesn't do any magic like declaration hoisting or semi-column insertion.
The only falsy objects are `false` and `nil`. `==` doesn't do any type conversion.
The addition `+` and concatenation `..` operators are different.
Some infix operators do automatic type conversion ( +, -, *, /, %, ..) between strings and numbers, but that's about it for weak typing. There's no octal to decimal conversion for strings with prepended zeros.
There's only one way to define objects. The `self` parameter is explicit for methods, but there's syntactic sugar to pass it automatically.
Scoping is similar: variables are global by default, which allows precise scoping for closures.
--
== Where the languages diverge:
You can do some magic with metatables and environments, but once again, the mental model is extremely simple.
The other major differences are coroutines (cooperative threads) and a "generic" `for` loop that allows to build custom idiomatic iterators.
At last, the array indexing starts at 1. This may sound like heresy to devout Dijkstra followers, but it's really not a big deal in practice.
--
[1]: http://www.lua.org/pil/ by Roberto Ierusalimschy, one of the author of the language.
In a video I saw, by one of the designers of the languages stated that this was the original purpose (engineers using this instead of C, with the low level details done by programming team in C).
Furthermore, the VM binary weights 200k. It is extremely portable (it uses the common subset of C89 and C++), and its code is a pleasure to hack.
[1] http://en.wikipedia.org/wiki/Category:Lua-scripted_video_gam...
Learning Lua on the other hand? If that's not utterly trivial, I'd be worried.
The biggest downside Lua always had was that it's deeply rooted in the embedded category, where it's hard to come out from. Tcl is one the market for ages and still doesn't have a proper culture of libraries. At least Lua has its "rocks", maybe that will make it a worthwhile candidate for the non-embedded sector, too. It's a much nicer language than most of its rivals.
Besides LuaRocks, there's a collection on the Lua wiki (http://lua-users.org/wiki/LibrariesAndBindings), and the mailing list (http://www.lua.org/lua-l.html) is very active.
And yeah - if you know Javascript, you won't have trouble learning Lua. It's like Javascript with less gotchas and better performance.
Not if you can also use it to write World Of Warcraft addons :)
http://nodejs.org/api.html#child-processes-89 http://www.sitepen.com/blog/2010/07/14/multi-node-concurrent...
... and yes, as others have pointed out, Node.js supports process forking, which is arguably the better model for CPU scaling in these types of services.
Last time I checked node.js and libraries for it (about a couple of months ago), I could not run the library I wanted on the latest version of the node.js because the API has completely changed.
Platform software that completely changes itself over a course of a couple of months ? Thanks but no thanks.
Disclaimer: It's been couple of months. Maybe the things have changed since then, will be grateful for an educational reply from someone who has used node.js, about its maintainability, especially for the use with third party libs.