Java naming conventions

試著忘記壹切 提交于 2019-12-20 04:08:35

问题


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?

  1. ucode
  2. uCode
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!