Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

constents in eifel

Posted on 2003-11-27
9
Medium Priority
?
1,699 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
  • 4
  • 4
8 Comments
 
LVL 24

Accepted Solution

by:
fridom earned 375 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

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…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

877 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