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



On 08/01/2009 08:14 PM, Hans Vercammen wrote:
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.

It seems to me none of those discussions were really conclusive.

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).

Potentially, yes. But experienced programmer would have no problem with that. If there is no way the problem could ever happen, why not use some optimizations?

  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.

That's true for unowned as well.

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 :)


Well, that's a very rough measurement taken by timing a loop. Not quite precise, but does show a significant difference. How it affects a real program is an entirely different question. I've created a simple exemplary application that analyzes an XML tree. It relies heavily on iteration and so far the difference in total running time is roughly 3-4%. So I guess it's not really significant in most cases.

Yet, I'm kinda wondering about one thing. It seems to me some people were, are and will be wanting inference for weak variables, regardless the real benefits may be negligible. Even if it were just to have nice C code where the reffing is not needed. Still, every time the question comes up, people will spend much more time arguing the insignificance then it would take to actually implement it... Quite

[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]