问题
My full variable name is Unique Code, however I want this variable to be "ucode"-ish.
So what would be correct concidering Java naming conventions?
- ucode
- uCode
- UCode
回答1:
See the coding conventions. For variables, camel case is recommended. Re. the naming, I would have thought
uniqueCode
would be the most logical choice (I'm aware that wasn't in your list of choices). Any uCode
variant looks like an abbreviation of unicode to me, and I would regard it as misleading. The above isn't an excessively long name (it's not an AbstractAnnotationAwareTransactionalTests, for example!)
I perhaps wouldn't embed the usage/restriction of the variable in the name itself. If you refactor the usage then you'll have to change the name of the variable too.
回答2:
Official doc for naming conventions: http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-135099.html#367
回答3:
Variable names should start with a lowercase letter and every other word should begin with a capital letter. So uCode
or uniqueCode
would fit with this convention.
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html
回答4:
I would always start my variables with a lowercase and then capitalise each word, so I would go with 2 but would prefer to call it uniqueCode
.
来源:https://stackoverflow.com/questions/15089616/java-naming-conventions