comp.lang.ada
 help / color / mirror / Atom feed
* Proposal: pragma Assumption
@ 2008-05-25 18:59 Santiago Urueña
  2008-05-25 22:34 ` Georg Bauhaus
                   ` (3 more replies)
  0 siblings, 4 replies; 29+ messages in thread
From: Santiago Urueña @ 2008-05-25 18:59 UTC (permalink / raw)


Hi everybody,

I'm thinking in sending the following proposal to the ARG, but I'd
like to present it here first to have more opinions about it
usefulness, and probably to refine it a bit with your comments...

It is based on a 2004 paper of Tony Hoare (from the book 'From Object-
orientation To Formal Methods') where he describes different types of
assertions used by (C/C++) developers in production code, including
this one:

  SYMPLIFYING_ASSUMPTION (strlen(input) > MAX_PATH, "not yet checking
for overflow");

'SYMPLIFYING_ASSUMPTION' is a macro very similar to the C 'assert',
also checking at run-time a boolean condition and aborting the program
if it evaluates to false. But if an 'assert' is valid during the whole
life of the application, the 'SYMPLIFYING_ASSUMPTION' is used by the
programmer just *during the coding phase* to document those cases that
aren't coded yet (probably edge cases). The difference is when
compiling the program _not_ in debug mode (NDEBUG defined): the
'assert' macros are eliminated by the preprocessor whereas it is a
compilation error if any 'SYMPLIFYING_ASSUMPTION' remains in the
sources.

That is, a SYMPLIFYING_ASSUMPTION is like those 'TODO:' or 'FIXME:'
annotations used to remind the programmer what should be modified in
the code, but it is recognized by the compiler instead of being just a
comment, and therefore cannot be ignored by accident.


So the proposal whould be adding to the next Ada revision two new
pragmas:

  pragma Assumption ([Check =>] boolean_expression[, [Message =>]
string_expression]);
  pragma Assumption_Policy (policy_identifier);   -- Error, Check

Which behave exactly like Assert and Assertion_Policy (also raising
Assertion_Error, but with a different message), except that by default
it is a compilation error to find any pragma Assumption in the sources
unless when explicitly allowed using a compilation flag or the 'Check'
policy.

Probably better names can be chosen for those pragmas, so feel free to
propose more adequate identifiers. Also, maybe in this case the
Message string should be required, anyway it is a documentation pragma
(in pragma Assert the second parameter is optional).

IMHO this pragma is not a complete replacement for the TODO or FIXME
comments, and in many cases it is better to code the whole
functionality at once than just the more common cases. However,
sometimes it will be a good approach to code just some cases
documenting the assumptions, run the testsuite (raising an exception
if any of those missing cases are triggered), and to code the rest in
the future. But now, even if you forget to add that code, the compiler
will remind you about those missing cases when trying to compile the
final executable (following the "programmers make faults" Ada
philosophy).

Do you think it is an useful addition to Ada 2015? Would you use this
feature? Do you know of any means to achieve the same effect in Ada
2005? Thanks

Cheers,

--
Santiago Urueña-Pascual
Technical University of Madrid (UPM)



^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2008-06-02 19:35 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-25 18:59 Proposal: pragma Assumption Santiago Urueña
2008-05-25 22:34 ` Georg Bauhaus
2008-05-26 17:10   ` Santiago Urueña
2008-05-26 10:01 ` Simon Wright
2008-05-26 17:21   ` Santiago Urueña
2008-05-26 18:21     ` Simon Wright
2008-05-27  8:11       ` Santiago Urueña
2008-05-27 19:08         ` Simon Wright
2008-05-27  3:28 ` anon
2008-05-27  7:51   ` Santiago Urueña
2008-05-27  9:39     ` anon
2008-05-27 10:39       ` Georg Bauhaus
2008-05-27 11:27       ` Santiago Urueña
2008-05-28  1:12         ` anon
2008-05-28  7:54           ` Santiago Urueña
2008-05-30  0:27             ` Randy Brukardt
2008-05-30  7:50               ` Georg Bauhaus
2008-05-30 11:03                 ` Santiago Urueña
2008-05-31  5:56                 ` Stephen Leake
2008-05-31  9:04                   ` Georg Bauhaus
2008-06-02  8:24                   ` Santiago Urueña
2008-06-02 19:35                     ` anon
2008-05-30 11:02               ` Santiago Urueña
2008-05-28  7:58 ` Santiago Urueña
2008-05-28  8:24   ` Jean-Pierre Rosen
2008-05-28 13:11     ` Santiago Urueña
2008-05-28  9:14   ` Georg Bauhaus
2008-05-28 13:14     ` Santiago Urueña
2008-05-28 11:01   ` anon

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