Re: [Vala] wish for Type Inference working for weak local variables



Jiří Zárevúcky <zarevucky jiri gmail com> writes:

On 08/01/2009 04:36 PM, Łukasz Pankowski wrote:
Hello

According to the Vala tutorial

"Finally Vala has a mechanism called Type Inference, whereby a local
variable may be defined using var instead of giving a type, so long as
it is unambiguous what type is meant."

Type Interface works great for owned variables (for example in
declaration of variable b below) but not for weak variable (neither
declaration of c2 nor c3 works).

I would prefer just "weak" (as in declaration of c2) as shorter, but
maybe "weak var" would be more readable/discoverable?

What do you think about the idea?  Would this be hard to implement?


class Foo {}

void main ()
{
     // var for short
     Foo a = new Foo();
     var b = new Foo();

     // no `weak' for short
     weak Foo c1 = a;
     weak c2 = a;            // syntax error
     weak var c3 = a;                // syntax error
}
   

I and Julien proposed that, but juergbi closed it as WONTFIX without
discussion.
Maybe if more people express their opinion, we could change his mind?

See this bug: http://bugzilla.gnome.org/show_bug.cgi?id=586486

Another performance related usage of the weak variables (apart from one
you mentioned in the bug comment #3) is that properties return weak
variables so the values are copied unless assigned to the weak variable
(as in the code below) and here "weak t = a.str" shortcut would also be
convenient.


class Foo {
    public string str { get; set; }
}

void main ()
{
    Foo a = new Foo();

    // uses g_strdup to duplicate the string
    var s = a.str;
    // no duplication needed
    weak string t = a.str;
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]