lua-users home
lua-l archive

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


On Fri, Oct 26, 2012 at 4:47 AM, David Collier <myshkin@cix.co.uk> wrote:
> The 'style' I was thinking of was how one would write the code to do the
> equivalent of what is common in C. I thoiught the Lua equivalent seemed
> to need many more lines of code, and was wondering if I had missed
> something.

first, more lines is not necessarily a bad thing.  some languages
purposely avoid multi-faceted syntaxes (i.e. assignment as an
expression) to make it clear to a reader which is the sole use of each
statement.

second, it's not uncommon that directly translating makes text grow.
The real measure of code density is on a newly rewritten code.  Part
of the attractiveness of high-level languages is to make it easy to
use higher-level structures as a basis (i.e. a Lua table vs a C array)
or more natural algorithms (i.e. good recursion with tail-call
optimization)

That said, i find C's code density a very nice thing and do enjoy
reading reasonably tight code.  But in Lua, i tend to use a lot more
whitespace and short lines.  Beauty is not only in the eyes of the
beholder, but also changes with the medium.

-- 
Javier