mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-08-03 19:17:27 -04:00
Updated CodeConventions (markdown)
parent
0c24523368
commit
77f61aca7e
@ -10,11 +10,12 @@ Lua
|
||||
- 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!
|
||||
- If you have to validate arguments, use the built-in `checkArg` method. Homogenous error messages are a good thing! Its usage is `checkArg(n, value, type1, ...)`, where `n` is the number of the argument, `value` is the value of the argument and `type1` and so on are the allowed types for the argument, as retrieved via `type(value)`. The number is used in the error message like so: "bad argument #n (type1 expected, got type(value))". So for example, to require the first argument to be a number you'd do `checkArg(1, arg, "number")`.
|
||||
|
||||
Bad:
|
||||
```lua
|
||||
function f(sArg1 , ... )
|
||||
print(sArg1)
|
||||
assert(type(sArg1)== "string", "me wants a strign!")
|
||||
if sArg1 then
|
||||
local nResult = 1
|
||||
--do some more stuff
|
||||
@ -29,7 +30,7 @@ end
|
||||
Good:
|
||||
```lua
|
||||
function f(arg1, ...)
|
||||
print(arg1)
|
||||
checkArg(1, arg1, "string")
|
||||
if arg1 then
|
||||
local result = 1
|
||||
-- We extrapolate the b-spline of the non-euclidean space to
|
||||
|
Loading…
x
Reference in New Issue
Block a user