www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - methods and instance variables cannot share a name

reply stonecobra <scott stonecobra.com> writes:
This is more for historical searching purposes, and to let people know 
that it is a difference between Java and D.

In my translation of Java to D at the source level, I cam across a class 
in Java that looks like:

Class SomeSet {

   KeySet keySet;

   KeySet keySet() {
     ...
   }

}

It is my understanding that this is incorrect in D and is as-designed, 
correct?

So, I am merely try to rename one of them and move on, just wanted to 
let people know.

Scott Sanders
Jul 29 2004
parent reply Regan Heath <regan netwin.co.nz> writes:
On Thu, 29 Jul 2004 19:47:46 -0700, stonecobra <scott stonecobra.com> 
wrote:

 This is more for historical searching purposes, and to let people know 
 that it is a difference between Java and D.

 In my translation of Java to D at the source level, I cam across a class 
 in Java that looks like:

 Class SomeSet {

    KeySet keySet;

    KeySet keySet() {
      ...
    }

 }

 It is my understanding that this is incorrect in D and is as-designed, 
 correct?

 So, I am merely try to rename one of them and move on, just wanted to 
 let people know.
How does Java treat the above? Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 29 2004
parent reply Mike Parker <aldacron71 yahoo.com> writes:
Regan Heath wrote:

 On Thu, 29 Jul 2004 19:47:46 -0700, stonecobra <scott stonecobra.com> 
 wrote:
 Class SomeSet {

    KeySet keySet;

    KeySet keySet() {
      ...
    }

 }

 It is my understanding that this is incorrect in D and is as-designed, 
 correct?

 So, I am merely try to rename one of them and move on, just wanted to 
 let people know.
How does Java treat the above?
Java knows the difference between a method and a member via the parentheses. It helps that you can't pass around function pointers in Java. These days, I've noticed more and more code where Java programmers are abandoning the traditional get/set syntax for method names where 'properties' are concerned, and end up naming the member and both methods the same.
Jul 30 2004
next sibling parent stonecobra <scott stonecobra.com> writes:
Mike Parker wrote:

 Regan Heath wrote:
 
 On Thu, 29 Jul 2004 19:47:46 -0700, stonecobra <scott stonecobra.com> 
 wrote:
 Class SomeSet {

    KeySet keySet;

    KeySet keySet() {
      ...
    }

 }

 It is my understanding that this is incorrect in D and is 
 as-designed, correct?

 So, I am merely try to rename one of them and move on, just wanted to 
 let people know.
How does Java treat the above?
Java knows the difference between a method and a member via the parentheses. It helps that you can't pass around function pointers in Java. These days, I've noticed more and more code where Java programmers are abandoning the traditional get/set syntax for method names where 'properties' are concerned, and end up naming the member and both methods the same.
Correct, in Java the parens are required. In D, they are optional, correct, so there is an ambiguous definition. Java has no problem, since they are not ambiguous, ie (keySet != keySet()). Scott
Jul 30 2004
prev sibling parent Regan Heath <regan netwin.co.nz> writes:
On Fri, 30 Jul 2004 16:11:19 +0900, Mike Parker <aldacron71 yahoo.com> 
wrote:
 Regan Heath wrote:

 On Thu, 29 Jul 2004 19:47:46 -0700, stonecobra <scott stonecobra.com> 
 wrote:
 Class SomeSet {

    KeySet keySet;

    KeySet keySet() {
      ...
    }

 }

 It is my understanding that this is incorrect in D and is as-designed, 
 correct?

 So, I am merely try to rename one of them and move on, just wanted to 
 let people know.
How does Java treat the above?
Java knows the difference between a method and a member via the parentheses.
Whereas D allows you to access a member function like the above with or without the parens as part of the properties feature of D.
 It helps that you can't pass around function pointers in Java. These 
 days, I've noticed more and more code where Java programmers are 
 abandoning the traditional get/set syntax for method names where 
 'properties' are concerned, and end up naming the member and both 
 methods the same.
In the case of D I tend to do the following... class { int fooBar() { return _fooBar; } int fooBar(int value) { _fooBar = value; } private: int _fooBar } so, if you were going to do that, then a rename of the member variable is the correct conversion step to take. Regan. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 31 2004