From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b307bd75c8071241 X-Google-Attributes: gid103376,public From: "John G. Volan" Subject: Assuaging sour grapes :-) [was: newbie Q: storage management] Date: 1997/05/06 Message-ID: <336FDF8B.73AF@sprintmail.com> X-Deja-AN: 239921089 References: <5k5hif$7r5@bcrkh13.bnr.ca> <336A065B.41C6@magellan.bgm.link.com> <336E15A4.167E@magellan.bgm.link.com> <5knhge$mul@top.mitre.org> Reply-To: johnvolan@sprintmail.com Newsgroups: comp.lang.ada Date: 1997-05-06T00:00:00+00:00 List-Id: Michael F Brenner wrote: > Another reason to open up the group to more people is that this group feels > that certain problems have been solved, according to recent posts. I said the problems you described _might_ have been solved, but without something more than the sketchy description you gave, it's hard to tell. > However, > some people in the community do not have access to the reasons why they > think they have been solved. In recent posts, I have been told that there > are machine- and compiler-independent ways within Ada-95 to > - put bits into a byte > - do stream_IO > - select alternate bodies for packages > (for example, 1000 device drivers with the same visible part, > of which one is selected as part of a computer program) I asked you to show a fleshed-out example of this this last problem so I or others could perhaps help you, but so far I haven't seen it. But let me take a guess at it any way: -------------------------------------------------------------------- package Drivers is type Driver_Type is abstract tagged limited private; type Driver_Access_Type is access all Driver_Type'Class; procedure Some_Primitive_Operation_Every_Driver_Must_Support (Driver : in out Driver_Type; ... -- other parameters) is abstract; procedure Some_Other_Primitive_Operation_Every_Driver_Must_Support (Driver : in out Driver_Type; ... -- other parameters) is abstract; ... -- etc. procedure Some_Reusable_Algorithm_That_Should_Work_With_Any_Driver (Driver : in out Driver_Type'Class; -- classwide, not inherited ... -- other parameters); -- not abstract, actually implemented here in terms of -- the primitives (could be written anywhere actually) ... end Drivers; -------------------------------------------------------------------- package Drivers.Mark_1 is type Mark_1_Driver_Type is new Driver_Type with private; procedure Some_Primitive_Operation_Every_Driver_Must_Support (Mark_1_Driver : in out Mark_1_Driver_Type; ... -- other parameters); procedure Some_Other_Primitive_Operation_Every_Driver_Must_Support (Mark_1_Driver : in out Mark_1_Driver_Type; ... -- other parameters); ... -- etc. end Drivers.Mark_1; -------------------------------------------------------------------- ... repeat 1000 times -------------------------------------------------------------------- package Drivers.Mark_1000 is type Mark_1000_Driver_Type is new Driver_Type with private; procedure Some_Primitive_Operation_Every_Driver_Must_Support (Mark_1000_Driver : in out Mark_1000_Driver_Type; ... -- other parameters); procedure Some_Other_Primitive_Operation_Every_Driver_Must_Support (Mark_1000_Driver : in out Mark_1000_Driver_Type; ... -- other parameters); ... -- etc. end Drivers.Mark_1000; -------------------------------------------------------------------- with Drivers.Mark_123; ... -- and some other stuff procedure Tuesdays_Driver_Application is -- On Tuesday, we chose the Mark-123 driver implementation: Tuesdays_Driver : Drivers.Mark_123.Mark_123_Driver_Type; ... and some other stuff begin ... Drivers.Some_Reusable_Algorithm_That_Should_Work_With_Any_Driver (Driver => Tuesdays_Driver, ...); ... end Tuesdays_Driver_Application; -------------------------------------------------------------------- with Drivers.Mark_456; ... -- and some other stuff procedure Wednesdays_Driver_Application is -- On Wednesday, we chose the Mark-456 driver implementation: Wednesdays_Driver : Drivers.Mark_456.Mark_456_Driver_Type; ... and some other stuff begin ... Drivers.Some_Reusable_Algorithm_That_Should_Work_With_Any_Driver (Driver => Wednesdays_Driver, ...); ... end Wednesdays_Driver_Application; -------------------------------------------------------------------- with Drivers.Mark_1; ... -- repeat 1000 times with Drivers.Mark_1000; package Drivers.Selection is Mark_1_Driver : aliased Drivers.Mark_1.Mark_1_Driver_Type; ... -- repeat 1000 times Mark_1000_Driver : aliased Drivers.Mark_1000.Mark_1000_Driver_Type; type Driver_Index_Type is range 1 .. 1000; -- if your driver implementations have better names than "Mark n", -- then perhaps this could be an enumerated type called -- "Driver_Name_Type" type Driver_Selection_Type is array (Driver_Index_Type) of Driver_Access_Type; -- array of classwide pointers Driver_Selection : constant Driver_Selection_Type := (1 => Mark_1_Driver'Access, 2 => Mark_2_Driver'Access, ... -- repeat 1000 times 999 => Mark_999_Driver'Access, 1000 => Mark_1000_Driver'Access); end Drivers.Selection; -------------------------------------------------------------------- with Drivers.Selection; ... -- and some other stuff package Dynamic_Interactive_Driver_Selection_Application is Driver_Index : Drivers.Selection.Driver_Index_Type; ... -- and some other stuff begin ... -- query the user for the Driver_Index, -- maybe using Ada.Text_IO Drivers.Some_Reusable_Algorithm_That_Should_Work_With_Any_Driver (Driver => Drivers.Selection.Driver_Selection(Driver_Index).all, ... ); ... -- maybe this is all in a loop, so the user can actually ... -- change the driver selection as the program progresses end Dynamic_Interactive_Driver_Selection_Application; Okay, so now you have a heterogeneous array of drivers, each with a different implementation, but all implementing the same abstract interface. You can even dynamically select the driver at run time! What would arrays of packages give you that this doesn't? If you want an array of "first-class objects" why not just use ... an array of first class objects! :-) Side note: If you were going to try and solve a problem like this in some other object-oriented programming language (e.g., C++, Eiffel, Smalltalk ...), the solution would pretty much follow the same design pattern: You'd have a bunch of concrete-implementation subclasses inheriting from some abstract class. Your client code would base its (reusable) algorithms solely on the primitive interface provided by the abstract class, working with a "classwide" view of the instance object (in C++ you'd have to be dealing with a reference (&) or a pointer (*) to an instance of your base class). The only downside I can see to this design pattern is that the use of classwide programming means that you get dynamic dispatching, which adds a bit of overhead -- but from your sketchy description, it sounded like you needed to be able to select the implementation at run time anyway. > But I do not know how to accomplish these things in a machine- and > compiler-independent manner, using the pragmas, attributes, and features > of the Ada-95 language in the ISO standard. Therefore, either I am > ignorant in these three areas, or the standard needs specific examples > in these three areas, or the language needs to be fixed to do these > important things portably. A standards document such as the Ada95 Reference Manual can't be all things to all people. Its job is to formally specify the language, not necessarily to provide a readable tutorial for its use. There are other places you ought to try for such tutorial help, including asking for help on comp.lang.ada. But please work _with_ the folks here. We're generally a friendly bunch, not at all the shadowy cabal of language politicos you seem to be painting us as ... :-) ------------------------------------------------------------------------ Internet.Usenet.Put_Signature (Name => "John G. Volan", Home_Email => "johnvolan@sprintmail.com", Slogan => "Ada95: The World's *FIRST* International-Standard OOPL", Disclaimer => "These opinions were never defined, so using them " & "would be erroneous...or is that just nondeterministic now? :-) "); ------------------------------------------------------------------------