7 ms·
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 b
by natch 11y ago
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.