Solved

constents in eifel

Posted on 2003-11-27
9
1,665 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
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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now