[nem-en] Declaring Properties in the constructor - ala Boo

Mark Haniford markhaniford at gmail.com
Fri Sep 29 10:22:33 CEST 2006


Hi,

I think one of the neat features of Boo is that you can declare property
values in the constructor:
http://boo.codehaus.org/Part+09+-+Methods#Part09-Methods-DeclaringPropertiesintheConstructor

e.g.  window = Window (Width: 800, Height: 600, Title: "Window");  // where
Width, Height, and Title are all public properties in the class Window

This feature seems very convienent to me.  It would probably be pretty easy
to write a macro to do it too, e.g. window = Construct(SomeClass, Width:
800, Height: 600, Title: "Window");

But would it be more convenient to have it in the compiler proper?  In the
case of constructors with arguments, you could disallow it, or have optional
property arguments after the defined constructor arguments


class SomeClass
{
    [Accessor(AnInt, flags=WantSetter)]
    private mutable _an_int : int;

    [Accessor(AString, flags=WantSetter)]
    private mutable _a_string : string;


    public this(i : int) {
        AnInt = i;
    }
}

sc = SomeClass(3, AString: "hello");
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /mailman/pipermail/devel-en/attachments/20060929/785a099f/attachment.html


More information about the devel-en mailing list