Ah, this one is a story the lua maintainers wouldn't tell you...
I kid, I kid.
This is partially my fault, because I'm used to writing code in the Lua style (e.g. setmetatable), with a dash of snake_case mixed in. It seems the original Lua authors (robn and a few others) were a fan of PascalCase, something which I cannot fault them for, and ecraven (who by and large wrote all the pigui code) used camelCase, otherwise known as Javascript style.
Interestingly enough, all of the code prior to when I joined the project used the function-call style for importing; the newer string-literal call style that occasionally shows up is entirely my personal style. I like it and am probably going to standardize it because it makes it extremely easy to see what you're importing, it closely follows Lua norms, and it effectively communicates that you're bringing in a module name to the local scope.
Code: Select all
import("a/b/c.lua") -- the existing function call style
require 'module.name' -- the new, "elegant" style
Opinions vary on consistent style; at the moment you are the primary Lua contributor so your voice has the most weight, but as the de-facto Lua maintainer my recommendation and personal style (I'll get it on the wiki eventually, I swear!) is as below:
Code: Select all
-- use the string-literal method with require() instead of import, due to import being on its way out the door
-- don't use filesystem paths, use Lua's module.name syntax; paths are also being deprecated now
-- also worth noting is to please name your files after their primary class, maintaining the same case
local MyNewClass = require 'lib.MyNewClass'
-- local / static variables at file or function scope should use snake_case
local my_size_var = ui.rescaleUI({ ... })
-- Types / Classes should use PascalCase, as in Engine or PiGui.Modules.Face
local class_obj = MyNewClass()
-- the pigui object is imported as lowercase because it's a reference to a dispatch object and not a type
local ui = require 'pigui'
-- instance variables should use camelCase for naming, to distinguish them from local variables and instance methods
class_obj.instanceVariable = my_size_var
-- class and instance methods should ideally use PascalCase as well, although I'm not opposed to using camelCase if necessary
class_obj:DoSomethingWithInstanceVariable()
-- methods bound to C++ should use PascalCase, with no exceptions
class_obj:CallSomeCPPMethod
However, nothing is perfect. We have enough code in pigui that uses camelCase instead of PascalCase that it's not worth refactoring everything - my rationale behind this is that this indicates that it's a wrapper over the C++ PiGui methods, although that's entirely an inconsistent back-explanation instead of a style choice. I occasionally slip into C++ style camelCase for local variable names, and pigui is universally imported as lowercase 'ui' because it's a lot easier to write like that, and it's also not a class, rather being a collection of function dispatchers.
Going forward, I'd recommend that everything but UI code uses this style guide; I'm willing to make a stylistic difference for function and method names in the UI code just because that's about 3,000 instances that would need re-formatting and we don't have a good tool to do that automatically.
If you have suggestions I'd love to hear them; this style guide is mostly my personal style matched with existing code in the project (with some exceptions thrown in for the UI code). I'd like to think that most of these are fairly common-sense and don't cause confusion / hair loss when writing / maintaining Lua code, but I'm more than happy to take feedback on board.
...reading what I've written, it boils down to "use camelCase for UI code, use PascalCase for game code". Everything else is as outlined in the style guide above.