Solved

constents in eifel

Posted on 2003-11-27
9
1,683 Views
Last Modified: 2013-12-03
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
0
Comment
Question by:bearware
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 24

Accepted Solution

by:
fridom earned 125 total points
ID: 9872581
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
0
 
LVL 1

Author Comment

by:bearware
ID: 10128106
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
0
 
LVL 1

Author Comment

by:bearware
ID: 10128133
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.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 24

Expert Comment

by:fridom
ID: 10144410
Check out the strip keyword. This may make it simpler to state that postcondition

Regards
Friedrich
0
 
LVL 1

Author Comment

by:bearware
ID: 10145143
Thanks I have used strip when I Only change one thing. WOuld I use it with no args in stead od deep_clone?
0
 
LVL 24

Expert Comment

by:fridom
ID: 10146690
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
0
 
LVL 1

Author Comment

by:bearware
ID: 10146755
Hm now I am confused, can you tell me about strip
0
 
LVL 24

Expert Comment

by:fridom
ID: 10241361
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


0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question