由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - JavaBean variable name standard
相关主题
any tools for ...如何把函数体放入到try ... catch ... 中
eclipse 气死我了!return null or empty list/set/...
Complaint about Java class packageIntelliJ Open Sourced - How is it?
谁能说说Perm Gen Size太大有什么坏处?What's going on with Spring IDE's website?
请问java的ide请教:怎么把synchronize的method改成用thread 但thread safe呢?
调查:最好的Java IDEOO and abstract class
a question请问用什么java developer? 在哪里下载?
EJB bookNetbean duplicate class error
相关话题的讨论汇总
话题: name话题: variable话题: javabean话题: variables话题: var
进入Java版参与讨论
1 (共1页)
m*****y
发帖数: 120
1
Does anyone happen to know the official JavaBean naming standard? Such as,
can I make my variable name like "my_name", instead of "myName"?
Thanks a lot.
g*****g
发帖数: 34805
2
myName is the recommended coding standard by Sun.
But you can use my_name if you really want to, just use
getMy_name and setMy_name for function name

【在 m*****y 的大作中提到】
: Does anyone happen to know the official JavaBean naming standard? Such as,
: can I make my variable name like "my_name", instead of "myName"?
: Thanks a lot.

b******y
发帖数: 1684
3
没见过用_的
用my_name的,会被team member们背后耻笑或者当面质问

【在 g*****g 的大作中提到】
: myName is the recommended coding standard by Sun.
: But you can use my_name if you really want to, just use
: getMy_name and setMy_name for function name

g******u
发帖数: 153
4
my_name是做Database的人的习惯
g*****g
发帖数: 34805
5
Well, I joined this company, and all the instances
names are m_xxx, there are over 10K
source files. So what can you do? You have to do the
same even if it's ugly. Consistent style is more important
than convention.
m******t
发帖数: 2416
6
Well if all of them start with m_, at least they are consistent. 8-)
m_* originated from MSVC practice, I think.
For a couple of years I had all of my instance variables starting
with _, which actually makes the code much more readable if
you have to read the code in an editor without syntax highlight.

【在 g*****g 的大作中提到】
: Well, I joined this company, and all the instances
: names are m_xxx, there are over 10K
: source files. So what can you do? You have to do the
: same even if it's ugly. Consistent style is more important
: than convention.

g*****g
发帖数: 34805
7
It's maybe slightly more readable, but a headache on refactoring.
Think of a dumb value class, with IDE like eclipse you only need
to put down instance names and generate getter/setters out of it.
Now some manual changes are inevitable. You don't want to live with
function name like getM_blah

【在 m******t 的大作中提到】
: Well if all of them start with m_, at least they are consistent. 8-)
: m_* originated from MSVC practice, I think.
: For a couple of years I had all of my instance variables starting
: with _, which actually makes the code much more readable if
: you have to read the code in an editor without syntax highlight.

w*****g
发帖数: 1415
8
m_
_
是我常用的。但到了公司以后,要看公司的规范
m******t
发帖数: 2416
9

Oh no no, I was just talking about _starting_ instance variables with "_"
to distinguish them from local variables, not having "_" in the middle.
I totally agree with you. It's pointless and calling for trouble to do that.
And it's not even necessary to have starting _'s with modern IDEs.

【在 g*****g 的大作中提到】
: It's maybe slightly more readable, but a headache on refactoring.
: Think of a dumb value class, with IDE like eclipse you only need
: to put down instance names and generate getter/setters out of it.
: Now some manual changes are inevitable. You don't want to live with
: function name like getM_blah

h*****0
发帖数: 4889
10
this is c++ convention. java people don't use it.

【在 w*****g 的大作中提到】
: m_
: _
: 是我常用的。但到了公司以后,要看公司的规范

相关主题
调查:最好的Java IDE如何把函数体放入到try ... catch ... 中
a questionreturn null or empty list/set/...
EJB bookIntelliJ Open Sourced - How is it?
进入Java版参与讨论
c*****t
发帖数: 1879
11
nope.
It is pretty common to have instance variable prefixes. It prevent
one obvious error:
var = var
when it should be
this.var = var
this. is pretty painful to type and not everyone do it.
Particularly when you are quick viewing a source code, having m_ is
very helpful to distinguish instance variables from params.
Eclipse / IDEA all support prefixes.

