|
Thanks led mike,
Then, how do you understand the statement "cannot in general roll back the change already made to t1_", why can not?
regards,
George
|
|
|
|
|
led mike wrote: is rolling back an inherent feature of an assignment operator
Who said that?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
You did. "is not the whole scenario: it maybe also impossible to roll back"
CPallini wrote: You're interpretation is correct, but is not the whole scenario: it maybe also impossible to roll back becauseT1 class public interface simply doesn't allow it.
led mike
|
|
|
|
|
OK, if you throw, then you're going to leave Widget object in inconsistent state?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Ok and rolling back would be equal to inconsistent, not a solution to it.
led mike
|
|
|
|
|
led mike wrote: Ok and rolling back would be equal to inconsistent, not a solution to it.
Why?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
a = 5;
a = 12;
Now you expect the value of a to be 12, period. If it were 5 it's inconsistent since you don't expect it to be 5 any more than you expect it to be some random value due to an exception being thrown.
However I strongly suggest you buy and read Meyers[^] on Effective C++ and More Effective C++, I am a consumer not an author.
led mike
|
|
|
|
|
Off course you made an example using built in types, not complex objects.
Anyway I'll probably follow your suggestions, the books look interesting.
BTW a random value is not an inconsistent state for int .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Whatever. You just keep thinking whatever you want, I no longer care.
led mike
|
|
|
|
|
led mike wrote: Whatever. You just keep thinking whatever you want, I no longer care.
Of course.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Does led mike mean rollback is not needed in assignment operator if exception is thrown?
regards,
George
|
|
|
|
|
Yes. Though I don't know if is he or Scott Meyers
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Hi CPallini,
If no rollback when exception thrown in assignment operator, how could we make sure strong exception safe.
regards,
George
|
|
|
|
|
Well, I'm not an expert, however the article of your OP explain very well how to do that by expoiting the Pimpl Idiom , but shhhhhhhhhh, don't tell led mike.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Agree, CPallini! Let us wait for led mike to see how could he give us a strong exception safe assignment operator without change the class structure to Pimlp Idiom.
regards,
George
|
|
|
|
|
CPallini wrote: Yes.
No. See my reply to George. And yes it is from Meyers. Wink while you can monkey boy.
led mike
|
|
|
|
|
Post conditions are required by design by contract approach, or am I wrong?
led mike wrote: Wink while you can monkey boy.
Please elaborate (my poor English).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
CPallini wrote: Post conditions are required by design by contract approach, or am I wrong?
Yes, no, both. assignment operator, and other other operators, have implicit contracts. Read Meyers. ( I am getting a little tired of saying the "read Meyers" part you know )
CPallini wrote: Please elaborate (my poor English).
It's a twist on a quote from a movie Adventures of Buckaroo Banzai Across the 8th Dimension[^] where a character said "Laugh while you can monkey boy".
led mike
|
|
|
|
|
led mike wrote: Yes, no, both. assignment operator, and other other operators, have implicit contracts. Read Meyers. ( I am getting a little tired of saying the "read Meyers" part you know )
OK, I will do. However,you know, design by contract is only one of the possible approaches.
led mike wrote: It's a twist on a quote from a movie Adventures of Buckaroo Banzai Across the 8th Dimension[^] where a character said "Laugh while you can monkey boy".
I really appreciate you elaborated, thank you.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
CPallini wrote: design by contract is only one of the possible approaches.
Yes I know, and not the most popular approach. The most popular approach is probably the Disastrous Bowl of Worms approach. That's the one where you ignore all the advice from people like Kent Beck, Martin Fowler, Scott Meyers and others.
led mike
|
|
|
|
|
That's fanaticism.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
George_George wrote: Does led mike mean rollback is not needed in assignment operator if exception is thrown?
No. It means that rollback is an inappropriate post condition for an assignment operator since it is not part of the implied contract of the assignment operator.
led mike
|
|
|
|
|
Hi led mike,
What is your contract? My contract is, exception could be thrown, but all status of object should be consistent. Your contract is, if exception is thrown, status of object is unknown?
led mike wrote: contract of the assignment operator
regards,
George
|
|
|
|
|
George_George wrote: What is your contract?
My contract is: READ MEYERS!
Don't make me say that again, period.
led mike
|
|
|
|
|
Hi led mike,
What is MEYERS?
regards,
George
|
|
|
|