GNOME Bugzilla – Bug 586486
Type inference with explicit ownership
Last modified: 2009-07-23 14:01:17 UTC
Currently, when one uses "var variable = method ()" it isn't clear from that code whether the variable will become owned or unowned (and in future, once the semantics differ, it will never become weak). To define that, one has to type a full type, which is annoying. Thus, it would be much better if it is possible to explicitly define ownership, for example: owned var1 = method (); unowned var2 = method (); weak var3 = method (); I would actually prefer it over using "var", as with Vala's ownership paradigm it is not quite obvious.
I agree, and I think this is more than a simple enhancement, "var" is really confusing and should be deprecated in favor of "owned", "unowned" and "weak".
`var' is always owned, so it's not nearly as confusing as you describe. unowned/weak local variables should only be used very rarely, that is, when dealing with objects of non-reference counting types. In that case it might be better to write a nice GObject-based library on top, though. Can you elaborate why do you apparently need it a lot more often than I do? Reopen the bug if you can show that it would still be useful.
(In reply to comment #2) > `var' is always owned, so it's not nearly as confusing as you describe. Ah, sorry, I have been told otherwise. > unowned/weak local variables should only be used very rarely, that is, when > dealing with objects of non-reference counting types. In that case it might be > better to write a nice GObject-based library on top, though. > > Can you elaborate why do you apparently need it a lot more often than I do? > Reopen the bug if you can show that it would still be useful. > You're assuming nobody using Vala is concerned about performance of simple assignments. Assigning to a ref-counted variable is twelve times (!) slower then a pointer assignment. Imagine owned iterator. That's a crazy waste of processing power.
My concern is different, I just think that "var" is confusing, the name itself does not suggest the reference is owned. weak Object a = ...; var b = a; // I expect to have also a weak reference to an Object. And I also would like to have type inference with unowned and weak references.