Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Question on Myers #30

Reply
Thread Tools

Question on Myers #30

 
 
Marcelo Pinto
Guest
Posts: n/a
 
      03-01-2005
"White Wolf" <(E-Mail Removed)> wrote in message news:<cvr5u8$iri$(E-Mail Removed)>...
> Master of C++ wrote:
> > Of course, I don't follow EC++ as if it were a rule-book. But a lot of
> > well-respected authors (Herb Sutter, Steve McConnell etc.,) cite Myers
> > heavily, and I have respect for what he says in his book. Thats what
> > makes this advice a little confusing.

>
> No, they don't.


I have a copy of C++ Coding Standards by Sutter and Alexandrescu and
Scott Meyers is cited in 50 of the 100 items. And I once read one of
the Exceptional books and it said something like "Effective CD is a
good source of information"

>
> > Its not a typo. I verified it before posting.

>
> It is a typo. The book is written by Scott Meyers.

 
Reply With Quote
 
 
 
 
Howard
Guest
Posts: n/a
 
      03-01-2005

"Jonathan Turkanis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Howard wrote:
>> "Jonathan Turkanis" <(E-Mail Removed)> wrote in message

>
>> But that's not his point!

>
> Were talking about "Avoid member functions that return pointers or
> references to
> members
> less accessible than themselves," right?


Not exactly. The reason I jumped in was that Mr. Meyers' whole point
revolved around the reference being non-const. He was just showing one way
that data that should be private can be exposed via a public interface, and
that such a thing be avoided by using a const reference instead.


> This is the same as my example, and I'm arguing that contrary to Meyers,
> sometimes it's okay. I've given the argument twice now.
>


I will certainly concede that sometimes it is appropriate, and maybe even
needed. Mr. Meyers' statement was to "avoid" such a thing, which in my
opinion leaves plenty of room for "sometimes". And I still feel he's
got a valid point, certainly not rubbish, even if it wouldn't make a good
"hard and fast rule". Something to at least consider when designing a class
with private data, certainly. But really, my whole point in being here was
to correct the OP's posting that left off the critical "non-const" part, not
to argue the validity or scope of Mr. Meyers' argument.

-Howard




 
Reply With Quote
 
 
 
 
Master of C++
Guest
Posts: n/a
 
      03-01-2005
Oops ! I just nocited that my library (still !) has the first edition
of Meyer's book. In the first edition, he did not have that "non-const"
modifier in his chapter, but he seems to have corrected it in the
second edition. Even then, I wish he mentioned somewhere that it is ok
to do it in certain situations (esp, containers).

-Vijay.

 
Reply With Quote
 
Jonathan Turkanis
Guest
Posts: n/a
 
      03-01-2005
Howard wrote:
> "Jonathan Turkanis" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Howard wrote:
>>> "Jonathan Turkanis" <(E-Mail Removed)> wrote in message

>>
>>> But that's not his point!

>>
>> Were talking about "Avoid member functions that return pointers or
>> references to
>> members
>> less accessible than themselves," right?

>
> Not exactly. The reason I jumped in was that Mr. Meyers' whole point
> revolved around the reference being non-const.


But I was talking about non-const references.

> He was just showing
> one way that data that should be private can be exposed via a public
> interface, and that such a thing be avoided by using a const
> reference instead.
>
>
>> This is the same as my example, and I'm arguing that contrary to
>> Meyers, sometimes it's okay. I've given the argument twice now.
>>

>
> I will certainly concede that sometimes it is appropriate, and maybe
> even needed. Mr. Meyers' statement was to "avoid" such a thing,
> which in my opinion leaves plenty of room for "sometimes".


True, except that in the desicussion following the heading he says that
violating the rule (or guidline, or rule of thumb, or whatever) doesn't make
sense.

He also says that returning a non-const reference to member data is equivalent
to making it public, which is another thing I was arguing against.

Jonathan


> -Howard



 
Reply With Quote
 
Jonathan Turkanis
Guest
Posts: n/a
 
      03-01-2005
Ioannis Vranos wrote:
> Jonathan Turkanis wrote:
>
>> I'm not arguing that all data should be public or virtually public!
>> Just that it *sometimes* makes sense to have a public accessor
>> function which returns a reference to a private member.
>>
>> There are two separate issues:
>>
>> 1. Does it sometimes make sense to have public data? The answer is
>> yes, with the emphasis on 'sometimes.' Think of std:air.

>
>
> std:air, for example the one returned from map, contains copies of
> the elements.


This relates to the design of std::map, not std:air. There's good reason not
to be able to freely modify key in map.

Jonathan



 
Reply With Quote
 
Ioannis Vranos
Guest
Posts: n/a
 
      03-01-2005
Jonathan Turkanis wrote:

> This relates to the design of std::map, not std:air. There's good reason not
> to be able to freely modify key in map.



Yes. Perhaps I did not understand your point.



--
Ioannis Vranos

http://www23.brinkster.com/noicys
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Kanye West show was Mike Myers SECOND awkward live tv moment heinzmenses@hotmail.com Digital Photography 31 09-12-2005 08:54 PM
Michael Myers A+ 5th edition question Fred Mathering A+ Certification 4 05-27-2004 04:46 AM
Mike Myers 70-293 Book Brian MCSA 2 08-04-2003 01:10 PM
Mike Myers Book? steven A+ Certification 2 08-04-2003 02:02 AM
Re: A+!! Thanks M. Myers techophile A+ Certification 1 06-24-2003 07:43 PM



Advertisments