From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader01.eternal-september.org!aioe.org!epJzlJsZWlp1WuFmYLlBpQ.user.46.165.242.91.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: on Ada abtract data type vs. OOP. Date: Fri, 9 Sep 2022 12:49:14 +0200 Organization: Aioe.org NNTP Server Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: gioia.aioe.org; logging-data="64904"; posting-host="epJzlJsZWlp1WuFmYLlBpQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org"; User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader01.eternal-september.org comp.lang.ada:64301 List-Id: On 2022-09-09 11:32, Nasser M. Abbasi wrote: > Lets say one does not want to do inheritance. (I think it causes > more problems than it solves actually). You cannot in Ada where one can always inherit from any type in some way or another: - tagged extension: type S is new T with ...; - subtype constraining: subtype S is T; - cloing: type S is new T; > The only difference I see between Ada's ADT and OOP, is that > in Ada, the data itself is separated from the package and must > be passed to the package methods at each call. The data lives > in the client side. This applies to all types and has nothing to do with ADT or OO. A state can be either localized in an object (good design) or kept outside it in global variables (bad design). > While in OOP, the data lives inside the object. (these are called > data memebers). Just like in any type, not even abstract one. E.g. type X is range 1..100; The "data" live in each instance of X. > Let look at this simple example from [...] Stack example > In OOP, the stack itself, would live inside the "module" which will > be the class/object in that case. No, OOP example of stack is exactly the one you cited. There is a type Stack and operations of. A non-OO/ADT stack would be: generic -- No parameters!! package Generic_Integer_Stack is procedure Push (Val : Integer); procedure Pop (Val : out Integer); You get a stack instance this way: package Integer_Stack is new Generic_Integer_Stack; > So the main difference I see, is that in Ada ADT, the data (the stack > in this example) lives on the client side, and the package > just has the methods. The sentence does not make sense to me. OO is ADT. I am not sure which issue you have problem with: - No local states - Stateful vs stateless - Interface vs implementation inheritance > For me, this actually better than OOP. Having methods separated > from data is a good thing. You presented a perfectly OO design of a stack type. A better one would be: package Integer_Stacks is type Stack is tagged limited private; procedure Push (S : in out Stack; Val : Integer); procedure Pop (S : in out Stack; Val : out Integer); Here: - limited because we do not want copy or compare stacks - tagged because we might want to reuse the type implementation. For example: with Integer_Stacks; use Integer_Stack; package Integer_Signaled_Stacks is type Signaled_Stack is new Stack with private; procedure Wait_For_Not_Empty (Stack : in out Signaled_Stack; Timeout : Duration); private overriding procedure Push (S : in out Stack; Val : Integer); overriding procedure Pop (S : in out Stack; Val : out Integer); Here the stack maintains a lock to make it task safe and provides event to wait for non-empty stack. > Is there is something I am overlooking other than this? Again, > assuming one does not want to do inheritance? You cannot. Unless you use an extremely primitive language like C some form of inheritance is always there. > It seems to me that Ada ADT provides all the benefits of OOP and more, > as it does not mix data and methods inside one container. Can you explain what do you mean under mixing data with methods? Ada is very limited in terms of using subprograms as data. Basically you need to resort to pointers or generic formals. You certainly meant something else. > What do other think about this subject? - Ada type system needs an overhaul. - People confuse OOP with OOA&D. OOP is merely a better ADT. - Ada 83 was object-based and its ADT was quite weak. - Ada 95 fixed that, but stopped at single inheritance and dispatch and C++-esque idea of having types (AKA classes) and not so much types (AKA everything else we do not know how to deal right). - Ada 2005 added castrated Java-esque multiple dispatch Nothing happened to the type system since. > Do you think it is > better to do it as OOP, to have the data inside the object, > or like with ADT, where the data instances are on the client side? It is always preferable not to have global variables. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de