Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news.alt.net From: Ian Collins Newsgroups: comp.std.c++ Subject: Re: Proposal: Compilation-unit scoped private member functions Date: Tue, 18 Dec 2012 16:06:37 CST Organization: unknown Lines: 41 Sender: std-cpp-request@vandevoorde.com Approved: stephen.clamage@oracle.com Message-ID: References: <8f16e792-bac4-48f8-b542-33549608f11f@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed To: undisclosed-recipients:; Return-Path: X-Original-Date: Tue, 18 Dec 2012 13:29:27 +1300 X-Submission-Address: std-cpp-submit@vandevoorde.com Xref: csiph.com comp.std.c++:574 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 ]