Re: 64 bit C++ and OS defined types
* James Kanze:
On Apr 5, 2:34 am, "Alf P. Steinbach" <al...@start.no> wrote:
That's because of a preference for readability and my very
subjective opinion of what constitutes readability, he he. :)
And that ties in with that one practical and very C++ specific
benefit of avoiding the prefixes has only to do with "get",
not with "set".
Namely, to supporting letting the client code choose to
manually optimize (awkward notation) or not (especially when
the compiler does it), by doing
void getPopulationData( Container& c )
{
Container result;
...
result.swap( c );
}
Container populationData()
{
Container c;
getPopulationData( c );
return c;
}
Here client code will preferentially use "populationData",
relying on RVO for the cases where efficiency matters.
If it turns out that the compiler isn't up to the task and
measurements show that efficiency of these calls do matter a
lot, then client code can fall back to using
getPopulationData, in the place or places where it affects
performance.
How does this change anything with regards to the choice above?
It's readability, of /the calling code/.
Calling code that says
populationData( o );
doesn't really say anything about what it does. Is it perhaps an assertion that
'o' is population data? Is it perhaps an extraction of population data from 'o'?
What's going to happen here -- or not?
On the other hand, code that says
getPopulationData( o );
says what it does, because there are not many r?les that o can play here and
still have a reasonable programmer's-english sentence construct.
And also code that says
Container const o = populationData();
says what it does.
Of course, also with a "get" prefix there it says what it does because the
reader recognizes the prefix as a common redundant prefix. But, being redundant,
it is redundant. IMHO just visual clutter and more to read and write.
If you use get/set prefixes, overload resolution will come into
play for the selection of the get function. If you use no
prefixes, then the get name is still available for use as above.
Overload resolution is fine with respect to the goal of having the correct
implementation invoked.
It's not fine with respect to e.g. searching in an editor.
And it's not fine with respect to readability, and other human cognitive
activities such as dicussing the code -- then distinct names are bestest. :)
Cheers,
- Alf
--
Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
No ads, and there is some C++ stuff! :-) Just going there is good. Linking
to it is even better! Thanks in advance!