comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adambeneschan@gmail.com>
Subject: Re: Protected Type compiler complaint
Date: Mon, 7 Jul 2014 09:37:59 -0700 (PDT)
Date: 2014-07-07T09:37:59-07:00	[thread overview]
Message-ID: <a60a386d-0481-49af-8579-a20dd32c0e25@googlegroups.com> (raw)
In-Reply-To: <35cd9c91-4b2c-4baa-9ef6-3c69fd7086ce@googlegroups.com>

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:
> 

> 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, so 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 protected package variables expected to be usable by these spawned tasks? 

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/questions/148108/why-is-global-state-so-evil.

Anyway, I don't see that your protected object *needs* to be a global variable.  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 that contains other state information (including the protected object) and an access to that.  Then there are ways to get an access-to-protected or access-to-record passed to each task (one is to use an accept statement to pass the access value to a task; another is to declare the task type with an access discriminant).  

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 would be one case where a global variable is less bad than the alternatives, but you should definitely try to understand *why* globals are considered poor practice so that you understand what problems you might cause by using them.

                           -- Adam 

  reply	other threads:[~2014-07-07 16:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-07  7:15 Protected Type compiler complaint NiGHTS
2014-07-07  7:55 ` Simon Wright
2014-07-07 14:23   ` NiGHTS
2014-07-07 16:37     ` Adam Beneschan [this message]
2014-07-07 17:21     ` Simon Wright
2014-07-08 17:03     ` Shark8
2014-07-08 17:50       ` Anh Vo
2014-07-07 19:06 ` framefritti
2014-07-08  7:11   ` Georg Bauhaus
2014-07-08  7:53   ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox