I’ve been scripting camelCase all my life but now I’m thinking if its better to switch to all lowercase or snake_case (when providing reasoning don’t take into account my past habit of camelCase though)
the - case version (hello-world) is just ugly so that’s definitely out of the question for me
I also don’t want to do the AllCapitals because that takes more effort than camel and gets the exact same point across
snake_case imo is the easiest to read but it also takes a little more effort to type the _
so between camelCase and snake_case I’m kind of leaning towards snake_case over camelCase but I’m worried that it would take too long to type and it goes against the roblox naming convention
all lowercase does seem VERY attractive though as well because it takes the least amount of effort to type, but as with snake_case I’m worried it going against the roblox naming convention would be annoying
On top of that though, I’m afraid the variables will be too hard to read
As of typing this post though, my favorite is all lower case
So what are your thoughts and experiences with variable naming styles?
PascalCase for classes, fields/properties, and functions
camelCase for everything else
UPPER_SNAKE_CASE for constants
Avoid all lowercase because it’s really hard to read.
Here’s a code example from my preferences:
local MY_NUMBER = 32
local ThatObject = require(somewhere.ThatObjectModule)
local something = workspace.Something
local anotherThing = workspace.AnotherThing
local runService = game:GetService("RunService")
function DoSomething()
local object = ThatObject.new()
object:DoSomething()
local item = object.Item
return object
end
DoSomething()
I am also very picky about spacing. I have 2 blank lines between functions, and use 1 blank line to separate logical chunks of code to make it more readable.
My styling is heavily influenced by C# standard styling practices.
Edit: The important principle is that you want your code to be easily readable. Using different casing styles helps identify the variable type. For instance, if I’m using THIS_THING, then I can be quite confident that I intended it to be a constant.
Personally, I change in account to the language I am scripting in. For lua, I tend to stick to PascalCase, but of all the options I would highly discourage an all lower-case option. This can make for an extremely lengthy and difficult read of your scripts.
Use the standard. snake_case for variables is popular in languages like Python, but in Lua, the standard is camelCase. If you sacrifice readability by straying from the standard for some snowflake preference, you are an awful programmer.
Even if your code isn’t meant to be read by others, eventually there will come a day when you work with someone else on Roblox. At that point you will both be frustrated having to deal with someone else’s standard that isn’t your own. Seriously – just use the global standard unless you have a really good reason not to.
Idk, all_lowercase is pretty easy to read for me. Godot Engine uses it as its main format, and it seems to work fine.
I like to do PascalCase for everything (aside from constants) – you’re either all in or all out. Combining both pascal and camel just looks messy from an aesthetic perspective. But whatever works lol
There’s also the standard conventions and other people to consider, like others have pointed out.
As you can tell, there’s lots of different ways you can do stuff. I recommend you try all sorts of different styles, then go with whichever one suits you best.
My standard is the same as Crazyman32’s, only I like to also use PascalCase for constant Instances/RBXScriptSignals. Ex:
local RunService = game:GetService("RunService")
local RenderStepped = RunService.RenderStepped
I also never shorten my variable names and refuse to have them under 3 characters unless they’re math variables (i.e. I’m translating a formula/algorithm over to Lua). You’ll never see anything like plr, ply, char, etc in my code. Always player, character. This is the same for everything else.
For several reasons. First, you’ll find that a lot of scripters in Roblox are familiar with and adopt this method, and as such it makes it easier when sharing your script with others. Another important aspect is that not only is it more presentable, but it’s easier to skim-trough. Words can easily be picked up upon, and you know exactly where they start and end.
As for your other questions, I refer to how long it takes for one to associate a variable with a particular purpose. Remember that comments are not a replacement for properly-named variables! You should not force your fellow scripter to search for the initialization of the variable one is attempting to manipulate, and variables should be intuitive if you know the overall purpose of the script.
This is just me, but I end up either using camelCase or all lowercase with everything I use, mainly depending on what I am trying to work with. For me, all lowercase has become very easy to read, possibly having to do with my understanding of what are normally considered to be “dead languages”, which have had things written out with no spaces, no lowercase/capital letters (they’re all just a singular letter), and no periods/clear sentence structure.
That being said, if I am working on a project with multiple people, where I am not the only one working on something, I like to make my code more easily understood by others, and I will typically use camelCase along with snake_case, and a lot of comments.
It mainly just has to do with what I’m making it for, since I can skim through code and immediately see alllowercase and notice that it is two words, or notice that thisisavariable is four words.
Not whatsoever, it’s just a simple shift button away, it might take an added millisecond, but rather than it being annoying, it actually feels somewhat satisfying.
I didn’t know there was a name for how you Case your Code.
I always do Pascal because before I became a scripter I saw my friend do it so I also did it but maybe I should change that so there is more veriety and readability to my scripts.
However what ever casing you choose if your Variable names are stupid they won’t help, make sure they have meaningful names.
Commenting wouldn’t be needed in the first place if your Variable names are meaningful.
You shouldn’t have to type your Vars twice ever because you can Copy & Paste and sometimes it also auto completes for you.
Maybe you should change the Title to Casing Variables? It’s miss leading you aren’t asking about naming them.
It’s mostly up to preference, just don’t use ALL lowercase. You’d always want to value readability than an extra key press or two.
thisVariableIsInCamelCase = “very readable and ThisVariableIsInPascalCase = “very readable” would be better than thisvariableisinlowercase = “notveryreadable”