From: Beman Dawes (bdawes_at_[hidden])
Date: 2001-07-03 16:19:26
At 01:46 PM 7/3/2001, Ed Brey wrote:
>> > 8.4 "Function definitions in the class body are forbidden". It is my
>> > understanding that a function that soes nothing but expose a
>> > version of a member variable is quite reasonable to declare within
>> > class definition. Any reason why this usage is not mentioned here?
>> Because it's forbidden. Every implementation detail you expose in the
>> class body obscures the interface.
>Agreed. Here again, I'm curious to hear if how people find the
>convenience (and productivity?) of not defining the function separately
>trades off against the interface obscurement.
I think there is a somewhat different issue here.
Broadly speaking, source files can be classified as interface files
(normally headers) or implementation files (normally .cpp) in terms of
primary purpose. In reality, both .hpp and .cpp files are mixtures of
interface and implementation code.
The purpose of coding guidelines for interface code should be to clarify
and illuminate the interface, while hiding the implementation and its
details. Thus Dave's guideline above makes great sense for interface code.
The purpose of coding guidelines for implementation code should be to
clarify and illuminate the implementation and its details. There are cases
where this is best achieved by defining functions within the class
body. An example would be one or two line functions defined in a small
implementation helper class, in an implementation file, and not part of the
library's published interface. But note the long list of qualifications;
if in doubt, fall back on Dave's guideline.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk