Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > Re: Total Newbi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 17 of 53 Topic 4060 of 4302
Post > Topic >>

Re: Total Newbie Backward Compat Question

by Richard Heathfield <rjh@[EMAIL PROTECTED] > Mar 11, 2008 at 02:56 PM

Chris ( Val ) said:

> On Mar 11, 9:29 pm, Richard Heathfield <r...@[EMAIL PROTECTED]
> wrote:
>> Chris ( Val ) said:
>> <snip>
>>
>> > I think I can understand your reasons for [writing setters that
>> > return values], but that is a hack in C++,
>>
>> <shrug> :-)
> 
> And, and such an "unjustifiable" shrug it is :-)

Oh, I think I can justify it (to *my* satisfaction anyway!).

>> > and goes against everything we learn about OOP and writing good,
>> > maintainable and safe code.
>>
>> Um, *what*? What's unsafe about yielding the old value of a value
you're
>> about to change? At least that way you are providing the *possibility*
>> of restoring it.
> 
> Well, according to your philosophy, why have a class at all?
> Lets keep everything public and use a C structs only, because
> "is quite a useful thing to be able to do" :-)

Yes, there's a lot to be said for that. Nevertheless, I wasn't suggesting 
it. If you've got a way to set a value, and you've got a way to get a 
value, I see no harm in providing a way to do both at once. It's not as if

you're opening up extra access to the class - the access is *already* 
there, so all you're doing is making it convenient to kill two birds with 
one stone.

<snip>

>> I think throwing an exception is just plain irresponsible.
> 
> Sorry, but I think that comment didn't have much thought behind it :-)

I'm sorry you think so. :-|

