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 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: What is your opinion on Global Objects? Date: Sat, 22 Nov 2014 10:02:53 +0100 Organization: cbb software GmbH Message-ID: <1rh9s6fzqenal$.1u94l5nsktwsj$.dlg@40tude.net> References: <1tz9u84opgdwc$.a7dpkorp05gp.dlg@40tude.net> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: wfRpp7ltpEWhI2na6kgpfA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:23633 Date: 2014-11-22T10:02:53+01:00 List-Id: On Sat, 22 Nov 2014 08:46:36 +0100, J-P. Rosen wrote: > Le 21/11/2014 10:01, Dmitry A. Kazakov a écrit : >> On Thu, 20 Nov 2014 22:35:16 +0100, J-P. Rosen wrote: >> >>>> 1. You are hardcoded to a particular implementation (i.e. no dispatching) >>> Yes, it is more static, therefore safer and more easily provable. >> >> This is a bit contradictory. Proofs as such are always against some stated >> things. That already presumes several instances. Some instances may >> withstand the proof some don't. Thus the idea of proving an inherent >> singleton looks somewhat dubious. Singleton is only in the usage not a >> property. > Not at all. Where we differ is that you are thinking in terms of classes > first, then instances. You see the properties at class level, and then a > singleton (a class with a single instance) makes little sense. Correction: not classes, types. An instance, an object has a type. Instances of types form a class. Classes are relevant only when reuse comes in question. > I am thinking in terms of objects first. Objects have properties. If > several objects share a common behaviour, then I group them into > "equivalence classes", and the common properties of the objects become > the properties of the class. If you think objects first, singletons make > perfect sense. Yes. That is what OOA/D say. I don't believe in OOA/D in software design. To me it is ad hocery and, worse, untyped. >> And you forgot about reuse. A singleton implementation may use some other >> types implementations or provide its implementation for reuse. > You implicitely think of reuse by inheritance. I favor reuse by composition. So what? You could find useful to reuse parts of the singleton implementation per composition as well. >>>> 3. The majority of the program becomes impure > Not really. If your problem requires a global state, then it is > "impure". Whether you use global variables in a package or a global > object gathering the data that you pass to subprograms does not change > anything. It does for the clients because it clearly defines the context the client is allowed to update. The origin of the context if it is global or not, plays no role to the client. In particular, the functionality of the client does not depend on whether the context is a singleton. One constraint less to be aware of, safer is the design. >>>> 5. Everything is compile-time constant (i.e. no creating or deleting things dynamically). >>> I would regard this as a huge benefit - dynamicity has always been >>> opposed to simplicity and provability. >> >> Huh, that reminds me of a relatively fresh discussion about termination of >> a library-level task in Ada. A typical singleton, isn't it? Yet impossible >> to terminate on application exit! > ??? Select ... or terminate works perfectly well for library tasks. I do > that all the time. It was not possible to have terminate alternative (in practice it is almost always so). -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de