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
LVL 1
bearwareAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fridomCEO/ProgrammerCommented:
You probably want to learn doing programming the Eiffel way. The approach with once is not the worst one. But you have to be sure that ABC does not offer any methods for changing the state of the object.

I can't see what you mean with constend methods. But if you mean you want to have  method with not side-effects on the state of it's Object you have to ensure that yourself. It's as in nearly every  other language.

You might want to read about the comand/query separation and see that queries should not have side-effects.

Regards
Friedrich

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bearwareAuthor Commented:
I am told:
"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
bearwareAuthor Commented:
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.

Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

fridomCEO/ProgrammerCommented:
Check out the strip keyword. This may make it simpler to state that postcondition

Regards
Friedrich
bearwareAuthor Commented:
Thanks I have used strip when I Only change one thing. WOuld I use it with no args in stead od deep_clone?
fridomCEO/ProgrammerCommented:
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
bearwareAuthor Commented:
Hm now I am confused, can you tell me about strip
fridomCEO/ProgrammerCommented:
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


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.