Java naming conventions

2019-02-28 14:57发布

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

4条回答
Summer. ? 凉城
2楼-- · 2019-02-28 15:18

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楼-- · 2019-02-28 15:32

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.

查看更多
手持菜刀,她持情操
5楼-- · 2019-02-28 15:34

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.

查看更多
登录 后发表回答