From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on ip-172-31-91-241.ec2.internal X-Spam-Level: X-Spam-Status: No, score=0.0 required=3.0 tests=none autolearn=ham autolearn_force=no version=4.0.1 Path: nntp.eternal-september.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Best use cases for OOP (resent quoted sorry) Date: Thu, 28 Aug 2025 17:12:22 +0200 Organization: A noiseless patient Spider Message-ID: <108prkk$1dp7v$1@dont-email.me> References: <108pppp$1dmp6$1@dont-email.me> <108pq1l$1dp6u$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 28 Aug 2025 15:12:21 +0000 (UTC) Injection-Info: dont-email.me; posting-host="6f970729dc22bef6d204ec8c3c6ab955"; logging-data="1500415"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+DtPkElNCFTJWpAhTkBPcCqVi4WYR3juE=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:qpbrJj8GxnU5FEuMgstdnN8qnsA= In-Reply-To: <108pq1l$1dp6u$1@dont-email.me> Content-Language: en-US Xref: feeder.eternal-september.org comp.lang.ada:66977 List-Id: On 2025-08-28 16:45, Kevin Chadwick wrote: > I have struggled to find compelling reasons to use tagged types considering > they affect the size of records and potentially elaboration issues that > cannot exist without tagged types. Nothing forces you to use variant sizes or construction hooks. The advantage is the you can, if you need it. > I know some use tagged types just for dot notation but that doesn't really > move the needle in my mind. I would certainly appreciate it if people could > share their favourite use cases for tagged types though. Things that are > perhaps a pain without them or were with Ada 83. 1. The easiest example is network protocols. If you take a look at the Simple Components implementation, then the server and client know nothing about the actual protocol. They simply read and write chunk of data. Upon connection a factory is called which returns an instance of a connection object. This type implements HTTP, MQTT, ModBus, LDAP whatever. The server/client simply passes data to the object for processing. That are dispatching calls. 2. Syntax tree. The nodes of the tree are tagged types. You can nicely reuse parts of implementation, e.g. numeric literals etc. You can inspect an implementation of Ada expression parser. The parser itself knows nothing about Ada. It is the same parser that is used for JSON or XPM. 3. GUI widgets it are practically impossible to have without OO, as you need a hierarchy of and an ability to create new widgets using the old ones. In AICWL layers of a gauge, oscilloscope, meter are tagged types. The instrument is drawn by drawing each layer via a dispatching call. 4. Practically all container types are tagged in order to extend functionality but also for generic programming. Consider an ability to iterate a container. All iteratable containers form a class. With tagged types you can formally define such a class as an interface and inherit it in vector, map, set. You can do that with generics too, but that would force everything generic. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de