lua-users home
lua-l archive

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


David,

When working on nutria project I was in troubles about applying which coding standard to lua, because, AFAIK there is no official choice. So I have decided to use a Drupal Conding Standards: http://drupal.org/coding-standards, weird but helped my eyes a lot :)

Take a look to the code and you will see what I mean: http://gitorious.org/nutria

Blessings.

--
Fernando P. García, http://www.develcuy.com
+51 1 9 8991 7871, Calle Santa Catalina Ancha #377, Cusco - Perú

** Before printing this message, please consider your commitment with the environment, taking care of it depends on you.
** Antes de imprimir este mensaje piensa en tu compromiso con el medio ambiente, protegerlo depende de tí.

---- On Fri, 02 Jul 2010 21:31:15 -0500 David Manura <dm.lua@math2.org> wrote ----

On Thu, Jul 1, 2010 at 5:18 PM, liam mail <liam.list@googlemail.com> wrote:
> If I were to be totally honest the thing which I dislike most about Lua is
> the keyword 'local', I dislike typing it over and over again and that the
> fact the default scope is global. Having edited third party code, it also
> seems to encourage the use of the globals although this is not to say that
> the same authors would have used scoped variables in other languages.

The "Huffman encoding" language design principle in Perl says that
common operations should have shorter syntax than less common
operations. A slightly different formulation expressed in the Lua
community is that dangerous operations should look ugly [1]. In Lua,
we have "a=b" for re-assignment or, if coding policy permits [2],
global variable definition, and we then have the longer "local a=b"
for lexical variable definition. In the interest of minimizing
complexity (number of plausible states), users should strive to use
lexical variable definitions and minimize use of variable
re-assignments and globals, but the syntax may encourage the opposite
here. The same criticism could be said of other procedural languages,
but a number of these use the shorter keyword 'var' [4], and Perl has
an even shorter though curiously named 'my'. The Go language also has
a short-hand: using "a := b" rather than "a = b" is analogous to
"local a = b" in Lua. Regardless of syntax though, the linter [2]
could limit the use of '=', and one's text editor could use color and
font to make less desirable operations like mutating assignment and
global variable definition more prominent [3], or in a way more
"expensive" syntactically.

BTW, concerning the relationship between Lua syntax and user coding
practice, what I see regularly is poorly indented Lua code when Lua is
used embedded (and perhaps not by professional programmers). Baring a
draconian approach like Python, the solution again may be the linter
and text editor offering assistance.

[1] http://lua-users.org/lists/lua-l/2010-05/msg00481.html
[2] http://lua-users.org/wiki/DetectingUndefinedVariables
[3] http://lua-users.org/wiki/LuaInspect
[4] _javascript_, Go, and to some extent C#