roxen.lists.pike.general

Subject Author Date
Re: Pike 7.8.300 beta Reinhard Pfau <Reinhard[dot]Pfau[at]gmx[dot]de> 19-06-2009
On Wed, 2009-06-17 at 18:50 +0000, Henrik Grubbstr?m (Lysator) @ Pike
(-) importm?te f?r mailinglistan wrote:
> >Taking a first look at Pike 7.8.300, I found a flaw (in comparison to
> >7.6.112) with XML DOM parser:
> [...]
> >I don't know if this effect is wanted in Pike 7.8 ?
> >If yes, the DOM module is broken and might require some changes.
> >If no, we might have a problem with the compiler in 7.8 :-(
> 
> Interesting problem:
> 
>   class A
>   {
>     int foo = 1;
>   
>     int a()
>     {
>       return foo;
>     }
>   }
>   class B
>   {
>     static int foo = 2;	// Use static for compat with old pikes.
>   
>     int b()
>     {
>       return foo;
>     }
>   }
>   class C
>   {
>     inherit A;
>     inherit B;
>   
>     int c()
>     {
>       return foo;
>     }
>   }
> 
> In current Pike 7.8:
> 
>   C()->foo: UNDEFINED
>   C()->a(): 1
>   C()->b(): 2
>   C()->c(): 2
> 
> In Pike 7.2, 7.4, 7.6 and old 7.7:
> 
>   C()->foo: 1
>   C()->a(): 1
>   C()->b(): 2
>   C()->c(): 2
> 
> Note that both of the above behaviours are a bit strange; in the old
> pikes the symbol "foo" represents two different variables when used
> from inside the class C and when indexed from outside. In Pike 7.8
> the protected (aka static) symbol "foo" from B hides the one from A.

Hmm... right.

But the old pike's way seems to be more consistent:
Think of a function accepting an object of class A and get's passed an
instance of class C:

void fancy_func(A var)
{
  if (var->foo == 1)
  {
    // do fancy things
  }
}

/* ... */
fancy_func( C() );


With the old pike's that's not a a problem; the func sees the "right"
foo. 
With 7.8, it gets an UNDEF when accessing foo; the func sees a different
interface than it expects to see (and use)...

The old behavior is also similar to C++: when I pass a derived class
down to a func accepting base class (pointer or reference), the func
"sees" the interface of the base class even if the derived class hides
methods in it's own implementation.

Now it's the interesting question what behavior pike will have in the
future?


Greetings,
Reinhard

-- 
Reinhard Pfau
mailto:<Reinhard.Pfau[at]gmx.de>