Capitalize variable names

I always declare my variables starting with the first lowercase letter.
Elements of a dictionary, parts, and instance properties always begin with the first capital letter.
Because of that, I took a beating out of my program trying to find a bug until I found out that I had a variable like “myVar” and a dictionary element like “MyVar”: after all, I had dic.myVar and dic.MyVar living together …
To avoid this confusion again, wouldn’t it be interesting to standardize the use of variables to start with a capital letter? So everything would start with a capital letter: variables, dictionary elements, instances, properties, etc.
Any better ideas?

If you’re consistent about it, having different capitalization schemes for different things can make your code more readable. E.g. here how I usually do it for consts, classes and everything else.

HEXAGON_DISTANCE = 50

local ScriptEvent = require(game.ServerStorage.ScriptEventClass)

local scriptEventA = ScriptEvent.New()```
1 Like

It’s all preference when it comes to code you’re writing yourself… Especially if you’ve worked with other languages. For instance, loml is Java, and therefore most of my code has semicolons everywhere. But it works for me, and it helps me stay organized. I also do a lot of object oriented programming in lua even though it’s not necessary.

But yeah back on subject, unless you’re working on a project that is seen by more than just your eyes, there’s no right way to name variables, it’s all preference. However, if you are working in a group you should probably make your code as clear and concise as possible.

You can always take a look at this,

2 Likes