Trouble setting variable from abstract method implementation that is called by constructor

View: New views
10 Messages — Rating Filter:   Alert me  

Trouble setting variable from abstract method implementation that is called by constructor

by EricButler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi everyone,

Please see the code below. Is this a bug in Boo or am I doing
something wrong? The same (as far as I can tell) thing written in C#
works as I expect it to.

I'm using Boo SVN r3008 and Mono 1.9.1.

Thanks!
 - Eric

abstract class Bar:
        def constructor():
                self.go()

        abstract def go():
                pass

class Foo(Bar):
        test = null

        def constructor():
                 super()
                 if self.test == null:
                  raise "Failure!!"

        override def go():
                self.test = "Hello World"
                print 'self.test is',self.test

f = Foo()

output:

$ booi test.boo
self.test is Hello World
System.Exception: Failure!!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Trouble setting variable from abstract method implementation that is called by constructor

by George-94 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Foo constructor call test = null after super().

declare it as 'test as string'

On 12 июн, 21:50, Eric Butler <e...@...> wrote:

> Hi everyone,
>
> Please see the code below. Is this a bug in Boo or am I doing
> something wrong? The same (as far as I can tell) thing written in C#
> works as I expect it to.
>
> I'm using Boo SVN r3008 and Mono 1.9.1.
>
> Thanks!
>  - Eric
>
> abstract class Bar:
>         def constructor():
>                 self.go()
>
>         abstract def go():
>                 pass
>
> class Foo(Bar):
>         test = null
>
>         def constructor():
>                  super()
>                  if self.test == null:
>                         raise "Failure!!"
>
>         override def go():
>                 self.test = "Hello World"
>                 print 'self.test is',self.test
>
> f = Foo()
>
> output:
>
> $ booi test.boo
> self.test is Hello World
> System.Exception: Failure!!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Trouble setting variable from abstract method implementation that is called by constructor

by EricButler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi there,

Thanks for the reply.

Removing the "= null" from the foo declaration does fix the problem,
however this seems a bit inconsistent/unexpected to me.

My expectation is that the variable would be assigned it's value as soon
as it is declared. Is there documentation that explains the order all
this is evaluated?

Can you explain why the decision was made to do it this way vs. the way
C# handles this? I know Boo is not C#, and I'm not objecting to it
functioning differently, I just want to understand the design.

Thanks,
 - Eric


George wrote:

> Foo constructor call test = null after super().
>
> declare it as 'test as string'
>
> On 12 июн, 21:50, Eric Butler <e...@...> wrote:
>> Hi everyone,
>>
>> Please see the code below. Is this a bug in Boo or am I doing
>> something wrong? The same (as far as I can tell) thing written in C#
>> works as I expect it to.
>>
>> I'm using Boo SVN r3008 and Mono 1.9.1.
>>
>> Thanks!
>>  - Eric
>>
>> abstract class Bar:
>>         def constructor():
>>                 self.go()
>>
>>         abstract def go():
>>                 pass
>>
>> class Foo(Bar):
>>         test = null
>>
>>         def constructor():
>>                  super()
>>                  if self.test == null:
>>                         raise "Failure!!"
>>
>>         override def go():
>>                 self.test = "Hello World"
>>                 print 'self.test is',self.test
>>
>> f = Foo()
>>
>> output:
>>
>> $ booi test.boo
>> self.test is Hello World
>> System.Exception: Failure!!
> >

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Trouble setting variable from abstract method implementation that is called by constructor

by George-94 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


In every constructor after calling the base class constructor Boo
compiler inserts code assignment class variables  if it exists. (test
= null)
Then it adds explicit constructor code. Your design when base
constructor implicitly modifies child variable is hmm.. unusual for
OOP.

On 13 июн, 02:12, Eric Butler <e...@...> wrote:

> Hi there,
>
> Thanks for the reply.
>
> Removing the "= null" from the foo declaration does fix the problem,
> however this seems a bit inconsistent/unexpected to me.
>
> My expectation is that the variable would be assigned it's value as soon
> as it is declared. Is there documentation that explains the order all
> this is evaluated?
>
> Can you explain why the decision was made to do it this way vs. the way
> C# handles this? I know Boo is not C#, and I'm not objecting to it
> functioning differently, I just want to understand the design.
>
> Thanks,
>  - Eric
>
> George wrote:
> > Foo constructor call test = null after super().
>
> > declare it as 'test as string'
>
> > On 12 июн, 21:50, Eric Butler <e...@...> wrote:
> >> Hi everyone,
>
> >> Please see the code below. Is this a bug in Boo or am I doing
> >> something wrong? The same (as far as I can tell) thing written in C#
> >> works as I expect it to.
>
> >> I'm using Boo SVN r3008 and Mono 1.9.1.
>
> >> Thanks!
> >>  - Eric
>
> >> abstract class Bar:
> >>         def constructor():
> >>                 self.go()
>
> >>         abstract def go():
> >>                 pass
>
> >> class Foo(Bar):
> >>         test = null
>
> >>         def constructor():
> >>                  super()
> >>                  if self.test == null:
> >>                         raise "Failure!!"
>
> >>         override def go():
> >>                 self.test = "Hello World"
> >>                 print 'self.test is',self.test
>
> >> f = Foo()
>
> >> output:
>
> >> $ booi test.boo
> >> self.test is Hello World
> >> System.Exception: Failure!!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Trouble setting variable from abstract method implementation that is called by constructor

