Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 63277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:36:27+00:00 2026-05-10T18:36:27+00:00

In the (otherwise) excellent book C++ Coding Standards , Item 44, titled Prefer writing

  • 0

In the (otherwise) excellent book C++ Coding Standards, Item 44, titled ‘Prefer writing nonmember nonfriend functions’, Sutter and Alexandrescu recommend that only functions that really need access to the members of a class be themselves members of that class. All other operations which can be written by using only member functions should not be part of the class. They should be nonmembers and nonfriends. The arguments are that:

  • It promotes encapsulation, because there is less code that needs access to the internals of a class.
  • It makes writing function templates easier, because you don’t have to guess each time whether some function is a member or not.
  • It keeps the class small, which in turn makes it easier to test and maintain.

Although I see the value in these argument, I see a huge drawback: my IDE can’t help me find these functions! Whenever I have an object of some kind, and I want to see what operations are available on it, I can’t just type ‘pMysteriousObject->‘ and get a list of member functions anymore.

Keeping a clean design is in the end about making your programming life easier. But this would actually make mine much harder.

So I’m wondering if it’s really worth the trouble. How do you deal with that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:36:27+00:00Added an answer on May 10, 2026 at 6:36 pm

    I’m going to have to disagree with Sutter and Alexandrescu on this one. I think if the behavior of function foo() falls within the realm of class Bar‘s responsibilities, then foo() should be part of bar().

    The fact that foo() doesn’t need direct access to Bar‘s member data doesn’t mean it isn’t conceptually part of Bar. It can also mean that the code is well factored. It’s not uncommon to have member functions which perform all their behavior via other member functions, and I don’t see why it should be.

    I fully agree that peripherally-related functions should not be part of the class, but if something is core to the class responsibilities, there’s no reason it shouldn’t be a member, regardless of whether it is directly mucking around with the member data.

    As for these specific points:

    It promotes encapsulation, because there is less code that needs access to the internals of a class.

    Indeed, the fewer functions that directly access the internals, the better. That means that having member functions do as much as possible via other member functions is a good thing. Splitting well-factored functions out of the class just leaves you with a half-class, that requires a bunch of external functions to be useful. Pulling well-factored functions away from their classes also seems to discourage the writing of well-factored functions.

    It makes writing function templates easier, because you don’t have to guess each time whether some function is a member or not.

    I don’t understand this at all. If you pull a bunch of functions out of classes, you’ve thrust more responsibility onto function templates. They are forced to assume that even less functionality is provided by their class template arguments, unless we are going to assume that most functions pulled from their classes is going to be converted into a template (ugh).

    It keeps the class small, which in turn makes it easier to test and maintain.

    Um, sure. It also creates a lot of additional, external functions to test and maintain. I fail to see the value in this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found the book Java Concurrency in Practice to be an excellent guide to
In the opengl section of Hillegass' otherwise fine book, we're given sample code for
I've followed this otherwise excellent tutorial on getting Xen working with Ubuntu but am
I am using this - otherwise excellent - vb tab control in one of
I'm having a lot of trouble compiling the otherwise excellent Contiki OS on my
Is there anything more compact (or otherwise better) than this? <x:Array x:Key=titles Type=System:String> <System:String>Mr.</System:String>
Is there any difference in performance - or otherwise - between: ptr->a(); and (*ptr).a();
Which useful (for performance or otherwise) constructions are valid bytecode, but not expressable in
I want to introduce some random* behavior into an otherwise static html file. I
The tail-end of an OpenVPN connection (that otherwise appears successful) says (with leading timestamps

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.