【在 h*****0 的大作中提到】
: this is c++ convention. java people don't use it.
g*****g
发帖数: 34805
12
when you do var = var, Eclipse gives you a warning.
this.var isn't really that difficult to type with modern IDE.
The problem with prefix is refactoring, it just doesn't follow
java bean convention for example. Many convention over configuration
libraries now count on the right instance name to do the magic via
annotation.

【在 c*****t 的大作中提到】
: nope.
: It is pretty common to have instance variable prefixes. It prevent
: one obvious error:
: var = var
: when it should be
: this.var = var
: this. is pretty painful to type and not everyone do it.
: Particularly when you are quick viewing a source code, having m_ is
: very helpful to distinguish instance variables from params.
: Eclipse / IDEA all support prefixes.

h*****0
发帖数: 4889
13
in 水木社区,java people believe that m_ is unneccesary and reduces
readability. they think when there is a this.var = var, you shold always
type this. explicitely to inhance readability.
and they said that good IDEs, like IDEA will automatically show member
variable and local variable in different colors, there is totally no need to
use m_. and they also believe that the extra m_ makes the automatic
completion feature slower to show up (you need to type m_ then another
character to trigger this)

【在 c*****t 的大作中提到】
: nope.
: It is pretty common to have instance variable prefixes. It prevent
: one obvious error:
: var = var
: when it should be
: this.var = var
: this. is pretty painful to type and not everyone do it.
: Particularly when you are quick viewing a source code, having m_ is
: very helpful to distinguish instance variables from params.
: Eclipse / IDEA all support prefixes.

h*****0
发帖数: 4889
14
i think for member variable known to outside(e.g. with setXX and getXX
method), we should never use any pre/sufix.

【在 g*****g 的大作中提到】
: when you do var = var, Eclipse gives you a warning.
: this.var isn't really that difficult to type with modern IDE.
: The problem with prefix is refactoring, it just doesn't follow
: java bean convention for example. Many convention over configuration
: libraries now count on the right instance name to do the magic via
: annotation.

c*****t
发帖数: 1879
15
Both Eclipse and IDEA can auto generate setXXX and getXXX for variables
with prefixes automatically. I don't think that's a problem at all.
Of course, this rule does not apply to PUBLIC/package variables (which
should only be used in cases of very simple data structures). Using
protected is a bad design. So using m_ is really for private instance
variables.
In my experience, one often times cannot always open a Java file in
an IDE and read. For example, you wanted to quickly checkout the
sou

【在 h*****0 的大作中提到】
: i think for member variable known to outside(e.g. with setXX and getXX
: method), we should never use any pre/sufix.

h*****0
发帖数: 4889
16
it doesn't matter if you use var later...
if it matters, e.g. you changed the value of var after the same function
where you set this.var = var, then this design itself has some flaw... and
you should be very careful in this case, of course. typing this. isn't that
painful, just a habit, and it actually helps checking the code as you
mentioned.

【在 c*****t 的大作中提到】
: Both Eclipse and IDEA can auto generate setXXX and getXXX for variables
: with prefixes automatically. I don't think that's a problem at all.
: Of course, this rule does not apply to PUBLIC/package variables (which
: should only be used in cases of very simple data structures). Using
: protected is a bad design. So using m_ is really for private instance
: variables.
: In my experience, one often times cannot always open a Java file in
: an IDE and read. For example, you wanted to quickly checkout the
: sou

s******n
发帖数: 876
17
I find "camel case" uneasy for eyes. it exists only because underscore is
too hard to type. programmers should really have specially designed
keyboards; standard keyboards were designed for secretaries.

【在 m*****y 的大作中提到】
: Does anyone happen to know the official JavaBean naming standard? Such as,
: can I make my variable name like "my_name", instead of "myName"?
: Thanks a lot.

1 (共1页)
进入Java版参与讨论
相关主题
Netbean duplicate class error请问java的ide
Re: Why are all java IDEs written in jav调查:最好的Java IDE
how to solve the problem: the members change by each other .a question
问一个java的面试题 (转载)EJB book
any tools for ...如何把函数体放入到try ... catch ... 中
eclipse 气死我了!return null or empty list/set/...
Complaint about Java class packageIntelliJ Open Sourced - How is it?
谁能说说Perm Gen Size太大有什么坏处?What's going on with Spring IDE's website?
相关话题的讨论汇总
话题: name话题: variable话题: javabean话题: variables话题: var