Don’t go into programming if you don’t have a good thesaurus

Many programmers feel that naming things in their code is not only the hardest task they face, but also one of the most important

By  


So many names to choose from...

Image credit: flickr/Rex Roof

Last week I wrote a piece about the hardest tasks programmers have to do. It was based primarily on a recent discussion thread on Quora. Based on the responses and the votes, there was a clear number one, hardest task for software developers: naming things (e.g., variables, classes, functions, procedures, etc.).

I found this result somewhat surprising, as it wouldn’t have been my own personal choice based on my years as a developer (I think I would have voted for “Working with someone else’s code”). But what really surprised me was the margin by which naming was the number one choice. It wasn’t even close. Here’s how it broke down:


Naming things in code is really hard

Image credit: ITworld/Phil Johnson

The results were based on 4,500 votes developers provided on Quora and an older Ubuntu Forums thread. Naming things got (just about) as many votes as the next 8 hardest tasks combined. Wow!

Yes, these are totally non-scientific results based on the input from a self-selecting group. But still, I think this tells us something significant. Namely, that naming things really is tricky, which many non-programmers probably don’t even realize.

There was a thread on StackExchange a few years ago about this very topic. To emphasize the point, here are some more quotes from programmers about the pain and difficulty of naming:

"I do spend a lot of time as well worrying about the names of anything that can be given a name when I am programming." willcodejavaforfood

"I have to agree that naming is an art." Otávio Décio

"...its one of the most important things if you want your code to be readable by others." Geries Handal

That last quote, I think, gets at the heart of at least partly why it’s so hard: because it’s so important. Choosing the right names for things can make code easier to read, understand and debug, not just by you, but also by others who come after you. Once you have to do it, you quickly realize that it’s not easy coming up with names that are descriptive and concise. As Jeff Atwood wrote:

Creating good names is hard, but it should be hard, because a great name captures essential meaning in just one or two words

Also, many feel that paying attention to proper naming can help you to write better code. If you can’t come up with a clear and concise name for a variable or function, it might be a sign that something is amiss in the code. In that case, you might want to consider rewriting or refactoring.

"Often times, however, the inability to come up with a name may be a hint to something wrong with your design. Does your method have too many responsibilities? Does your class encapsulate a coherent idea?" Brad Barker

"One lesson I heave [sic] learned, is that if you can't find a name for a class, there is almost always something wrong with that class: you don't need it, it does too much" Toon Krijthe

"It's good that it's difficult. It's forcing you to think about the problem, and what the class is actually supposed to do." JW.

Long story short: if you’re going into programming, be sure to get yourself a good thesaurus.

Read more of Phil Johnson's #Tech blog and follow the latest IT news at ITworld. Follow Phil on Twitter at @itwphiljohnson. For the latest IT news, analysis and how-tos, follow ITworld on Twitter and Facebook.

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Ask a Question