lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


In message <20030815120011.GA1344@digital-scurf.org>, Rob Kendrick writes:
> Hi guys,
> 
> A friend of mine recently looked into Lua, and had some concerns with
> the way it is.  I've listed his points here (each line prefixed with **)
> and my proposed reply.  I claim not to be a Lua guru, so I'm asking for
> some advice on my answers. :)

Mostly your reponses seem fine.

> * Coroutines miss the point.
> * coroutine.yield(...) should just be shorthand for
> * coroutine.resume(coroutine_that_resumed_me, ...)
>   That they may, but they're still functionally useful.  I'm sure if you
>   raised the issue with them, they'd add the functionality you'd like.

Lua coroutines are more flexible.  Your friends approach is limited.  If
they really want it like that it's not hard to make some wrapper
functions to do it is it?

> * The specification isn't nearly rigorous enough. 

Actually I've not found anything significant that isn't in the
documentation (somewhere).  The documentation does rely on knowing C
(because many behaviors are inherited from C).

> * Semicolons essential sometimes but not always. 
>   The need for what is normally treated as meaningless in some cases
>   to make them unambigious is not unique to Lua.  (C++ suffers from
>   this, too).  And you can always insert a newline and make your
>   code more readable anyway.

This is _feature_ not a drawback, the best way to think about it is that
the statement terminator is either ';' or newline.  BASIC is like this
(with respect to ':') as is BCPL, and awk; it is not exactly an unusual
feature in a language.  If your friend is jittery then always
insert semicolons.  It'll make it feel more like C as well.  I'm
surprised your friend didn't complain about "begin" and "end" instead of
'{' and '}'

> * The whole syntax looks a little fragile, in terms of giving unexpected
> * results rather than errors, if you get things wrong. 
>   This is a personal source code style.  I don't find it fragile at all.

I don't find it fragile either.  And if I have a problem the syntax is
so small that it is easy to check the grammar.

> * Undefined division-by-zero behaviour. 
>   I'm not so sure on this one - 1/0 returns inf.  I seem to have bells
>   ringing in my head about making division-by-zero behavior consistant
>   is unportable.

He's right (or was in Lua 4).  Lua's division by 0 behaviour is
inherited from C, which states it is undefined.  Some architectures
return the appropriate infinity others raise the appropriate exception
(signal) others yet no doubt do something completely garbage.

It's not hard to hack the VM to raise a lua error on division by 0.  I
have done it in the past.  I doesn't even slow anything down really.

> * If there's a way to remove elements from tables, I missed it.
>   You did.  table.remove()

foo.bar = nil
foo[1] = nil

Cheers,
 drj