Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #19061
| From | Eric Sosman <esosman@ieee-dot-org.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: nomenclature |
| Date | 2012-10-02 17:38 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <k4fms9$vi3$1@dont-email.me> (permalink) |
| References | <70c1d214-71ac-478d-95d7-a5984c3dc180@googlegroups.com> |
On 10/2/2012 3:51 PM, bob smith wrote:
> Is this sort of thing bad practice (using parameter names that are the same as my field names in the constructor)?
>
>
>
> public My_Rectangle(double x, double y, double width, double height) {
> this.x=x;
> this.y=y;
> this.width=width;
> this.height=height;
>
> }
It makes good sense to me. I don't need to invent two different
names for the same thing:
private final double x, y, width, height;
public MyRectangle(double top, double left,
double wide, double tall) {
x = top;
y = left;
width = wide;
height = tall;
}
Also, if the names agree I'm less likely to make the kind of
silly error shown above. (Did you spot it on the first reading?)
Keep in mind that the parameter names used for non-private
methods and constructors are as much a part of the interface as
are the method names themselves. They're visible in the Javadoc,
and are probably visible when an IDE auto-suggests or even auto-
generates code. So you don't just need names, you need good
names. If you then insist on using different names for the fields,
you may wind up giving the good names to the clients and forcing
the implementor to suffer with less-good names. Some people get
around this by inventing one good name and then altering it:
private final double _goodName;
public Thing(double goodName) {
_goodName = goodName;
}
... but to my eye this is awkward and ugly. YMMV.
--
Eric Sosman
esosman@ieee-dot-org.invalid
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
nomenclature bob smith <bob@coolfone.comze.com> - 2012-10-02 12:51 -0700
Re: nomenclature Arne Vajhøj <arne@vajhoej.dk> - 2012-10-02 15:58 -0400
Re: nomenclature Patricia Shanahan <pats@acm.org> - 2012-10-02 13:05 -0700
Re: nomenclature Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-10-02 13:18 -0700
Re: nomenclature Lew <lewbloch@gmail.com> - 2012-10-02 13:22 -0700
Re: nomenclature Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-10-02 13:47 -0700
Re: nomenclature markspace <-@.> - 2012-10-02 14:27 -0700
Re: nomenclature Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-10-02 17:38 -0400
Re: nomenclature Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-10-05 16:38 +0000
Re: nomenclature Arne Vajhøj <arne@vajhoej.dk> - 2012-10-05 20:28 -0400
Re: nomenclature Roedy Green <see_website@mindprod.com.invalid> - 2012-10-03 16:02 -0700
csiph-web