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

Ask A Question

Stats

  • Questions 68k
  • Answers 68k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You will need to iterate on the items, and clone… May 11, 2026 at 12:15 pm
  • added an answer :g/xxxx/d This will delete all the lines with pattern, and… May 11, 2026 at 12:15 pm
  • added an answer Using your example, the solution is simple: bool DoOrTimeout<T>(T method,… May 11, 2026 at 12:15 pm

Related Questions

In the (otherwise) excellent book C++ Coding Standards , Item 44, titled Prefer writing
In the How Can I Expose Only a Fragment of IList<> question one of
In the course of your software development lifecycle, what essential design artifacts do you
In the case of languages that support single decision and action without brackets, such
In the latest version of WordPress, it gives you the opportunity to view a
In the past I've never been a fan of using triggers on database tables.
In the code below For i = LBound(arr) To UBound(arr) What is the point
In the PHP manual, to show the syntax for functions with optional parameters, they
In the Windows applications I work on, we have a custom framework that sits
In the business I work for we are discussion methods to reduce the read

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.