User:Ganaram inukshuk/Provisional style guide for Lua: Difference between revisions
No edit summary |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
Parts of it are adapted for use on the wiki, with details on specific conventions. If a specific convention is missing, fall back to that described in the Luarocks style guide. | Parts of it are adapted for use on the wiki, with details on specific conventions. If a specific convention is missing, fall back to that described in the Luarocks style guide. | ||
== Provisional additions for version 2 == | |||
Consistency with param names, including spelling: | |||
* Define all param names at the module level, not the template level | |||
* Use snake_case for all param names throughout; anything remotely close to snake_case is normalized to snake_case | |||
* "debug" and "nocat" are reserved for toggling categories; the use of "debug" this way has already been the standard | |||
== Preliminaries == | == Preliminaries == | ||
| Line 10: | Line 17: | ||
=== Naming and declaring variables === | === Naming and declaring variables === | ||
Variable names should be short and descriptive, written <code>snake_case</code>. Exceptions to this include counter variables, like with <code>i</code> in for loops. Boolean variables are prefixed with <code>is_</code>. Constants are named using <code>TRAIN_CASE</code>. | Variable names should be short and descriptive, written in <code>snake_case</code>. Exceptions to this include counter variables, like with <code>i</code> in for loops. Boolean variables are prefixed with <code>is_</code> or <code>has_</code> wherever possible. Constants are named using <code>TRAIN_CASE</code>. | ||
All variable declarations should start with <code>local</code>. | All variable declarations should start with <code>local</code>. | ||
| Line 48: | Line 55: | ||
=== Naming, declaring, and calling functions === | === Naming, declaring, and calling functions === | ||
As with variables, functions are named using <code>snake_case</code>. Functions that return a boolean variable are prefixed with <code>is_</code> | As with variables, functions are named using <code>snake_case</code>. Functions that return a boolean variable are prefixed with <code>is_</code> or <code>has_</code>. | ||
''tbd'' | ''tbd'' | ||