Hello, all.. Where can I read something about Lua programming conventions? I mean programming conventions labeling local and global variables, table fields, Lua variables in modules, variables in namespaces etc. etc... When names are written in capital letters, sign reserved for system variables, etc.? Thanx Jarda
On Wed, Sep 29, 2010 at 8:30 PM, Jaroslav Hajtmar
Hello, all.. Where can I read something about Lua programming conventions?
I mean programming conventions labeling local and global variables, table fields, Lua variables in modules, variables in namespaces etc. etc... When names are written in capital letters, sign reserved for system variables, etc.? http://www.lua.org/pil/ and context *lua files
-- luigi
Hi, besides that what Luigi wrote, I'd recommend the Lua users wiki. Don't take everything there as "perfect" or "the official way", as it is just a users wiki, like our wiki. http://lua-users.org/wiki/ Patrick
On Thu, 30 Sep 2010 10:47:42 +0200, Patrick Gundlach
Hi,
besides that what Luigi wrote, I'd recommend the Lua users wiki. Don't take everything there as "perfect" or "the official way", as it is just a users wiki, like our wiki.
Hello, I'd say there is no universal naming convention. For example I found local variables written with upper case (http://lua-users.org/wiki/AsciiMenu) ("local DASHES = string.rep('-', 80)") - it is not very common in programming to name local variables with upper case. But in this case - - it was probably to mark the variable as CONSTANT (as Lua doesn't have "const" keyword like C, where uppercase names are generally used for macros as constants or enums). So: - namespaces (modules) are generally named with lowercase names ('mynamespace.') (like in C? 'std::', 'boost::'), - variables are generally named with lowercase names ('_' may be used inside, so we get 'myvar' or 'my_var') - - constants with uppercase? ("local PFX = '#'"?) May be. - - global variables? One may prefer prefixing such variables somehow, so we get '_my_pfx' (or '_MyPfx' or '_myPfx')? (In C/Cpp, personally I use the 'g' prefix and camel notation, so I get 'gMyVar', opposite to all other vars with lowercase names like 'my_inner_var'.) But if a variable is to be global, it's better to encapsulate it to a namespace; thus "mark of globality" in the name gets unnecessary as we access the variable like 'mynamespace.var' (it's obvious the variable is global for that namespace). - functions? Naming like 'thisIsMyFunction()' (camel convention) is quite often, but one may prefer C-like naming ('this_is_my_function()' - so like internal variables?) or "TeX" convention ('thisismyfunction()') (natural to standard function, so we don't have 'string:g_sub()' or 'string:gSub()' but 'string:gsub()'). I'd say this to a wider discussion. You may get inspired from existing code as Patrick wrote, or e.g. to have a look into .lua scripts in ctx minimals. Lukas
Thanx Lukas Thanks for the comprehensive answer - I needed to know. Codes for own use probably does not make sense to solve, but I started to write a separate public ConTeXt module with many Lua code, so I want to meet Lua code conventions. I also have my habits, but I want to code written as it should be. Thanx Jarda Dne 30.9.2010 11:35, Procházka Lukáš Ing. - Pontex s. r. o. napsal(a):
On Thu, 30 Sep 2010 10:47:42 +0200, Patrick Gundlach
wrote: Hi,
besides that what Luigi wrote, I'd recommend the Lua users wiki. Don't take everything there as "perfect" or "the official way", as it is just a users wiki, like our wiki.
Hello,
I'd say there is no universal naming convention.
For example I found local variables written with upper case (http://lua-users.org/wiki/AsciiMenu) ("local DASHES = string.rep('-', 80)") - it is not very common in programming to name local variables with upper case.
But in this case - - it was probably to mark the variable as CONSTANT (as Lua doesn't have "const" keyword like C, where uppercase names are generally used for macros as constants or enums).
So:
- namespaces (modules) are generally named with lowercase names ('mynamespace.') (like in C? 'std::', 'boost::'),
- variables are generally named with lowercase names ('_' may be used inside, so we get 'myvar' or 'my_var')
- - constants with uppercase? ("local PFX = '#'"?) May be.
- - global variables? One may prefer prefixing such variables somehow, so we get '_my_pfx' (or '_MyPfx' or '_myPfx')? (In C/Cpp, personally I use the 'g' prefix and camel notation, so I get 'gMyVar', opposite to all other vars with lowercase names like 'my_inner_var'.) But if a variable is to be global, it's better to encapsulate it to a namespace; thus "mark of globality" in the name gets unnecessary as we access the variable like 'mynamespace.var' (it's obvious the variable is global for that namespace).
- functions? Naming like 'thisIsMyFunction()' (camel convention) is quite often, but one may prefer C-like naming ('this_is_my_function()' - so like internal variables?) or "TeX" convention ('thisismyfunction()') (natural to standard function, so we don't have 'string:g_sub()' or 'string:gSub()' but 'string:gsub()').
I'd say this to a wider discussion. You may get inspired from existing code as Patrick wrote, or e.g. to have a look into .lua scripts in ctx minimals.
Lukas
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________
participants (4)
-
Jaroslav Hajtmar
-
luigi scarso
-
Patrick Gundlach
-
Procházka Lukáš Ing. - Pontex s. r. o.