comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Ada-Oriented GUI
Date: Thu, 29 Mar 2018 09:58:57 +0200
Date: 2018-03-29T09:58:57+02:00	[thread overview]
Message-ID: <p9i6c0$1rpi$1@gioia.aioe.org> (raw)
In-Reply-To: p9gll3$g3m$1@dont-email.me

On 2018-03-28 20:07, Alejandro R. Mosteo wrote:
> On 28/03/18 17:02, Dmitry A. Kazakov wrote:
>> On 28/03/2018 16:09, Alejandro R. Mosteo wrote:
>>> On 24/03/18 14:12, Dmitry A. Kazakov wrote:
>>
>>>> Now, programming this is like scratching your left ear with the 
>>>> right hand. I keep on asking for co-routines in Ada to break out of 
>>>> this lousy awful mess. To rein assorted mess of events/callbacks 
>>>> into a sequence imperative calls to be a able to program it as if it 
>>>> were an uninterrupted thread of control maintaining its state, just 
>>>> like if the I/O were synchronous.
>>>
>>> I've never used coroutines. Since this kind of "imperative-like" 
>>> sequences is what Rx provides, I understand that coroutines will 
>>> allow the same without staying in the declarative realm?
>>
>> I think so. Let you have Start_Write call and Write_Complete callback. 
>> The idea is to be able to write code in a "blocking" manner like:
>>
>>     declare
>>        State : ...; -- Data local to the co-routine
>>     begin
>>        Start_Write (...);
>>        Wait_For_Complete (...); -- Give up the thread of control until
>>        ...                      -- Write_Complete
>>        Start_Write (...);
>>        ...
>>
>> My understanding is that the "functional" style with closures is an 
>> alternative to this which calls Start_Write and then queues a closure 
>> to be called on Write_Complete. The closure will carry State with it 
>> and perform chained actions.
> 
> I think your understanding is right. Talking Rx, the data being 
> processed should ideally be the state. Actions need not be technically 
> closures, since they receive and return the data to pass along (I might 
> be imprecise here about closures; this is a problem of having studied CS 
> in another [human] language).

If this is only data, then it is just standard OO approach:

    type IO_Request is abstract ...
    procedure Complete_Write (Request : in out IO_Request) is abstract;

    procedure Start_Write
              (  File : in out File_Type;
                 Request : in out IO_Request'Class
              );

You derive from IO_Request, override Complete_Write, queue it using 
Start_Write.

The problem is that the program logic is split between bodies, which 
makes this method so uncomfortable.

> You can have actual closures too, and lambdas in recent Java. In my Ada 
> implementation subprograms cannot be closures since they have to be at 
> library level (I guess those and instantiations can be considered 
> closures on the library level, I fear I'm mixing theoretical and 
> implementation concepts here. I'm referring as a closure to a subprogram 
> that accesses the enclosing subprogram scope.)

Yes, this is what I meant.

