-
Notifications
You must be signed in to change notification settings - Fork 432
CodeConventions
Florian Nücke edited this page Jan 27, 2014
·
5 revisions
If you'd like to contribute code and save me the work of reformatting stuff (which will also make it more likely for it to be pulled!) please try to stick with the following conventions:
- Be consistent.
- Indent using spaces, two wide. Do indent properly.
- Try to limit width of the code to 80 chars.
- Don't add spaces between braces/brackets and what's in them.
- Do use brackets in functions calls even if it's not necessary.
- Name variables for what they are, don't include type markers in them, i.e. do not use Hungarian notation.
- Nice to have: sort your requires alphabetically (OCD!)
- Only comment if it's something complicated/non obvious. Keep in mind that comments increase file size, which increases the amount of RAM required to run your program!
Bad:
function f(sArg1 , ... )
print(sArg1)
if sArg1 then
local nResult = 1
--do some more stuff
return nResult
end
end
if f ( "a" ) ==1 then
print"asd"
end
Good:
function f(arg1, ...)
print(arg1)
if arg1 then
local result = 1
-- We extrapolate the b-spline of the non-euclidean space to
-- determine the fraction of potential failures encountered.
return result
end
end
if f("a") == 1 then
print("asd")
end