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 [2016/06/15 04:46]
payonel
lua_conventions [2019/08/05 22:02] (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 obviousKeep in mind that comments increase file size, which increases the amount of RAM required ​to load your program!+  * Feel free to comment ​your codeAny additional memory needed ​to load your file due to heavy use of comments is released soon after loading is complete.
   * 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"​).