News for hackers. Stuff that matters.
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by KirinDave on Wednesday October 13, 2010 @03:06AM (#1786379)
Attitudes like yours make me sad, on many levels.

It also makes me mad, because by every metric save the what-you-already-know, Lua is at least comparable, if not outright superior.

Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by ay on Wednesday October 13, 2010 @07:50AM (#1786794)
Strings operations is a tricky part though.

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.

Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by silentbicycle on Wednesday October 13, 2010 @08:40AM (#1786877)
How are string ops tricky in Lua? Patterns and table.concat can get a lot done, and when you need more power, there's LPEG (which is also quite speedy).
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by ay on Wednesday October 13, 2010 @09:39AM (#1787017)
"Patterns and table.concat can get a lot done" - sure. but it is may feel somewhat backasswards :-)

$ 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.

Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by silentbicycle on Wednesday October 13, 2010 @09:52AM (#1787052)
Context: Since Lua strings are immutable (and interned, like Erlang atoms, Lisp symbols, etc.), tables can be used as string buffers, and concatenation to large strings can be done in one step via table.concat. Appending to a string in a loop is slow, but that's true of any language with immutable strings.

$ 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.)
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by maushu on Wednesday October 13, 2010 @06:59AM (#1786727)
There is also the code reuse factor. Why learn/use yet other language if you can use javascript for both server and client?
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by gurraman on Wednesday October 13, 2010 @07:12AM (#1786748)
Better yet, let's go back to using ALGOL or something. Imagine how many reusable components we could have mustered up. We'd best stop all this innovation right now before it's too late.
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by maushu on Wednesday October 13, 2010 @03:05PM (#1788426)
Hmm, browsers don't use ALGOL though, better stay with JavaScript.
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by gurraman on Wednesday October 13, 2010 @09:26PM (#1789511)
Yes, but if the old geeks had been arguing like you did, the browsers would probably only support whatever language was popular on the server-side at that time.
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by jpiet on Wednesday October 13, 2010 @07:09AM (#1786739)
problem is: you cannot use it for both server and client. if this were true you would've been right. with node.js you still need to be aware if you're coding client or serverside for some constructs.
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by jrockway on Wednesday October 13, 2010 @09:11AM (#1786947)
Not really a problem; clients and servers always use different APIs in other languages. JavaScript is no difference.

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.

Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by rbranson on Wednesday October 13, 2010 @09:13AM (#1786952)
Without getting into a huge my language vs your language debate: I agree that this isn't the RIGHT attitude, but it's not about me learning Lua per say, it's a reality of writing code in the real world for real projects.
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by KirinDave on Wednesday October 13, 2010 @11:33AM (#1787461)
> I agree that this isn't the RIGHT attitude, but it's not about me learning Lua per say, it's a reality of writing code in the real world for real projects.

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.

Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by rbranson on Wednesday October 13, 2010 @01:01PM (#1787862)
Again, I agree with you on all points. I can't count on my hands the number of languages I've tried out and written a decent bit of code in, learning things along the way. However, that doesn't translate into "I should use this platform for a business-critical application."
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by KirinDave on Wednesday October 13, 2010 @02:04PM (#1788184)
Seems strange to decide on node.js if that's the problem. Node.js is by far less proven than Lua.
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by silentbicycle on Wednesday October 13, 2010 @03:50PM (#1788601)
No kidding. Lua has been used in production in industry for over 15 years.

http://www.lua.org/history.html

Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by Tichy on Wednesday October 13, 2010 @03:56AM (#1786470)
Is there a framework for writing asynchronous servers with Lua?
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by silentbicycle on Wednesday October 13, 2010 @08:12AM (#1786836)
Working on it. Libev-based. It's a spare-time project of mine. I have the "portable but not particularly scalable" pure Lua and luasocket backend done (for easy development + light deployment on Windows), working on the error handling in the libev backend now.

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.

Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by moonpolysoft on Wednesday October 13, 2010 @04:15AM (#1786501)
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by silentbicycle on Wednesday October 13, 2010 @08:38AM (#1786871)
I don't think that's what Tichy meant. That's just a wrapper library to make error handling easier in a coroutine-based event loop.

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.