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



Hi,

On Sat, 2009-08-01 at 16:53 +0200, Jiří Zárevúcky wrote:
On 08/01/2009 04:36 PM, Łukasz Pankowski wrote:
"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?
[...]

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


This discussion came up a few times before on the mailing list [1,2],
please query the archives and bugzilla first if you are unsure about
something.
Using weak/unowned is mainly intended for the bindings and in case you
need to break cycles to prevent memory leaks. Furthermore weak/unowned
variables could potentially create dangerous dangling pointers as there
is no certainty the memory pointed to is valid (think multi-threaded for
example). The overhead of reference counting is usually neglectable as
those interfaces are most likely in the cache already. For non-reference
counted types, you probably want the use transfer ownership or as Jürg
suggested write a nice GObject library on top that plays well with the
rest of the stack. And then there is also the possibility of using
pointers in vala, but then you are basically on your own without any
guaranties.

As you seem to claim that "Assigning to a ref-counted variable is twelve
times (!) slower then a pointer assignment." I would be very interested
in detailed profiling info to support that, or at least showing that
this is causing a significant slower program :)

[1] http://mail.gnome.org/archives/vala-list/2008-December/msg00051.html
[2] http://mail.gnome.org/archives/vala-list/2008-September/msg00011.html

Regards,
Hans




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