> A similar example in RxAda would be:
> 
> procedure Write (Item : in Item_Type) is ...
>     -- Take as much time as needed to write the Item
> end Write;
> 
> declare
>     S : Subscription :=
>       Generator_Of_Items &      -- May generate them at any pace
>       --  Pre-write actions would go here
>       On_Next (Write'Access) &  -- Write as they come
>       --  Post-write-actions would come here
>       Subscribe;
> begin
>     null; -- Nothing to do here
> end;
> 
> Or you can:
> 
> declare
>     S : Subscription :=
>       Generator_Of_Items &         -- May generate them at any pace
>       Subscribe_On (Background) &  -- Ensures Generator goes to BG
>       Map (Process'Access) &       -- Preprocess/transform items
>       Observe_On (Writer_Pool) &   -- Use a pool of dedicated tasks
>       On_Next (Write'Access) &     -- Writes one item
>       Subscribe;
> begin
>     null; -- Proceed with other things
> end;

Replacing ";" with "&"? (:-)) The real horrors start with conditional 
choices, loops, passing results from earlier steps down the chain, 
handling exceptions, honoring time constraints etc, everything we can 
keep simple and elegant in the "blocking" approach.

>> Needless to say that I don't find closures any appealing.
> 
> I seem to remember your objections from other threads, but I don't 
> remember why exactly (I found them very cumbersome for the standard 
> containers before the latest syntax sugar).

It not much the closures, but the programming style which forces program 
logic inversion. The things of primary reader's interest happen in 
bodies you pass as parameters or as primitive operations of parameters 
(in OO case). This is just a bad model. In that aspect it is no 
different from traditional callbacks.

OO decomposition wraps these callbacks into primitive operations.

"Functional" decomposition wraps callbacks into closures.

In both case the mess stays.

Choosing between these two I clearly in favor of OO, because it 
encapsulates the state into the object while the closure does it in some 
implicit way. Using plain access-to-subprogram instead of closure is the 
worst approach because maintaining the state is left to the programmer, 
which ends up with ugly void * User_Data passed around to be cast from 
type to type at run-time.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  reply	other threads:[~2018-03-29  7:58 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-18 13:33 Ada-Oriented GUI Jeffrey R. Carter
2018-03-19  2:03 ` Dan'l Miller
2018-03-19 14:10   ` Dan'l Miller
2018-03-21  9:49     ` Alejandro R. Mosteo
2018-03-21 13:58       ` Dan'l Miller
2018-03-21 18:43         ` briot.emmanuel
2018-03-21 19:17           ` Shark8
2018-03-21 22:40             ` Randy Brukardt
2018-03-21 23:52               ` Shark8
2018-03-22  6:50                 ` briot.emmanuel
2018-03-22 16:56                   ` Shark8
2018-03-23 16:29               ` Shark8
2018-03-23 22:59                 ` Randy Brukardt
2018-03-23 23:43                   ` Mehdi Saada
2018-03-26 22:09                     ` Randy Brukardt
2018-03-27  7:27                       ` Dmitry A. Kazakov
2018-03-27 23:58                         ` Randy Brukardt
2018-03-28  7:09                           ` Dmitry A. Kazakov
2018-03-22 17:34         ` Alejandro R. Mosteo
2018-03-22 17:50           ` Dan'l Miller
2018-03-22 18:58             ` Shark8
2018-03-23 12:06             ` Alejandro R. Mosteo
2018-03-20 16:41 ` Dan'l Miller
2018-03-20 21:34   ` Randy Brukardt
2018-03-21  2:22     ` Dan'l Miller
2018-03-21 21:50       ` Randy Brukardt
2018-03-22  8:45         ` Dmitry A. Kazakov
2018-03-22 10:58         ` Bojan Bozovic
2018-03-22 11:03           ` Bojan Bozovic
2018-03-21  8:25 ` Dmitry A. Kazakov
2018-03-21 14:30   ` Dan'l Miller
2018-03-21 15:57     ` vincent.diemunsch
2018-03-21 17:33       ` Dan'l Miller
2018-03-21 16:27     ` Dmitry A. Kazakov
2018-03-21 17:04       ` Dan'l Miller
2018-03-21 17:42         ` Dmitry A. Kazakov
2018-03-21 18:19           ` Dan'l Miller
2018-03-21 19:11             ` Simon Wright
2018-03-21 19:51               ` Dan'l Miller
2018-03-21 20:11                 ` Dmitry A. Kazakov
2018-03-21 20:33                   ` Dan'l Miller
2018-03-21 22:16                   ` Dan'l Miller
2018-03-22  9:12                     ` Dmitry A. Kazakov
2018-03-22 14:57                       ` Dan'l Miller
2018-03-22 15:46                         ` Bojan Bozovic
2018-03-22 14:00                     ` Dan'l Miller
2018-03-22 17:29                   ` Alejandro R. Mosteo
2018-03-21 21:58             ` Randy Brukardt
2018-03-26 21:20               ` G. B.
2018-03-21 22:33             ` Randy Brukardt
2018-03-22  1:43               ` Dan'l Miller
2018-03-22 23:47                 ` Randy Brukardt
2018-03-23  2:37                   ` Dan'l Miller
2018-03-23 22:42                     ` Randy Brukardt
2018-03-24  7:47                       ` Simon Wright
2018-03-23  9:05                   ` Jeffrey R. Carter
2018-03-23  9:48                     ` Bojan Bozovic
2018-03-23 10:20                     ` Alejandro R. Mosteo
2018-03-27 18:32                     ` Killing software and certification (was: Ada-Oriented GUI) Alejandro R. Mosteo
2018-03-27 19:25                       ` Killing software and certification Dmitry A. Kazakov
2018-03-28 13:54                         ` Alejandro R. Mosteo
2018-03-28 14:23                           ` Dmitry A. Kazakov
2018-03-28 17:06                             ` Alejandro R. Mosteo
2018-03-28 19:35                               ` Dmitry A. Kazakov
2018-03-28 15:47                           ` Jeffrey R. Carter
2018-03-28 17:02                             ` Dennis Lee Bieber
2018-03-28 17:59                             ` Dan'l Miller
2018-03-27 19:41                       ` Killing software and certification (was: Ada-Oriented GUI) Dan'l Miller
2018-03-28  0:04                         ` Randy Brukardt
2018-03-28  2:27                           ` Dan'l Miller
2018-03-28 13:54                           ` Killing software and certification Alejandro R. Mosteo
2018-03-28  0:21                       ` Killing software and certification (was: Ada-Oriented GUI) Jere
2018-03-28 13:54                         ` Killing software and certification Alejandro R. Mosteo
2018-03-23 12:31                   ` Ada-Oriented GUI Alejandro R. Mosteo
2018-03-23 12:59                     ` Dmitry A. Kazakov
2018-03-23 16:16                       ` Dan'l Miller
2018-03-23 17:18                         ` Dmitry A. Kazakov
2018-03-23 18:31                           ` Dan'l Miller
2018-03-23 20:06                             ` Dmitry A. Kazakov
2018-03-23 20:48                               ` Mehdi Saada
2018-03-23 21:18                                 ` Dmitry A. Kazakov
2018-03-24 11:36                       ` Alejandro R. Mosteo
2018-03-24 13:12                         ` Dmitry A. Kazakov
2018-03-28 14:09                           ` Alejandro R. Mosteo
2018-03-28 15:02                             ` Dmitry A. Kazakov
2018-03-28 18:07                               ` Alejandro R. Mosteo
2018-03-29  7:58                                 ` Dmitry A. Kazakov [this message]
2018-04-02 22:13                               ` Robert I. Eachus
2018-04-03  8:31                                 ` Dmitry A. Kazakov
2018-04-03 22:32                                   ` Robert I. Eachus
2018-04-04  7:30                                     ` Dmitry A. Kazakov
2018-03-25 12:57                         ` Jeffrey R. Carter
2018-03-24 16:33                   ` Dan'l Miller
2018-03-26 22:29                     ` Randy Brukardt
2018-03-27  0:15                       ` Dan'l Miller
2018-03-27  6:08                       ` Dennis Lee Bieber
2018-03-27  7:52                         ` Simon Wright
2018-03-27 14:48                           ` Dennis Lee Bieber
2018-04-01 17:37                       ` Robert I. Eachus
2018-03-25 19:19 ` Andrew Shvets
  -- strict thread matches above, loose matches on Subject: below --
2018-03-23 22:48 Randy Brukardt
2018-03-24  7:51 ` Simon Wright
replies disabled

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