Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: nomenclature Date: Tue, 02 Oct 2012 17:38:16 -0400 Organization: A noiseless patient Spider Lines: 48 Message-ID: References: <70c1d214-71ac-478d-95d7-a5984c3dc180@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 2 Oct 2012 21:38:17 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="ffb8f7085759b339c1002252b48331a4"; logging-data="32323"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18VmkqRd2/L05hBdtY6CGOP" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 In-Reply-To: <70c1d214-71ac-478d-95d7-a5984c3dc180@googlegroups.com> Cancel-Lock: sha1:6lWlC/BXRGBEmfuell+o5Cm8cKE= Xref: csiph.com comp.lang.java.programmer:19061 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