by cigarette :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


C# Language Specification says:

"""10.10.3 Constructor execution
Variable initializers are transformed into assignment statements,
and these assignment statements are executed BEFORE
the invocation of the base class instance constructor. """

Boo do different things,
its generats a function(named $initializer$?) to initialize instance
variables,
but this function is called AFTER calling base class constructor.

in this case, self.test is assigned "Hello World" by Bar.constructor,
then overridden to null by Foo.$initializer$

On Jun 13, 7:12 am, Eric Butler <e...@...> wrote:

> Hi there,
>
> Thanks for the reply.
>
> Removing the "= null" from the foo declaration does fix the problem,
> however this seems a bit inconsistent/unexpected to me.
>
> My expectation is that the variable would be assigned it's value as soon
> as it is declared. Is there documentation that explains the order all
> this is evaluated?
>
> Can you explain why the decision was made to do it this way vs. the way
> C# handles this? I know Boo is not C#, and I'm not objecting to it
> functioning differently, I just want to understand the design.
>
> Thanks,
>  - Eric
>
>
>
> George wrote:
> > Foo constructor call test = null after super().
>
> > declare it as 'test as string'
>
> > On 12 июн, 21:50, Eric Butler <e...@...> wrote:
> >> Hi everyone,
>
> >> Please see the code below. Is this a bug in Boo or am I doing
> >> something wrong? The same (as far as I can tell) thing written in C#
> >> works as I expect it to.
>
> >> I'm using Boo SVN r3008 and Mono 1.9.1.
>
> >> Thanks!
> >>  - Eric
>
> >> abstract class Bar:
> >>         def constructor():
> >>                 self.go()
>
> >>         abstract def go():
> >>                 pass
>
> >> class Foo(Bar):
> >>         test = null
>
> >>         def constructor():
> >>                  super()
> >>                  if self.test == null:
> >>                         raise "Failure!!"
>
> >>         override def go():
> >>                 self.test = "Hello World"
> >>                 print 'self.test is',self.test
>
> >> f = Foo()
>
> >> output:
>
> >> $ booi test.boo
> >> self.test is Hello World
> >> System.Exception: Failure!!- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Trouble setting variable from abstract method implementation that is called by constructor

by EricButler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi there,

Thank you for clarifying this. I would like to mention that C#, Python,
and Ruby all implement this the way I was expecting, with Boo being the
only exception I've found so far.

George - you mention that this is 'unusual'. In the specific case that
caused me to discover this, I am consuming an existing C# API[1] so it's
not my decision, however it doesn't seem so odd to me at all. I like the
ability to set a default value because it makes the code very explicit.

If the Boo team is satisfied with the current handling, I'm happy to end
the conversation right now, however I don't see the advantage of doing
it this way, especially when it's different from what a developer coming
from many other languages is likely to expect.

Thanks,
 - Eric

[1]:
http://svn.gnome.org/viewvc/banshee/trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/FilteredListSourceContents.cs?view=markup
(Note the InitializeViews() method)

leisurely wrote:

