How should the casing be for OOP objects?
For example
function Car.new()
local self = {}
self.speed = 5
return self
end
or
function Car.new()
local self = {}
self.Speed = 5
return self
end
How should the casing be for OOP objects?
For example
function Car.new()
local self = {}
self.speed = 5
return self
end
or
function Car.new()
local self = {}
self.Speed = 5
return self
end
Its a personal preference thing. I generally use UpperCamelCase because everything on roblox is in that format and I value constancy.
For lua OOP in general, i would recommend checking out chapter 16 of the lua pil, but in general, instantiators for OOP in lua tend to look something like this
local a = {}
a.__index = a
function a.new()
local self = {}
return setmetatable(self,a)
end
Do you mean the casing for the word “Speed”, it really does not matter use what you find most readable, most programmers tend to seperate every new word in a variable name by a capital letter though for example:
local RealTime -- UpperCamelCase
-- or some would do it like this
local realTime --lowerCamelCase
--or
local Real_Time
--it really is whatever you like the most and is readable
--just ensure you use meaningful variable names
Expanding upon this, Lua programmers tend to prefer loweCamelCase since it meshes nicely with the standard library (which is all lowercase) & the style guide roblox is intending to move towards for internal code advises lowerCamelCase (or camelCase) for member values & functions (properties & methods).
But, in the end, it’s whatever the author prefers.
I guess your right but as long you use meaningful variable names you should be good, I tend to use UpperCamelCase though.
Yes, I edited my message to make my intent more clear; it’s whatever the author of the code is most comfortable with that matters most.