POV-Ray : Newsgroups : povray.off-topic : The other OS : Re: The other OS Server Time
30 Jul 2024 10:19:50 EDT (-0400)
  Re: The other OS  
From: Darren New
Date: 7 Aug 2011 11:45:53
Message: <4e3eb331$1@news.povray.org>
On 8/7/2011 8:00, Warp wrote:
>    "In computer science, a predicate is called an invariant to a sequence
> of operations provided that: if the predicate is true before starting
> the sequence, then it is true at the end of the sequence."


Well, here's the thing.

assert(a < b) is testing a precondition if you stick it in a function before 
any code that changes values of variables.

assert(a < b) is testing a postcondition if you stick it in a function after 
all code that changes values of variables.

assert(a < b) is testing an invariant if you have it as a precondition and a 
postcondition for every function that reads or writes a or b.

assert(a < b) might even be part of a loop variant rather than any invariant.

In your example, "a < b" might be an invariant. "assert(a < b)" isn't 
enforcing an invariant unless you write it at the start and end of every 
function.

But sure, assert() is about as close as you can get in C to providing a way 
to implement the design pattern of DbC. It is, as you said, "the closest 
thing". But that's like saying "function pointers is the closest thing you 
have to closures in C." I.e., not very close. :-)

-- 
Darren New, San Diego CA, USA (PST)
   How come I never get only one kudo?


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.