forked from luvit/luvit
-
Notifications
You must be signed in to change notification settings - Fork 0
Coding Conventions
hnakamur edited this page Aug 20, 2012
·
2 revisions
- DO use 2 spaces for indents
if luving_it then
print("yeah")
end
-
DO use camelCase for functions, eg
findOne()
,readFile()
-
DO use snake_case for variables, eg
first_pass
,skip_rest
-
DO use err as the first argument to ALL callbacks
function fetch(cb)
end
fetch(function(err, result)
if err then
print("Error: "..err)
else
print("OK")
end
end)
- DO use TitleCase for classes, modules and namespaces
local NewSchool = {}
NewSchool.detect = function(preferred_lang)
if preferred_lang == "lua" or preferred_lang == "node" then
print("Hello, luvit is async lua built on node's infrastructure.")
else
print("Hello old-school. Try luvit, you'll love it")
end
end
return NewSchool
- DO NOT use one line if statements. DO use multi-line if statements.
-- No Good
if err then return err end
-- Good
if err then
return err
end
- ?? File naming conventions are inconsistent. Should not be snake_case as they are modules.
- ?? How should
require
modules be named? egUtil = require('util')
orutil = require('util')
- ?? Should single quotes be preferred over double quotes?
- ?? Module headers
- ?? Function headers
- ?? Directory structure
project\
bin\ -- installable scripts
lib\ -- source library
modules\ -- project dependencies
vendor\ -- third party/vendor source not packaged as modules
test\ -- tests
init.lua -- main export module, eg `return require('./lib/project')`
package.lua -- metadata for package managers
LICENSE -- project's license
README.md -- readme file