[Exceptional C++ Style] Exceptional C++ Style - Item 24: ConstantOptimization

Adrian Fagg adrianf at evaluategroup.com
Thu Jan 27 07:51:28 EST 2005


> -----Original Message-----
> From: effective-cpp-bounces at accu.org
> [mailto:effective-cpp-bounces at accu.org]On Behalf Of Hammond, Peter
> Sent: 27 January 2005 10:44

> I was wondering about this in the context of coding standards
> recently. In
> Exceptional C++ (item 43) Herb remarks that const on a value
> parameter is
> pointless, and when I see it in a header it worries me: it is
> a sign that
> someone may have misunderstood const, or pass-by-vlaue, or
> both. On the
> other hand, having the constness of the argument enforced in the
> implementaion can be very useful. The obvious way to solve it
> is to leave it
> in the implemtation, but remove it from the definition, as
> the guideline
> above. However, the difference between declaration and
> definition would seem
> to be a source of confusion for many. Has anyone got any
> experience of this
> kind of guideline and whether in practice it helps or confuses?

As an exercise in something or other, I'm not quite sure what, how about a
different slant on this and other coding standard guidelines:

Leaving aside the overwhelming practical objections such as breaking
billions of lines of code, what if the language enforced a rule that all
value parameters were to be treated as const?
How annoying would it be?
For this particular guideline, I'd say hardly annoying at all. As a
resolution of worries about how to declare and define value parameters, it
would be a positive boon.

Similarly hypothetical arguments could apply to, for example, NVI: The
compiler could reject all public and protected virtual functions, thus
annoying 99% of C++ programmers, perhaps excepting Herb and Jim.:-)

Regards,

Adrian

Work: mailto:adrianf at evaluategroup.com
Home: mailto:adrian.fagg at ntlworld.com

Pretty pictures: http://homepage.ntlworld.com/rbyadf/




More information about the Effective-cpp mailing list