comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Discriminants or Constructor Function for Limited Types
Date: Thu, 5 May 2022 20:53:27 -0500	[thread overview]
Message-ID: <t51v2o$enb$1@dont-email.me> (raw)
In-Reply-To: t4vsfi$jtb$1@gioia.aioe.org

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:t4vsfi$jtb$1@gioia.aioe.org...
> On 2022-05-05 01:49, Randy Brukardt wrote:
>
>> Those cases that you worry are "unsafe" seem to me to only occur because 
>> of
>> "hacks and workarounds". There's no good reason to do any of those things
>> intentionally unless you are using a "hack" to do something dubious in 
>> the
>> first place.
>
> Is a task component a hack? Well so long there is no tagged task types 
> aggregation is the only way.

Task objects look like a cool language feature, but use beyond the simplest 
patterns will get one into a load of trouble (deadlocks, erroneous use of 
objects, etc.) Almost all of the correct uses of seen are implementations of 
the "pool of workers" scheme. But you can do that without any explicit tasks 
by using the Ada 2022 parallelism features, and that's a lot safer because 
they include checks against most of the problems. (At least, you can once 
they're implemented.) Or one could use a library like Brad Moore's to do 
that (letting it handle the tasks).

So, very much like writing your own basic data structures from scratch, this 
is a feature which is mostly OBE. (Embedded uses are mostly Ravenscar, and 
that doesn't allow dynamically started tasks in the first place.)

> Controlled types are hacks, yes, but there is no alternative. You admit 
> that all tagged types (and I would say all types) should be controlled = 
> support user-defined initialization hooks.

I don't think I said anything about controlled types being hacks.

> Dispatching from Initialize is a double hack, but again, if you need it, 
> the alternative, client-side manual initialization is way worse.

Agree here.

> Exception propagation upon initialization? There is no enforceable 
> exception contracts to fight it.

But you don't (or shouldn't) care what happens to an object when an 
exception is raised during initialization. The program is wrong, it needs to 
be fixed, end of story. On top of that, the language guarentees that all 
(controlled) objects that are initialized will get finalized (even when 
exceptions happen), so there is no possible leakage from a well-designed 
controlled type. So even in the case of a program that must keep running, 
resources will not be leaked or corrupted. You can handle the exception and 
retry. What you can't do is use the object that failed for anything, so the 
fact that you don't know if it was fully initialized is irrelevant.

> So I say, if hacks occur, then because of the language problems, not only 
> because some lazy programmer does something stupid.

You have a strange idea of language problems. (But of course I've known that 
for a long while; I've written these responses for the benefit of lurkers 
and the OP, not so much to convince you of anything. :-)

                                     Randy.


  reply	other threads:[~2022-05-06  1:53 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-04  9:02 Discriminants or Constructor Function for Limited Types R R
2022-05-04  9:40 ` Jeffrey R.Carter
2022-05-04  9:47 ` Dmitry A. Kazakov
2022-05-04 23:49   ` Randy Brukardt
2022-05-05  6:56     ` Dmitry A. Kazakov
2022-05-06  1:53       ` Randy Brukardt [this message]
2022-05-06  8:48         ` Dmitry A. Kazakov
2022-05-07  3:26           ` Randy Brukardt
2022-05-07 14:55             ` Dmitry A. Kazakov
2022-05-08  2:32               ` Randy Brukardt
2022-05-08  8:37                 ` Dmitry A. Kazakov
2022-05-08 17:19                   ` Doctor Who
2022-05-08 18:00                     ` Dmitry A. Kazakov
2022-05-08 18:07                       ` Doctor Who
2022-05-09  8:52                       ` Niklas Holsti
2022-05-09  9:45                         ` Dmitry A. Kazakov
2022-05-09 10:19                       ` Doctor Who
2022-05-09 11:15                         ` Dmitry A. Kazakov
2022-05-09 12:05                           ` Doctor Who
2022-05-09 12:31                             ` Dmitry A. Kazakov
2022-05-10  4:48                   ` Randy Brukardt
2022-05-10  6:18                     ` Dmitry A. Kazakov
2022-05-04 15:05 ` AdaMagica
2022-05-05  9:59 ` R R
replies disabled

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