[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua Naming Conventions
- From: Asko Kauppi <askok@...>
- Date: Wed, 27 Dec 2006 23:15:33 +0200
Jérôme VUARAND kirjoitti 27.12.2006 kello 4.35:
2006/12/26, Jimmie Houchin <firstname.lastname@example.org>:
Language communities often have desired conventions which make things
easier for the community. I did a search of the mailing list archives
and could not find anything regarding desired naming conventions
Are there any such naming conventions or best practices that I as one
learning Lua would benefit from following.
I think everything lower case without underscores seems to be the norm
in small snippets. This is partly because Lua is a weakly typed
language, variables can hold any type be it numbers, strings objects
or functions. And Lua being such a high level language, code is
usually very short and is therefore clear enough without additionnal
My 2 cents :-)
I agree with Jimmie,
Lua seems to need less conventions than some more format languages.
One thing I've found useful is commenting the types of parameters in
a function header, just above the code itself (kind of doxygen-like,
but informal, take your pick or don't but here goes:)
-- [str][,err_str]= serialize( val [,dump_mode_bool=false] )
-- Prepare 'val' into a string presentation that can be unwrapped using
-- val: number/ boolean/ string/ table (including subtables)/ nil
-- function/ userdata (if 'dump_mode'==true)
-- allows this function to be used for "dumping" data structures
-- without intention to read them back via 'm.deserialize()'.
-- _lev: INTERNAL PARAMETER (nil for outside calls)
-- +1, +2, ... for recursive table traversal
-- _catch: INTERNAL PARAMETER (nil for outside calls)
-- a table having so far handled tables as its keys (avoids
traversing cycled tables,
-- or copying shared subtables)
-- Note: Metatables of 'val' are ignored (not passed through
-- Table cycles and shared subtables are not allowed (tables
must be a tree).
function m.serialize( v, dump_mode, _lev, _catch )
The use of '_' prefix is there for parameters not used by the API
(but by recursive calls of the function itself).