Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #574

Re: Proposal: Compilation-unit scoped private member functions

From Ian Collins<ian-news@this.is.invalid>
Newsgroups comp.std.c++
Subject Re: Proposal: Compilation-unit scoped private member functions
Date 2012-12-18 16:06 -0600
Organization unknown
Message-ID <aj9rn7Fdf3aU7@mid.individual.net> (permalink)
References <ff2d9902-a232-40f4-9e22-97b2563099f8@googlegroups.com> <ahu6pqFijb1U1@mid.individual.net> <8f16e792-bac4-48f8-b542-33549608f11f@googlegroups.com>

Show all headers | View raw


christopher.dearlove@googlemail.com wrote:
>  On Friday, December 14, 2012 5:19:33 PM UTC, Ian Collins wrote:
>>    Your proposal would not improve testability, the locally private
>>    functions would, by virtue of their linkage, be impossible to test.
>
>  How do you test a normal private function?

I wouldn't.  If the function isn't tested via a public interface, I
would create a new class to do the work and test that.

Once upon a time I was in favour of making the test class a friend, but
over time and after much debate within my team, we realised we produced
better code, with more reusable components, by not doing this.

>  I can see your point, and Francis' point, about gain vs. cost. The
>  largest gain I can see (just having seen the proposal outline) is
>  that if I refactor a member function (public or private) by putting
>  some of it into a new function, this allows doing this without
>  changing the header file and hence forcing a recompilation. As Francis
>  says, you can do this by passing member data by reference, but even if
>  you inline the functions (and they may be large enough that some compilers
>  will warn too large to inline, conflicting with the usual practice of
>  getting rid of all warnings as well as errors) that's losing the
>  programmer's convenience and clarity of not having to redeclare data
>  members.

In most cases if a function is too large to inline, the overhead of
calling is is minimal compared to the time spent in the function.  The
inline keyword is never more than a hint, so any warnings are probably
spurious and could be suppressed.

-- 
Ian Collins


[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]

Back to comp.std.c++ | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Proposal: Compilation-unit scoped private member functions kfsone@googlemail.com - 2012-11-21 11:29 -0800
  Re: Proposal: Compilation-unit scoped private member functions Francis Glassborow<francis.glassborow@btinternet.com> - 2012-12-14 09:10 -0800
  Re: Proposal: Compilation-unit scoped private member functions Daniel Krügler<daniel.kruegler@googlemail.com> - 2012-12-14 09:11 -0800
  Re: Proposal: Compilation-unit scoped private member functions Ian Collins<ian-news@this.is.invalid> - 2012-12-14 09:19 -0800
    Re: Proposal: Compilation-unit scoped private member functions christopher.dearlove@googlemail.com - 2012-12-17 08:52 -0800
      Re: Proposal: Compilation-unit scoped private member functions Ian Collins<ian-news@this.is.invalid> - 2012-12-18 16:06 -0600
        Re: Proposal: Compilation-unit scoped private member functions christopher.dearlove@googlemail.com - 2013-02-22 10:48 -0600
          Re: Proposal: Compilation-unit scoped private member functions ootiib@hot.ee - 2013-02-22 16:39 -0600
            Re: Proposal: Compilation-unit scoped private member functions Jason McKesson <jmckesson@googlemail.com> - 2013-02-23 23:22 -0800
              Re: Proposal: Compilation-unit scoped private member functions Balog Pal<pasa@lib.hu> - 2013-02-25 11:01 -0600
          Re: Proposal: Compilation-unit scoped private member functions Ian Collins <ian-news@this.is.invalid> - 2013-02-23 18:21 -0800
            Re: Proposal: Compilation-unit scoped private member functions christopher.dearlove@googlemail.com - 2013-02-25 10:59 -0600
    Re: Proposal: Compilation-unit scoped private member functions Balog Pal<pasa@lib.hu> - 2013-02-25 11:01 -0600
      Re: Proposal: Compilation-unit scoped private member functions Andy Lutomirski <luto@amacapital.net> - 2013-02-28 22:16 -0800

csiph-web