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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a046ce7f5ee1fa51 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-12-04 07:24:07 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!news.stealth.net!news.stealth.net!news-out.visi.com!hermes.visi.com!uunet!ash.uu.net!world!news From: Robert A Duff Subject: Re: new_line in a put_line User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Wed, 4 Dec 2002 15:23:14 GMT Content-Type: text/plain; charset=us-ascii References: <1ec946d1.0212020657.2bd8b5c@posting.google.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Organization: The World Public Access UNIX, Brookline, MA Xref: archiver1.google.com comp.lang.ada:31421 Date: 2002-12-04T15:23:14+00:00 List-Id: Dmitry A. Kazakov writes: > On 04 Dec 2002 10:31:15 +0100, Fraser Wilson > wrote: > > >Dmitry A. Kazakov writes: > > > >> Just do not do I/O from them. Define a mutex as a protected object and > >> a spin lock as a controlled type (less troubles with releasing a > >> mutex): > > > >[..] > > > >> procedure Put_Line (Text : String) is > >> Get_It : Lock (Write_Mutex'Access); > >> begin > >> Ada.Text_IO.Put_Line (Text); > >> end Put_Line; > > > >Something inside me rebels at using side-effects from a declaration > >like that. > > Right, right. It is also my opinion [there was a thread regarding this > subject in c.l.a] that using unused (:-)) objects probably indicates a > design problem. A task-based design might be better. There is nothing wrong with declaring a limited controlled object that is used only for its Initialize/Finalize effects. It's a common idiom in Ada (and also in C++). It's the *only* way in Ada to safely ensure that resources get cleaned up -- so telling people not to use it is bad advice, IMHO. You could reasonably argue that Ada ought to have a better syntax for this -- one that does not involve creating dummy types. In fact, such a syntax was proposed as part of Ada 9X, but was rejected on the grounds that limited controlled types provide all the necessary functionality. A task-based design would work just fine, too. - Bob