Meaningful and Verbose names

I don’t mind the odd abreviation of a local variable inside a function, but when I was working on a project back in 2014, I came across variable names like “sss” and then later on I have come across method names and class names where the contents is complex and not named particularly well.

My approach to this is, “if a brand new team member with not much experience joined your project, could they understand the intention of what you are trying to do.” The content of our class or function may be complex, but from reading the class name and method names can they understand what the functionality should do and also how heavy it potentially is.

This includes putting the correct “doing” words on your function.

Let’s say you had a method

int ShipAttackPower()

What does this do? Does it set the attack power to a variable inside the class and return it? Does it retrieve some data from JSON? Does it calculate it on the fly depending on if a bullet hits another ship in some collision detection logic? A seemingly innocent naming of a function can cause a lot of questions!

If we just want to retrieve the settings then you should lable the function:

int GetShipPowerFromSettings()

If you need to calculate it on the fly you should name it:

int CalculateShipPower()

I briefly mentioned performance. In the past, I have been heavily involved with optimization (trying to get a Unity game to run on 5-year-old mobile devices is always fun). Although you will use some sort of profiler, it is good to have a name that explains what it is doing as if you find your function is heavy and you know it is Calculating or Getting something from settings, etc then it can help you infer why your function is so heavy.