> C# Language Specification says:
>
> """10.10.3 Constructor execution
> Variable initializers are transformed into assignment statements,
> and these assignment statements are executed BEFORE
> the invocation of the base class instance constructor. """
>
> Boo do different things,
> its generats a function(named $initializer$?) to initialize instance
> variables,
> but this function is called AFTER calling base class constructor.
>
> in this case, self.test is assigned "Hello World" by Bar.constructor,
> then overridden to null by Foo.$initializer$
>
> On Jun 13, 7:12 am, Eric Butler <e...@...> wrote:
>> Hi there,
>>
>> Thanks for the reply.
>>
>> Removing the "= null" from the foo declaration does fix the problem,
>> however this seems a bit inconsistent/unexpected to me.
>>
>> My expectation is that the variable would be assigned it's value as soon
>> as it is declared. Is there documentation that explains the order all
>> this is evaluated?
>>
>> Can you explain why the decision was made to do it this way vs. the way
>> C# handles this? I know Boo is not C#, and I'm not objecting to it
>> functioning differently, I just want to understand the design.
>>
>> Thanks,
>>  - Eric
>>
>>
>>
>> George wrote:
>>> Foo constructor call test = null after super().
>>> declare it as 'test as string'
>>> On 12 июн, 21:50, Eric Butler <e...@...> wrote:
>>>> Hi everyone,
>>>> Please see the code below. Is this a bug in Boo or am I doing
>>>> something wrong? The same (as far as I can tell) thing written in C#
>>>> works as I expect it to.
>>>> I'm using Boo SVN r3008 and Mono 1.9.1.
>>>> Thanks!
>>>>  - Eric
>>>> abstract class Bar:
>>>>         def constructor():
>>>>                 self.go()
>>>>         abstract def go():
>>>>                 pass
>>>> class Foo(Bar):
>>>>         test = null
>>>>         def constructor():
>>>>                  super()
>>>>                  if self.test == null:
>>>>                         raise "Failure!!"
>>>>         override def go():
>>>>                 self.test = "Hello World"
>>>>                 print 'self.test is',self.test
>>>> f = Foo()
>>>> output:
>>>> $ booi test.boo
>>>> self.test is Hello World
>>>> System.Exception: Failure!!- Hide quoted text -
>> - Show quoted text -
> >

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


class A:
        def constructor():
                self.go()
       
        abstract def go():
                pass

class B(A):
        test = null

        def constructor():
                super()
                print self.test
       
        def go():
                self.test = "hello world"

B()


public abstract class A
{
        public A ()
        {
                this.Go();
        }

        public abstract void Go();
}

public class B : A
{
        string test = null;

        public B () : base ()
        {
                System.Console.WriteLine(this.test);
        }

        public override void Go ()
        {
                this.test = "hello world";
        }

        public static void Main ()
        {
                new B();
        }
}


class A:
        def __init__(self):
                self.go()

class B(A):
        test = None

        def __init__(self):
                A.__init__(self)
                print self.test

        def go(self):
                self.test = "hello world"

B()


class A
    def initialize()
        self.go()
    end
end

class B < A
    @test = nil

    def initialize()
        super()
        puts @test
    end

    def go()
        @test = "hello world"
    end
end

B.new


class A:
        def constructor():
                self.go()
       
        abstract def go():
                pass

class B(A):
        test

        def constructor():
                super()
                print self.test
       
        def go():
                self.test = "hello world"

B()


Re: Trouble setting variable from abstract method implementation that is called by constructor

by Rodrigo B. de Oliveira :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


2008/6/14 Eric Butler <eric@...>:
>..
> If the Boo team is satisfied with the current handling

That's a bug.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Trouble setting variable from abstract method implementation that is called by constructor

by EricButler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Okay, I added a bug report to track this issue:
http://jira.codehaus.org/browse/BOO-1056

Thanks!
- Eric

Rodrigo B. de Oliveira wrote:
> 2008/6/14 Eric Butler <eric@...>:
>> ..
>> If the Boo team is satisfied with the current handling
>
> That's a bug.
>
> >

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Trouble setting variable from abstract method implementation that is called by constructor

by Cedric Vivier :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Sat, Jun 14, 2008 at 9:01 PM, Rodrigo B. de Oliveira
<rodrigobamboo@...> wrote:
> 2008/6/14 Eric Butler <eric@...>:
>> If the Boo team is satisfied with the current handling
>
> That's a bug.

Might be more complex than that.
When I inlined $initializer$ stuff into the constructors, I've not
changed the order (which also looked weird to me) because of something
I can't remember right now :-/

Maybe it was the 'feature' using self-instance methods within the
initializer (which is forbidden now since it produced unverifiable
code), but it could also be because of some other boo-specific
feature, any guesses ?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---


Re: Trouble setting variable from abstract method implementation that is called by constructor

by Avishay Lavie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I don't understand - what feature of Boo makes it different than C#
and other CLR languages in that it needs its own way of invoking field
initializers? Why can't we just do whatever it is C# does, if we want
consistent behavior?

On Jun 15, 6:52 pm, "Cedric Vivier" <cedr...@...> wrote:

> On Sat, Jun 14, 2008 at 9:01 PM, Rodrigo B. de Oliveira
>
> <rodrigobam...@...> wrote:
> > 2008/6/14 Eric Butler <e...@...>:
> >> If the Boo team is satisfied with the current handling
>
> > That's a bug.
>
> Might be more complex than that.
> When I inlined $initializer$ stuff into the constructors, I've not
> changed the order (which also looked weird to me) because of something
> I can't remember right now :-/
>
> Maybe it was the 'feature' using self-instance methods within the
> initializer (which is forbidden now since it produced unverifiable
> code), but it could also be because of some other boo-specific
> feature, any guesses ?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang
-~----------~----~----~----~------~----~------~--~---

LightInTheBox - Buy quality products at wholesale price