bearware
asked on
constents in eifel
I am looking at different types of constness in eifel:
1) Feature that returns a constent
I tryed
feature
my_const : ABC is
once
Result := abc.make(xyz)
end
This is very bad, I changes the once to a do, this is better. But I cant make it truly const.
2) Constend methods.
I can do this this with:
ensure
const_method: is_equal(old)
Is there a way to put this ensure into an operation/macro so I dont have to retype it all the time.
E.G.
in ANY
feature
const_method is
do
check const_method: is_equal(callers old) end
end
1) Feature that returns a constent
I tryed
feature
my_const : ABC is
once
Result := abc.make(xyz)
end
This is very bad, I changes the once to a do, this is better. But I cant make it truly const.
2) Constend methods.
I can do this this with:
ensure
const_method: is_equal(old)
Is there a way to put this ensure into an operation/macro so I dont have to retype it all the time.
E.G.
in ANY
feature
const_method is
do
check const_method: is_equal(callers old) end
end
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
In my question I have:
ensure
const_method: is_equal(old)
This is useless, it always passes.
But I think this will work:
ensure
const_method: is_deep_equal(old deep_clone(Current))
Unfortuanatly there is no typing shortcut: as far as I know.
ensure
const_method: is_equal(old)
This is useless, it always passes.
But I think this will work:
ensure
const_method: is_deep_equal(old deep_clone(Current))
Unfortuanatly there is no typing shortcut: as far as I know.
Check out the strip keyword. This may make it simpler to state that postcondition
Regards
Friedrich
Regards
Friedrich
ASKER
Thanks I have used strip when I Only change one thing. WOuld I use it with no args in stead od deep_clone?
I am not fully sure about that and in fact I'm not even sure if the deep_equal and deep_copy stuff will work. Just think about threads. Some other thread my change the objects state. I know that deep_clone is probably the most expensive operation one can do in Eiffel, so it will surely use a lot of time while running with deep nested structures. Base line is, that I avoid deep_clone as much as I can. I just remember one time when I was not able to get away without it. Under other circumstances, it was no problem to avoid it.
So IMHO relying on the postcondition might work usually but I'm sure not always.
Regards
Friedrich
So IMHO relying on the postcondition might work usually but I'm sure not always.
Regards
Friedrich
ASKER
Hm now I am confused, can you tell me about strip
strips does what it names suggest it strips of elements from an object
let's say you have
class FOO
feature
a : INTEGER
b: INTEGER
then strip (a) yields an ARRAY of objects without the a feature. so you could say, nothing is changed but ... or the like.
if you say
equal (strip (a), old strip(a)) then this means. All elements but "a" stay unchanged. I could assume this might be handy.
Regards
Friedrich
let's say you have
class FOO
feature
a : INTEGER
b: INTEGER
then strip (a) yields an ARRAY of objects without the a feature. so you could say, nothing is changed but ... or the like.
if you say
equal (strip (a), old strip(a)) then this means. All elements but "a" stay unchanged. I could assume this might be handy.
Regards
Friedrich
ASKER
"You may not accept this answer"
When I try to except the only answer.
P.S. I think this does it:
method is
....
ensure
const_method: is_deep_equal(old deep_clone(Current))
end