Coders,do you still have problem naming things?

5 points by devspaper ↗ HN
"There are only two hard things in Computer Science: cache invalidation and naming things." Yeah,after 5 years coding,I still do,how about you? I wish there is a tool out there helps me naming variables and functions.

16 comments

[ 4.0 ms ] story [ 52.1 ms ] thread
I believe the saying is, "There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors."

But seriously I do still have problems naming things. And when working with other developers we can never seem to agree on a good name. The name he or she chooses is usually way different that what I would choose.

Since nowadays we all have autocompletion and good refactoring tools (to rename a variable), I usually give a pretty explicit name, even if it's sometimes more than 40 characters long. At least there's no ambiguity on the variable meaning, even if it makes the code a bit hard to read sometimes.
I would argue that descriptive and unambiguous long names make the code easier to read.
Sometimes it's just going to be hard. But sometimes it may be an indication that you don't know quite what the thing is, because the thing is too many things.
For many new devs the hard times are too many,CODELF is a better way I guess
The problem is picking a name that is both abstract and descriptive.
Huh, sounds interesting. What's an example of having an abstract name, and why is that important?
(comment deleted)
(comment deleted)
What made it easier for me was jettisoning the notion that names must be short.

1. Names must be descriptive.

2. Names must be unambiguous.

3. Names should be no longer than they need to be to achieve #1 and #2

I just ask myself: what is this thing, or what is it doing?

Then take the answer to that question, and boil it down to a name.

Then look at each word in that name and try to think of different interpretations of that word. If I find some ambiguity, then change something until the ambiguity is replaced with clarity. "Change something" could be changing that one word, or a word next to it, or it could be changing the whole thing. Yes sometimes this is hard, but often it's easy.

Also for #1, the context can help a little, so in a tight scope where there's plenty of context indicating what a variable might be for, the name can be less descriptive. By contrast, for publicly exposed names, they could be used far away from their original context, so fulfilling #1 relies entirely on the name itself, with no reliance on the context.

Names can describe their nature or their function. Blending the two can be difficult.
Just found this tool,pretty new.I've tried it about 1 hours,Some how it helps,helps me to calm down to have a good mood to think. I have to say this is sweet cool. Just like it says:Search over projects from Github, Bitbucket, Google Code, Codeplex, Sourceforge, Fedora Project to find real-world usage variable names — http://unbug.github.io/codelf/
I'm surprised there isn't already some sort of name generator that does this for you (like all the other startup and funny name generators). It should just ask you what it does and then convert it to some sort of camelcase or titlecase etc format with a standard convention.

Reaching here.. maybe even use AI to slowly standardize on certain things as more poeple use it?

Much like what Natch says, I go about it by asking myself what this function is doing and then proceeding to name it something that mirrors that. If I find myself unable to answer then perhaps the function is doing more than it should be and that also gives me a chance to break it up into simpler functions each doing something that can easily be described by its signature.