"Destructors" and dynamic pre/post-conditions 
Author Message
 "Destructors" and dynamic pre/post-conditions

Is there a quick and/or clean way to provide 'destructor' capabilities in Eiffel? I find this to be a useful aspect of C++ and would like to have the same capabilities in Eiffel.

Also, in providing Eiffel-like pre/post-conditions for a C++ package I implemented them in such a way that additional conditions could be added as the state of the classes/objects evolved. Given the effort to provide basic pre/post-conditions to C++ the last step of dynamicizing(?) them started out more 'proof of concept' then anything else, but I found them useful in some situations. Has anyone in the Eiffel community run into situations where a similar capability would be helpful?



Tue, 01 Jul 1997 01:49:13 GMT  
 "Destructors" and dynamic pre/post-conditions

Quote:

>Is there a quick and/or clean way to provide 'destructor' capabilities in Eiffel? I find this to be a useful aspect of C++ and would like to have the same capabilities in Eiffel.

Eiffel is a garbage collected language, so there is no need for desctructors.
However, you can specify that a specific routine should be executed just before
the object is garbage collected.

Quote:
>Also, in providing Eiffel-like pre/post-conditions for a C++ package I implemented them in such a way that additional conditions could be added as the state of the classes/objects evolved. Given the effort to provide basic pre/post-conditions to C++ the last step of dynamicizing(?) them started out more 'proof of concept' then anything else, but I found them useful in some situations. Has anyone in the Eiffel community run into situations where a similar capability would be helpful?

Hmm. This sounds interesting, but 'm not sure I understand what you mean by
"additional conditions could be added as the state of the classe/objects
involved".

Please explain.

...richie

--


*                                                                  *
* "In anything at all, perfection is finally attained not when     *



Tue, 01 Jul 1997 12:04:04 GMT  
 "Destructors" and dynamic pre/post-conditions

Quote:

> Eiffel is a garbage collected language, so there is no need for desctructors.

That's not completely true; there's a thread going on right now in
comp.lang.c++ discussing this point.

In general, a "destructor" in C++ is a routine that releases an
object's resources.  Memory is the most common resource that you have
to release, and, of course, it's unnecessary to worry about that in a
language like Eiffel.  Memory isn't the only sort of resource, though:
there are also file handles, windows, graphical resources, semaphores,
and so on.

Now it probably doesn't make sense in Eiffel to try to use destructors
for that purpose: I doubt that the concept can ever be all that useful
in a garbage-collected language.  Still, the general question remains:
you have to have some mechanism of handling the acquisition and
release of resources in a controlled manner, and your mechanism has
to work even in the presence of abnormal exits from routines.

In C++, the mechanism you typically use is the constructor and
destructor, and in most versions you typically use unwind-protect.
I'm quite new to Eiffel, though.  How do most Eiffel programmers deal
with this problem?
--

                               --matt



Wed, 02 Jul 1997 03:30:43 GMT  
 "Destructors" and dynamic pre/post-conditions
Matt Austern writes

Quote:

Bielak) writes:

> > Eiffel is a garbage collected language, so there is no need for  
desctructors.

> That's not completely true; there's a thread going on right now in
> comp.lang.c++ discussing this point.

> In general, a "destructor" in C++ is a routine that releases an
> object's resources.  Memory is the most common resource that you have
> to release, and, of course, it's unnecessary to worry about that in a
> language like Eiffel.  Memory isn't the only sort of resource, though:
> there are also file handles, windows, graphical resources, semaphores,
> and so on.

> Now it probably doesn't make sense in Eiffel to try to use destructors
> for that purpose: I doubt that the concept can ever be all that useful
> in a garbage-collected language.  Still, the general question remains:
> you have to have some mechanism of handling the acquisition and
> release of resources in a controlled manner, and your mechanism has
> to work even in the presence of abnormal exits from routines.

> In C++, the mechanism you typically use is the constructor and
> destructor, and in most versions you typically use unwind-protect.
> I'm quite new to Eiffel, though.  How do most Eiffel programmers deal
> with this problem?

This is an issue of finalization.  Before the Eiffel GC reclaims an object it  
calls that object's finalization routine.  In this routine, files can be  
closed, etc.

Regards,
Wolfgang Ziller



Wed, 02 Jul 1997 06:09:11 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. "BIG E vs little e", was pre-condition vs post-condition

2. Pre-condition vs. Post-condition

3. Pre-condition vs. Post-condition

4. Pre-condition vs Post-condition

5. pre-condition vs post-condition

6. Post-constructors and pre-destructors

7. Using MEMORY to make a "Destructor"

8. Where to implement Pre and Post Conditions?

9. Pre- and post-conditions (was Commenting code)

10. Pre/Post Conditions

11. question about pre- & post-conditions

12. percursor and pre- and post-condition inheritance

 

 
Powered by phpBB® Forum Software