Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #19047 > unrolled thread

nomenclature

Started bybob smith <bob@coolfone.comze.com>
First post2012-10-02 12:51 -0700
Last post2012-10-03 16:02 -0700
Articles 11 — 9 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  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

#19047 — nomenclature

Frombob smith <bob@coolfone.comze.com>
Date2012-10-02 12:51 -0700
Subjectnomenclature
Message-ID<70c1d214-71ac-478d-95d7-a5984c3dc180@googlegroups.com>
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;

}

[toc] | [next] | [standalone]


#19049

FromArne Vajhøj <arne@vajhoej.dk>
Date2012-10-02 15:58 -0400
Message-ID<506b474e$0$294$14726298@news.sunsite.dk>
In reply to#19047
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;
>
> }

We can discuss whether it looks good or bad.

But it is very widely used, so any Java developer should
understand it.

Some IDE's even generate constructor code looking like
that.

Arne

[toc] | [prev] | [next] | [standalone]


#19051

FromPatricia Shanahan <pats@acm.org>
Date2012-10-02 13:05 -0700
Message-ID<uZadnYq4Mf-P1PbNnZ2dnUVZ_hadnZ2d@earthlink.com>
In reply to#19047
On 10/2/2012 12: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;
>
> }
>

Often, there is one right name for a property, like "width" for the
width of a rectangle. That is both the best possible identifier for a
private field representing the property, and the best possible
identifier for a constructor argument setting its value.

Why give one of them a different, necessarily inferior, identifier?

Patricia

[toc] | [prev] | [next] | [standalone]


#19053

FromDaniel Pitts <newsgroup.nospam@virtualinfinity.net>
Date2012-10-02 13:18 -0700
Message-ID<h_Has.3630$w_2.159@newsfe12.iad>
In reply to#19047
On 10/2/12 12: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;
>
> }
>

If you are considering objecting because it requires "this.", I actually 
find that to be a useful syntax, and my constructors (and setters) use 
it, even if there isn't a name collision with local symbols.

Most experienced Java programmers will take more exception with the 
class name.  Java convention would suggest MyRectangle, not My_Rectangle.

I've seen people try to avoid "name collisions", with ugly results. 
Underscores before members, or before parameters, or other such 
conventions.  Ugly... ugly.

[toc] | [prev] | [next] | [standalone]


#19054

FromLew <lewbloch@gmail.com>
Date2012-10-02 13:22 -0700
Message-ID<887fd0ae-c207-4298-a738-ae43fda10be1@googlegroups.com>
In reply to#19053
Daniel Pitts wrote:
> 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;
>>
>> }
>>
> 
> If you are considering objecting because it requires "this.", I actually 
> find that to be a useful syntax, and my constructors (and setters) use 
> it, even if there isn't a name collision with local symbols.
> 
> Most experienced Java programmers will take more exception with the 
> class name.  Java convention would suggest MyRectangle, not My_Rectangle.

http://www.oracle.com/technetwork/java/codeconv-138413.html

> I've seen people try to avoid "name collisions", with ugly results. 
> Underscores before members, or before parameters, or other such 
> conventions.  Ugly... ugly.

-- 
Lew

[toc] | [prev] | [next] | [standalone]


#19058

FromDaniel Pitts <newsgroup.nospam@virtualinfinity.net>
Date2012-10-02 13:47 -0700
Message-ID<wpIas.2286$ng.1914@newsfe01.iad>
In reply to#19054
bob smith wrote:
>>> public My_Rectangle(double x, double y, double width, double height) {

Daniel Pitts wrote:
>> Most experienced Java programmers will take more exception with the
>> class name.  Java convention would suggest MyRectangle, not My_Rectangle.

Lew wrote:
> http://www.oracle.com/technetwork/java/codeconv-138413.html

Thanks for the link Lew. That matches in general what my specific 
example showed ;-)

[toc] | [prev] | [next] | [standalone]


#19060

Frommarkspace <-@.>
Date2012-10-02 14:27 -0700
Message-ID<k4fm7g$puf$1@dont-email.me>
In reply to#19047
On 10/2/2012 12:51 PM, bob smith wrote:
> Is this sort of thing bad practice

> public My_Rectangle(double x, double y, double width, double height) {


The arguments are fine, but the underscore in the ctor name isn't 
considered proper coding convention for Java.


[toc] | [prev] | [next] | [standalone]


#19061

FromEric Sosman <esosman@ieee-dot-org.invalid>
Date2012-10-02 17:38 -0400
Message-ID<k4fms9$vi3$1@dont-email.me>
In reply to#19047
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

[toc] | [prev] | [next] | [standalone]


#19129

FromAndreas Leitgeb <avl@gamma.logic.tuwien.ac.at>
Date2012-10-05 16:38 +0000
Message-ID<slrnk6u393.u9l.avl@gamma.logic.tuwien.ac.at>
In reply to#19061
Eric Sosman <esosman@ieee-dot-org.invalid> wrote:
> 	private final double _goodName;
> 	public Thing(double goodName) {
> 	    _goodName = goodName;
> 	}

I admit using a "m_" prefix on fields:
   private final double m_goodName;
   public Thing(double goodName) {
       m_goodName = goodName;
   }

I got into that habit in my early days of C++ with (gasp)
some Microsoft IDE.  I'm not completely following that 
style, though, as I typically don't use type-hints after
the underscore.

Sometimes I even do that, like when I think that goodName 
looks strange, but xGoodName looks much less strange. Also,
when there is a goodName for some item, but two different
representations for it, then I might do something roughly
like:

   private int m_iGoodName;
   private String m_sGoodName;
   public void setGoodName(int iGoodName) {
      m_iGoodName=iGoodName;
      m_sGoodName=""+iGoodName;
   }
   public void setGoodName(String sGoodName) {
      m_sGoodName=sGoodName;
      m_sGoodName=Integer.parseInt(sGoodName);
   }

I guess you now feel like asking what name (and type) I use
for the getter, but that's beyond the scope of the example.
;-)

[toc] | [prev] | [next] | [standalone]


#19163

FromArne Vajhøj <arne@vajhoej.dk>
Date2012-10-05 20:28 -0400
Message-ID<506f7b26$0$291$14726298@news.sunsite.dk>
In reply to#19129
On 10/5/2012 12:38 PM, Andreas Leitgeb wrote:
> Eric Sosman <esosman@ieee-dot-org.invalid> wrote:
>> 	private final double _goodName;
>> 	public Thing(double goodName) {
>> 	    _goodName = goodName;
>> 	}
>
> I admit using a "m_" prefix on fields:
>     private final double m_goodName;
>     public Thing(double goodName) {
>         m_goodName = goodName;
>     }
>
> I got into that habit in my early days of C++ with (gasp)
> some Microsoft IDE.  I'm not completely following that
> style, though, as I typically don't use type-hints after
> the underscore.

The special Win32 flavor of hungarian notation.

Arne

[toc] | [prev] | [next] | [standalone]


#19085

FromRoedy Green <see_website@mindprod.com.invalid>
Date2012-10-03 16:02 -0700
Message-ID<kvgp68d87ignigokftnmmic4itgcahfkd5@4ax.com>
In reply to#19047
On Tue, 2 Oct 2012 12:51:05 -0700 (PDT), bob smith
<bob@coolfone.comze.com> wrote, quoted or indirectly quoted someone
who said :

>public My_Rectangle(double x, double y, double width, double height) {
>		this.x=x;
>		this.y=y;
>		this.width=width;
>		this.height=height;

This is Sun standard practice.
-- 
Roedy Green Canadian Mind Products http://mindprod.com
The iPhone 5 is a low end Rolex. 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web