Thread overview
methods and instance variables cannot share a name
Jul 30, 2004
stonecobra
Jul 30, 2004
Regan Heath
Jul 30, 2004
Mike Parker
Jul 30, 2004
stonecobra
Aug 01, 2004
Regan Heath
July 30, 2004
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
July 30, 2004
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/
July 30, 2004
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.



July 30, 2004
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
August 01, 2004
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/