comp.lang.ada
 help / color / mirror / Atom feed
From: Colin Paul Gloster <Colin_Paul_Gloster@ACM.org>
Subject: Re: [SPARK] Code safety and information hiding
Date: Mon, 21 Aug 2006 13:30:23 +0200
Date: 2006-08-21T11:30:26+00:00	[thread overview]
Message-ID: <20060821131232.Q662@docenti.ing.unipi.it> (raw)
In-Reply-To: <uu047jkgz.fsf@stephe-leake.org>

Stephen A. Leake had written:

"[..]
type Distribute_Mode_Type is (Master_Mode, Remote_Mode, Single_Mode);
Distribute_Mode : Distribute_Mode_Type := Single_Mode;
[..]"

Jeffrey R. Carter responded:

"[..]
Again, it must be reasonable and meaningful for me to change the SW to
write this variable whenever it suits me.

If that's not the case, then I claim this should not be a variable.
Instead of being able to write

X.Distribute_Mode := X.Master_Mode;

I should have to call something like

function Request_Distribute_Mode_Change
    (New_Mode : Distribute_Mode_Type)
return Boolean;
-- Request mode change to New_Mode.
-- Returns True if the mode change is legal; False otherwise.

All the details of when a mode change may occur should be encapsulated
with the current mode value.
[..]"



During the next clock cycle it might no longer be legal to change mode.



On Sun, 20 Aug 2006, Stephen Leake wrote:

"[..]

Ah. You want the code to enforce the design rules. That's not possible
in general. Ada allows enforcing some design rules, but not ones at
this level.

In fact, for this particular variable, the rule is "only the
environment task may write to this variable, and only before any other
tasks are started".

People modifying the code must understand the design."


Obviously, if only one task exists which is permitted to write to the 
variable, then a getter and a setter are sufficient, unless someone 
modifies the code so that another task can also write. I accept that you 
have been posting about trying to make it impossible for people to make 
such a modification, and that this is not strictly achievable, but the 
getter and setter methods paradigm is well understood widely when only one 
owner is allowed to call the setter method, so why would you be especially 
worried that someone would not realize this for this simpler example you 
presented?


Stephen Leake has written:

"[..]

Hmm. Now that I think about it, it would be easy to implement a
run-time check for that rule. But it would be a waste of time in the
production system. Might still be worth it; I have other run-time
checks for similar rules (in particular, "symbols must be written
before being read") that are hard to check otherwise.

[..]"

Was simply Ada code run in the application to check the rule meant by 
that, or do you have customized run-time checks in your GNAT run-time 
kernel?

Regards,
Colin Paul Gloster



  parent reply	other threads:[~2006-08-21 11:30 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-16  7:56 [SPARK] Code safety and information hiding Maciej Sobczak
2006-08-16  8:53 ` roderick.chapman
2006-08-16 11:18   ` Stuart
2006-08-16 13:23     ` Maciej Sobczak
2006-08-16 19:49 ` [SPARK] " Jeffrey R. Carter
2006-08-17  7:01   ` Maciej Sobczak
2006-08-17 18:08     ` Jeffrey R. Carter
2006-08-17 20:00       ` Björn Persson
2006-08-18  1:22         ` Jeffrey R. Carter
2006-08-18 19:39           ` Björn Persson
2006-08-19  5:35             ` Jeffrey R. Carter
2006-08-19 12:47               ` Björn Persson
2006-08-20  3:58                 ` Jeffrey R. Carter
2006-08-20 11:35                   ` Björn Persson
2006-08-18 23:02   ` Robert A Duff
2006-08-19  5:40     ` Jeffrey R. Carter
2006-08-19  9:49       ` Stephen Leake
2006-08-20  3:52         ` Jeffrey R. Carter
2006-08-20 19:06           ` Stephen Leake
2006-08-21  1:07             ` Jeffrey R. Carter
2006-08-21  7:25               ` Maciej Sobczak
2006-08-21 19:31                 ` Jeffrey R. Carter
2006-08-21 19:58                   ` Dmitry A. Kazakov
2006-08-21 21:06                     ` Björn Persson
2006-08-22  7:16                       ` Maciej Sobczak
2006-08-22  9:45                         ` Björn Persson
2006-08-22 12:42                           ` Maciej Sobczak
2006-08-22  7:27                       ` Dmitry A. Kazakov
2006-08-21 11:30             ` Colin Paul Gloster [this message]
2006-08-22 10:51               ` Stephen Leake
2006-08-23  9:44     ` Peter Amey
2006-08-23 22:37       ` Jeffrey R. Carter
2006-08-24 10:55         ` Peter Amey
2006-08-24 23:33           ` Jeffrey R. Carter
replies disabled

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