Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
lua_conventions [2015/03/08 09:28]
vexatos
lua_conventions [2016/06/15 06:46] (current)
payonel
Line 9: Line 9:
   * Name variables for what they are, don't include type markers in them, i.e. do not use Hungarian notation.   * 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!)   * 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!+  * 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 load 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"​).   * 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"​).