Coders,do you still have problem naming things?
"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 ] threadBut 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.
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.
Reaching here.. maybe even use AI to slowly standardize on certain things as more poeple use it?
A level up is where you can write names in such a way it detects bugs: http://www.joelonsoftware.com/articles/Wrong.html