From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Unknown constraints and type composition
Date: Thu, 14 Jun 2018 18:19:57 +0200
Date: 2018-06-14T18:19:57+02:00 [thread overview]
Message-ID: <pfu4jf$brh$1@gioia.aioe.org> (raw)
In-Reply-To: pfu23n$csb$1@dont-email.me
On 2018-06-14 17:37, Alejandro R. Mosteo wrote:
> I think I have read somewhere that types with unknown constraints are a
> good way of ensuring you (or your users) don't end with uninitialized
> values:
>
> types Whatever (<>) is [limited] private;
>
> function Create return Whatever;
>
> This seems nice at first sight but when these types have any likelihood
> of ending as members of another type you will hit the "unconstrained
> member" problem.
As well as problems with publicly derived types.
> A workaround then is to use a Indefinite_Holder, but that's an
> imposition on your clients (ugly). If your type is furthermore limited,
> then you must use pointers and consider providing controlledness and
> deallocation in the enclosing type (uglier).
>
> Right now I'm on the point of a new design where I have many
> interrelated types that require initialization calls (it's a C binding).
> And, as always, I'm unsure of the way to go, or if I'm missing another
> technique without shortcomings. Your thoughts if you have any on this
> issue are much appreciated.
Without constructors there is no solution to the problem.
In large projects instead of holder I use a reference-counted controlled
handle. The target's type declaration goes into private packages. The
handles go to the public interface packages. It is tedious [*], but it
the only working method if you want to enforce construction and hide
implementation.
-----------------------
* Because of parallel types hierarchy, lack of delegation support, lack
of interface inheritance.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2018-06-14 16:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-14 15:37 Unknown constraints and type composition Alejandro R. Mosteo
2018-06-14 16:19 ` Dmitry A. Kazakov [this message]
2018-06-14 16:58 ` sbelmont700
2018-06-14 17:53 ` Jeffrey R. Carter
2018-06-15 5:13 ` J-P. Rosen
2018-06-15 9:34 ` Alejandro R. Mosteo
2018-07-08 13:53 ` Jacob Sparre Andersen
2018-06-14 21:28 ` Randy Brukardt
2018-06-15 9:37 ` Alejandro R. Mosteo
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox