This translator: isaced Reviewer: li Qing
Original link:slideshare
Links:JF Micro Magazine produced
This paper is edited by Jay Micro Editor on the basis of translation. If you have any questions, please feel free to communicate.
How to name it is actually the hardest thing to do in programming.
naming conventions for George Orwell
How to name?
In short, There is no way to choose words according to their meanings ... However, sometimes we don't know what words are more appropriate .
When you think of something abstract, you are more inclined to think of the first words, unless you deliberately do not, the words will also appear, until you blur or change your mind .
When you think of a specific object, you think the word is poor, and then you want to describe the already seen, and then you continue to look for the word that is more appropriate for it .
Six Principles
The following is the naming six principle given by George:
1. never use metaphor, simile, or other language to describe the way you see it in a book .
2. never use too long a word, if a short word has been able to explain the problem
3. If it is possible to shorten the terminology, try to shorten
4. never use the words in the passive voice, if you can use the words in the active voice
5. never use foreign vocabulary, academic terminology, if you can think of everyday words that mean similar
6. breaking any of the above rules, compared to a more straightforward way of speaking
These rules sound very relevant , and indeed they are . but for those who are used to the popular style of writing , these points are especially important. The following are specific explanations of these six principles.
1, do not use metaphor, simile : To prevent overuse of the customary design patterns, just because the code is used to see. such as :
Abstractcon? gurationfactory
2, as long as the short can not use long words : If a short vocabulary has been able to explain the problem , then try to use concise variable name, only for better reasons to use the long name . such as:
Company_person_collection
Vs
Staff
3 . If you can shorten the language, try to shorten it: avoid adding meaningless words to the naming . such as :
Abstractobjectformatterproxy
......
Org.springframework.web.servlet.support.
Abstractannotationcon? Gdispatcher
Servletinitializer
" It's like the same kind of therapy. All you have to do is simplify until there's nothing. "by Kevlin Henney.
4, as far as possible to use the active voice words: can use the active to never use passive voice words, easy to understand the user, but also abide by the grammatical rules of identifiers.
Such as:
Class Planevents
Vs
Class Eventplanner, or even class Scheduler.
5, try to use everyday words, avoid using foreign words or academic terminology, do not let special terminology from a library to pollute your domain model, but also beware of those from other languages into the "alien" named Library.
such as:Shipmentmonad
6, break any of the above rules, if you have a more simple and clear way to express. Of course, if your code is being advertised on many well-known websites, such as the Daily WTF, you can ignore what I say. (the Daily WTF, the American famous ugly Code development, disaster development case website.) )
Note: Many depend on the context;
Of course, publishing library code is not the same as maintaining private program code.
Do you feel that writing code is as difficult as writing prose?
Not to be continued.
Continue reading: The commonality of writing and programming--"How to name: The hardest thing to program" continued
[Reprint, please indicate the JF Micro-publication , translator and translation links. ]
How to name: The hardest thing to do in programming 1