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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.70.140.138 with SMTP id rg10mr13905411pdb.1.1404751080434; Mon, 07 Jul 2014 09:38:00 -0700 (PDT) X-Received: by 10.182.40.233 with SMTP id a9mr12557obl.36.1404751080156; Mon, 07 Jul 2014 09:38:00 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!hn18no4598085igb.0!news-out.google.com!bp9ni2744igb.0!nntp.google.com!uq10no2403188igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 7 Jul 2014 09:37:59 -0700 (PDT) In-Reply-To: <35cd9c91-4b2c-4baa-9ef6-3c69fd7086ce@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=KSa2aQoAAACOxnC0usBJYX8NE3x3a1Xq NNTP-Posting-Host: 66.126.103.122 References: <35cd9c91-4b2c-4baa-9ef6-3c69fd7086ce@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Protected Type compiler complaint From: Adam Beneschan Injection-Date: Mon, 07 Jul 2014 16:38:00 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 3334 X-Received-Body-CRC: 1339263589 Xref: news.eternal-september.org comp.lang.ada:20777 Date: 2014-07-07T09:37:59-07:00 List-Id: On Monday, July 7, 2014 7:23:32 AM UTC-7, NiGHTS wrote: > On Monday, July 7, 2014 3:55:24 AM UTC-4, Simon Wright wrote: >=20 > A question about the variables in the Test.P type you introduced. I would= like to make available to other spawned tasks these protected variables, s= o essentially Test.P needs to be a global of some kind Test.P is a type, so it doesn't make sense to be global. I assume that you= want some global *object* whose type is Test.P. > with static data in the currently running process. I heard much about not= creating global variables for good Ada coding practice, so how is this pro= tected package variables expected to be usable by these spawned tasks?=20 Global variables are considered poor programming practice in any language--= it has nothing to do with Ada. Understanding the reasons involves getting = into software design principles. I did a quick search and found what seems= to be a pretty good discussion at http://programmers.stackexchange.com/que= stions/148108/why-is-global-state-so-evil. Anyway, I don't see that your protected object *needs* to be a global varia= ble. If you have some state that you want to share between tasks, you can = either declare an access to your protected type, or declare a record type t= hat contains other state information (including the protected object) and a= n access to that. Then there are ways to get an access-to-protected or acc= ess-to-record passed to each task (one is to use an accept statement to pas= s the access value to a task; another is to declare the task type with an a= ccess discriminant). =20 However, this can be a problem if the tasks are standalone top-level tasks = that are not explicitly created by the program. It's possible that this wo= uld be one case where a global variable is less bad than the alternatives, = but you should definitely try to understand *why* globals are considered po= or practice so that you understand what problems you might cause by using t= hem. -- Adam=20