>> (Yes, we could have a flame war about this, but I hope we're not
>> going to. I don't insist that anyone changes their mind on my account.)
> 
> People will not follow me nor you. Rather, they will adopt the
> generally accepted principles in best practice.

That is, alas, all too often /not/ true. But wise people will follow that 
strategy for as long as it makes sense. Rules are there to make you 
*think* before you break them.

>> > It's just too easy to forget how many times it was set, and if it was
>> > a newx or oldx value, and where in the code a mistake was made.
>>
>> All mistakes are too easy to make. That doesn't mean we *have* to make
>> them. For example, it's pretty darn easy to put v = i++ instead of v =
>> ++i (or vice versa), but that doesn't mean we should avoid using ++.
> 
> Yes, mistakes are easy to make, but why make then easier?

If the payoff is sufficient, why not? As Doug Gwyn once said (and I'm 
paraphrasing here because I'm too lazy to look it up): "by making it 
impossible for people to do stupid things, you also make it impossible for

them to do clever things". Added flexibility gives added op****tunity to 
get it wrong, yes, but it also gives added op****tunity to do something 
special. (This is a general observation - I'm not claiming that adding a 
return value to a setter gives one the ability to discover a practical 
cold fusion technique.)

> 
>> >> int oldx = p.getx();
>> >> p.setx(newx);
>> >> dosomethingwith(p);
>> >> p.setx(oldx);
>>
>> > This is *much* better, as the 'getter' will always return the current
>> > value, without chance of returning anything other than that.
>>
>> No, it's not much better at all. In my view, it's a little bit worse.
>> It's more code, and it's less elegant.
> 
> Oh, come on, Richard!!!

Hmm? We've crossed swords before, Chris, albeit very amicably, and I seem 
to recall that you eventually changed your mind on that occasion. I'm not 
saying you're necessarily going to do that this time, but please at least 
give me the credit for having thought about this a bit, even if you think 
I'm wrong.

> I can only state that in my experience of using C++, I have become
> very comfortable with OOP, and would avoid procedural programming
> at all costs, albeit for small toy programs.

Well, I'm very happy for you. :-)  But not everybody thinks like that. 
There's more to C++ than OOP.

<snip>

-- 
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www.
+rjh@[EMAIL PROTECTED]
 users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 




 53 Posts in Topic:
Total Newbie Backward Compat Question
Hal Vaughan <hal@[EMAI  2008-03-10 05:38:03 
Re: Total Newbie Backward Compat Question
Richard Heathfield <rj  2008-03-10 05:48:22 
Re: Total Newbie Backward Compat Question
Hal Vaughan <hal@[EMAI  2008-03-10 05:49:42 
Re: Total Newbie Backward Compat Question
Richard Heathfield <rj  2008-03-10 06:24:13 
Re: Total Newbie Backward Compat Question
Hal Vaughan <hal@[EMAI  2008-03-11 14:35:17 
Re: Total Newbie Backward Compat Question
Crazy c <chrisNchrist@  2008-03-10 04:12:17 
Re: Total Newbie Backward Compat Question
Richard Heathfield <rj  2008-03-10 12:05:13 
Re: Total Newbie Backward Compat Question
"Daniel T." <  2008-03-11 06:37:11 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-10 06:15:26 
Re: Total Newbie Backward Compat Question
Richard Heathfield <rj  2008-03-10 14:21:14 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-11 02:15:39 
Re: Total Newbie Backward Compat Question
Richard Heathfield <rj  2008-03-11 10:29:42 
Re: Total Newbie Backward Compat Question
Bart van Ingen Schenau &l  2008-03-11 18:58:25 
Re: Total Newbie Backward Compat Question
"Daniel T." <  2008-03-12 06:26:50 
Re: Total Newbie Backward Compat Question
Bart van Ingen Schenau &l  2008-03-12 17:43:08 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-11 04:21:32 
Re: Total Newbie Backward Compat Question
Richard Heathfield <rj  2008-03-11 14:56:52 
Re: Total Newbie Backward Compat Question
Anand Hariharan <mailt  2008-03-11 19:31:54 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-12 06:15:16 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-12 06:19:55 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-12 06:27:42 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-12 06:54:16 
Re: Total Newbie Backward Compat Question
Bart van Ingen Schenau &l  2008-03-12 18:40:28 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-12 07:10:18 
Re: Total Newbie Backward Compat Question
Richard Heathfield <rj  2008-03-12 14:28:48 
Re: Total Newbie Backward Compat Question
Hal Vaughan <hal@[EMAI  2008-03-13 05:43:14 
Re: Total Newbie Backward Compat Question
Richard Heathfield <rj  2008-03-13 07:11:42 
Re: Total Newbie Backward Compat Question
Jerry Coffin <jcoffin@  2008-03-14 00:25:02 
Re: Total Newbie Backward Compat Question
Hal Vaughan <hal@[EMAI  2008-03-13 03:23:30 
Re: Total Newbie Backward Compat Question
Philip Potter <pgp@[EM  2008-03-13 15:57:05 
Re: Total Newbie Backward Compat Question
"Daniel T." <  2008-03-12 11:46:58 
Re: Total Newbie Backward Compat Question
Bart van Ingen Schenau &l  2008-03-14 21:34:35 
Re: Total Newbie Backward Compat Question
"Daniel T." <  2008-03-14 22:01:32 
Re: Total Newbie Backward Compat Question
Francis Glassborow <fr  2008-03-15 10:02:29 
Re: Total Newbie Backward Compat Question
Anand Hariharan <mailt  2008-03-12 18:36:13 
Re: Total Newbie Backward Compat Question
"Daniel T." <  2008-03-13 06:52:53 
Re: Total Newbie Backward Compat Question
Anand Hariharan <mailt  2008-03-12 23:36:10 
Re: Total Newbie Backward Compat Question
Micah Cowan <micah@[EM  2008-03-14 09:40:31 
Re: Total Newbie Backward Compat Question
"Daniel T." <  2008-03-13 10:23:19 
Re: Total Newbie Backward Compat Question
Bart van Ingen Schenau &l  2008-03-14 21:45:47 
Re: Total Newbie Backward Compat Question
"Daniel T." <  2008-03-15 07:14:33 
Re: Total Newbie Backward Compat Question
Francis Glassborow <fr  2008-03-15 16:14:23 
Re: Total Newbie Backward Compat Question
"Daniel T." <  2008-03-16 09:37:37 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-18 05:04:15 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-18 05:40:29 
Re: Total Newbie Backward Compat Question
Richard Heathfield <rj  2008-03-18 22:54:23 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-18 07:12:06 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-21 05:44:42 
Re: Total Newbie Backward Compat Question
Richard Heathfield <rj  2008-03-21 13:34:56 
Re: Total Newbie Backward Compat Question
Ben Bacarisse <ben.use  2008-03-12 18:05:26 
Re: Total Newbie Backward Compat Question
"Daniel T." <  2008-03-12 20:46:50 
Re: Total Newbie Backward Compat Question
Ben Bacarisse <ben.use  2008-03-13 01:57:08 
Re: Total Newbie Backward Compat Question
Ben Bacarisse <ben.use  2008-03-13 18:54:38 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 13 20:12:53 CDT 2008.