comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: Object-Oriented style question
Date: Tue, 10 Jan 2012 00:47:19 -0800 (PST)
Date: 2012-01-10T00:47:19-08:00	[thread overview]
Message-ID: <36ee3b54-496c-41d4-a8ba-3357741adada@p4g2000vbt.googlegroups.com> (raw)
In-Reply-To: 4f0b7f2b$0$7617$9b4e6d93@newsspool1.arcor-online.net

On Jan 10, 12:58 am, Georg Bauhaus <rm-
host.bauh...@maps.futureapps.de> wrote:

> Wouldn't the following lookup function handle the situation?
>
>     function Lookup (Table  : Dictionaries.Map;
>                      Object : T'Class) return Boolean is
>     begin
>        return Table.Contains (Object'Unchecked_Access);
>     end Lookup;

> Object denotes an object, then, so no nulls. Therefore, passing
> the result of 'Unchecked_Access to function "Contains" should
> be safe in the sense that Contains always gets a meaningful
> access value to be used as a key.

Yes, but this also brings an idea for some typing convention, which I
happen to use.
The idea is to somehow express the expectation that the operation has
with regard to the lifetime of the object and with regard to the
aliasing that can be involved. In the case of Info, where no access
value is used, the operation expects nothing, which means that it
should not leak the reference to the object (store it, etc.). That is,
after the operation completes, the object can be destroyed with no
consequences, as no alias was created.
In the case of Info_3 (or any other operation that accepts access
values), the operation can assume that the object lives longer and can
therefore leak (store, etc.) the reference and make new alias - it is
up to the user to figure out the complete lifetime management.

Of course, this convention is not checked statically (other than with
the usual rules for access types, which can be bypassed with
Unchecked_XXX anyway), but is a good hint for the user with regard to
object lifetime expectations.

For this reason I would explicitly use access values in the profile if
the operation stores the access value in a dictionary.
The user should know that there is some aliasing going on there.

> The effect is that there still wouldn't be any parameters of an
> anonymous access-to-object type at the level of T's definition.

Why this should be a goal?
I prefer if the profile describes what is going on. If sh*t is going
on, then it is better to show it in the profile than to hide it and
surprise the user later.

--
Maciej Sobczak * http://www.inspirel.com



  reply	other threads:[~2012-01-10  8:47 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-08 12:45 Object-Oriented style question Georg Bauhaus
2012-01-08 12:52 ` Simon Wright
2012-01-08 13:25   ` Dmitry A. Kazakov
2012-01-08 14:18 ` Robert A Duff
2012-01-08 20:32   ` Martin Dowie
2012-01-08 20:52     ` Robert A Duff
2012-01-09 22:34   ` Adam Beneschan
2012-01-09 23:21     ` Robert A Duff
2012-01-10  8:34     ` Dmitry A. Kazakov
2012-01-09  8:55 ` Maciej Sobczak
2012-01-09 23:58   ` Georg Bauhaus
2012-01-10  8:47     ` Maciej Sobczak [this message]
2012-01-10 10:27       ` Dmitry A. Kazakov
2012-01-10 12:27       ` Georg Bauhaus
2012-01-11  8:54         ` Maciej Sobczak
2012-01-10 21:26       ` Randy Brukardt
2012-02-08 12:23 ` Yannick Duchêne (Hibou57)
2012-02-08 12:39 ` Yannick Duchêne (Hibou57)
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox