Naming is hard – what’s in a name?

TLDR;

Naming things is hard, really hard. Try not to worry too much, refactoring is more important here, if in doubt, make something up and ask others.

Naming things is hard. Really hard.

My non programmer friends and family typically think understanding how to interpret code is the hardest part of programming, i.e. speaking the language. They’re nearly right, I’d argue that it is related to language but actually something at a much more basic level, naming. Those of you who have been lucky enough to have children (myself included) will know the endless hours your agonise over what to name your child, “oooo I knew a David once, I just didn’t like him, David’s out”, “David Ian Swindells, well that would look like DIS when abbreviated and then his friends will make fun of him in school “… and so on and so on. (No offense to the David’s out there, David is clearly a brilliant name, no bias there at all 🙂 )

Naming code is like naming a child

Naming code is like naming a child 🤔, you need to see into every possible future situation where that name might be used or interpreted and guess how it might come across, does it communicate it’s intention well, is it misleading, is it too long, too short and so on and so on.

Top Tips for Naming

Naming things is hard. Really hard. Here are my top tips for naming that should make your life a little easier.

Better with practise

Typically, as with all things in life, you get better with practise at naming. I found, exposure to other people’s code and online tutorials really helped, you almost absorb other naming styles and ideas by osmosis.

Refactoring is your friend

There are tools that can help when you get it “wrong” or the situation changes and the variable/class/function/whatever needs to change. I’m a huge fan of JetBrains tools, as a .NET developer, resharper is my crack go to tool of choice for refactoring. But, other tools are catching up too, Visual Studio’s own inbuilt offering is pretty sophisticated, a long way from it’s “right click, rename … OMG it’s renamed EVERYTHING, and I can’t undo, and it’s not in source control NOOOOOOOOOOOO!!!!” days of VS 2005. There is no real reason that you should be forced to #GetItRightFirstTime like some sort of programming God, just write what you think is best, roll with it, then change it as and when you need.

Remember

Naming is hard, Keep calm and may the force be with you yoda image.

Keep calm and may the force be with you, always.

And if there’s no force available, get some coffee ☕, that’ll get you through 😁

David

Big guy, beard, likes software development.