[comp.lang.eiffel] Functions and Side-effects

chrisv@runx.oz.au (Chris Velevitch) (05/24/91)

In article <1166@tetrauk.UUCP> rick@tetrauk.UUCP (Rick Jones) writes:
>compiler.  The Eiffel "philosophy" is that routines should be either functions
>or procedures;  i.e. a routine which returns a value is a function, and should
>always be written without side effects.  It can therefore be called repeatedly
>without changing the state of the system.  A procedure which does change the
>state should not have a return value.
>
>The compiler can never totally enforce this, although it does produce warnings
>if you call a function and don't assign its return value.  (If it is a true
>function without side-effects the statement is pointless, if the statement is
>not pointless the routine must change the state so it should not have a return
>value.)  I must confess that I sometimes break this rule, but only to the
>extent of having a procedure return a boolean to indicate whether it succeeded
>or not - and such routines would have no value in as assertion statment.

You don't have to break the rule in this case either. You can have an
attribute which indicates the success or otherwise of the routine. The
value of the attribute indicates the state of the object.
-- 
Chris Velevitch, Sydney NSW, Australia.
Internet: chrisv@runxtsa.runx.oz.au, UUCP: uunet!runxtsa.runx.oz.au!chrisv