Re: hiding a class property behind a method

2014-02-23 Thread luka8088
On 23.2.2014. 13:51, luka8088 wrote: > That is exactly what I wanted to point out! I reduced the example code > to make that point more obvious: Just one note. I know how this works currently in D and how it works in C++. What I am asking here is not how it works but is this a good idea as I just

Re: hiding a class property behind a method

2014-02-23 Thread luka8088
On 22.2.2014. 23:43, simendsjo wrote: > On 02/22/2014 11:33 PM, Francesco Cattoglio wrote: > The problem isn't about optional parenthesis or properties. It's the > fact that > you can redefine a symbol to be something entierly different, and that this > difference will only be seen if you are looki

Re: hiding a class property behind a method

2014-02-22 Thread francesco cattoglio
On Saturday, 22 February 2014 at 22:42:24 UTC, simendsjo wrote: The problem isn't about optional parenthesis or properties. It's the fact that you can redefine a symbol to be something entierly different, and that this difference will only be seen if you are looking at the symbol through the "

Re: hiding a class property behind a method

2014-02-22 Thread simendsjo
On 02/22/2014 11:33 PM, Francesco Cattoglio wrote: On Saturday, 22 February 2014 at 17:21:50 UTC, luka8088 wrote: It seems to me that the following code should be illegal, but I am uncertain of it so I am posting here for a confirmation before I post it on bug tracker: [snip] Nice find. I gues

Re: hiding a class property behind a method

2014-02-22 Thread Francesco Cattoglio
On Saturday, 22 February 2014 at 17:21:50 UTC, luka8088 wrote: It seems to me that the following code should be illegal, but I am uncertain of it so I am posting here for a confirmation before I post it on bug tracker: [snip] Nice find. I guess we could add this to the list of "ugly code cau

Re: hiding a class property behind a method

2014-02-22 Thread simendsjo
On 02/22/2014 09:43 PM, Ali Çehreli wrote: It looks like name hiding, which I am familiar from C++. Name hiding does not differentiate between functions and variables. Ali The problem is that hiding a name *is* a problem. When you are hiding a name, then a class would no longer behave as yo

Re: hiding a class property behind a method

2014-02-22 Thread Ali Çehreli
On 02/22/2014 10:00 AM, Maxim Fomin wrote: > On Saturday, 22 February 2014 at 17:41:58 UTC, Ali Çehreli wrote: >> >> The code uses the two objects through the A interface and x() is a >> virtual function on that interface. >> >> When the C interface is used then we get C.x, which happens to be >>

Re: hiding a class property behind a method

2014-02-22 Thread Ali Çehreli
On 02/22/2014 12:06 PM, Nynn007 wrote: >> The code uses the two objects through the A interface and x() is a >> virtual function on that interface. > [...] >> Ali I agree. :) > > The book "Programming in D" (r651) says in chapter "57.7 Using the > subclass in place of the superclass", in the ex

Re: hiding a class property behind a method

2014-02-22 Thread Nynn007
The code uses the two objects through the A interface and x() is a virtual function on that interface. [...] Ali The book "Programming in D" (r651) says in chapter "57.7 Using the subclass in place of the superclass", in the example about Clock and AlarmClock : void use(Clock clock) {

Re: hiding a class property behind a method

2014-02-22 Thread Maxim Fomin
On Saturday, 22 February 2014 at 17:41:58 UTC, Ali Çehreli wrote: The code uses the two objects through the A interface and x() is a virtual function on that interface. When the C interface is used then we get C.x, which happens to be hiding the x() function of the base class. It looks nor

Re: hiding a class property behind a method

2014-02-22 Thread Ali Çehreli
On 02/22/2014 09:21 AM, luka8088 wrote:> It seems to me that the following code should be illegal, but I am > uncertain of it so I am posting here for a confirmation before I post it > on bug tracker: > > > http://dpaste.dzfl.pl/dae728734cc6 > > > import std.stdio; > > class A { >string x ()

Re: hiding a class property behind a method

2014-02-22 Thread simendsjo
On 02/22/2014 06:21 PM, luka8088 wrote: import std.stdio; class A { string x () { return "A"; }; } class B : A { override string x () { return "B"; }; } class C : A { string x = "C"; // should this be illegal? } void main () { A o1 = new B(); writeln(o1.x); // B A o2 = new

hiding a class property behind a method

2014-02-22 Thread luka8088
It seems to me that the following code should be illegal, but I am uncertain of it so I am posting here for a confirmation before I post it on bug tracker: http://dpaste.dzfl.pl/dae728734cc6 import std.stdio; class A { string x () { return "A"; }; } class B : A { override string x () { re