Return unto others what you wish them to pass to you.
Or, in code, for every object $foo and every valid pair of get_bar() and set_bar(), this must work:
$foo->set_bar($foo->get_bar());
Violate this, particularly in an update to an existing system, and you will truely have hell to pay. This happened in a system I'm working on and by my count I'm fixing the fifth bug associated with it over a span of two months!
-sam
Ooops. (Score:2)
Assuming you're talking about code I wrote (and a bug I just fixed in Bricolage), I think I would design it differently today than I did a couple years ago when I wrote it, though I'm not sure how. I'll have to think about it...
--David
Re:Ooops. (Score:2)
-sam
Re:Ooops. (Score:2)
I didn't think you were tweaking my nose, and I agree that what you're "onto" is indeed an excellent guiding principal. Here's another that I'll follow in other future projects: Never, ever use 0 (that's a zero) as an object identifier.
--David
My golden rule of simple mutators: (Score:1)
set_fooshall return the object mutated, they shall not return the new value, you already knew that. They shall not return the old value, if you wanted to know that you should have asked. If a simple mutator fails, it shall throw an exception.Actually, in general, and unless there's a bloody good reason for returning something else, methods should always return
$selfor throw an exception.Why?
Re:My golden rule of simple mutators: (Score:2)
pdcawley wrote (emphasis mine):
Did you mean mutators should always return $self? Having an accessor return $self would be disappointing.
Re:My golden rule of simple mutators: (Score:1)