Re: [Vala] Ownership syntax changes
- From: Jürg Billeter <j bitron ch>
- To: Hans Vercammen <hveso3 gmail com>
- Cc: vala-list <vala-list gnome org>
- Subject: Re: [Vala] Ownership syntax changes
- Date: Sat, 20 Dec 2008 08:24:04 +0100
On Sat, 2008-12-20 at 02:19 +0100, Hans Vercammen wrote:
On Fri, 2008-12-19 at 12:10 +0100, Jürg Billeter wrote:
* `(owned)' cast replaces `#' reference transfer expression
Even less used, equally unintuitive. Example of new syntax:
string foo = (owned) bar;
I don't have a strong opinion on this since I don't really need it, but
using a cast expression feels a bit wrong. Not sure if we want to keep
the option open of having operator overloading, but what about something
like:
string foo <= bar;
or
string foo << bar;
In my opinion, this is not a lot clearer than the # syntax. The idea is
to use a more descriptive syntax so that reading code gets easier. As it
shouldn't be used often, a few characters more to type should not be an
issue.
Furthermore, please note that it needs to be an expression, it can also
be used as a method argument, not just in assignments.
some_method (42, (owned) bar);
* `unowned' type modifier complements `weak' type modifier
`weak' only make sense for reference fields, list elements, and local
variables to break reference cycles. Vala will use
`g_object_add_weak_pointer' in these places in future versions.
I definitely agree we should avoid dangling pointers as much as
possible. However, I fear a bit that many people will turn to using
pointers when this is also applied to local variables.
Why do you think people will switch to pointers? Do you have an example
in mind where the change might cause issues?
In other places where `weak' is currently used such as method return
values or fields of non reference counted types, it has the meaning of
"no ownership transfer". This is mostly used in bindings but can also be
used in Vala code to fine-tune the ABI. In my opinion, `unowned' as
counterpart to `owned' fits better in those places.
It probably depends how you look at it. Personally, I tend to think in
terms of shared and weak references. Owned and unowned seem to suggest
an object can only be owned in one place.
I agree, however, owned and unowned are mainly used for non-reference
counted objects such as strings or GLists. They can really only be owned
in one place, and that's why I think it makes sense to use these names.
Users should be very careful about unowned references as they are really
unsafe.
Jürg
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]