r...@zedat.fu-berlin.de (Stefan Ram) wrote:
> Pavel <pauldont...@removeyourself.dontspam.yahoo> writes:
>> In your case, there is a predominant idiom for selecting the verbs,
>> namely get and set, hugely popularized by Java Beans API.
>
> We are not part of the Java culture, but of the C culture.
I am a part of software engineering culture. I do not think I will ever
identify myself as "XYZ language programmer". Selecting the
right-for-task level of abstraction is one of the key skills software
engineer should possess. Class member name is an abstraction pertinent
to multiple programming languages and is best selected at its own merit.
>
> Our guide, therefore, is Rob Pike, not the Java Language
> specification.
As per the above, I am don't have any sympathy to blind adherence to any
programming language-level Bible, be it JLS, K&R, Most Effective
Anything or any other thing of the kind. I do appreciate all of the
above for good ideas and mean to ignore bad ideas when I see them. I try
to distinguish between good and bad ideas based on rationally defined
criteria.
>
> The JLS says:
>
> »Method names should be verbs or verb phrases«.
>
> But we can see that, using method names such as »main«,
> »max«, or »sin«, they do not follow their own recommendation!
>
> Rob Pike has understood better what governs common
> semantics. He wrote:
>
> »Procedure names should reflect what they do;
> function names should reflect what they return.«
So, how is the name for setter like "precision" you are suggesting below
reflects what the setter "returns"? You do not seem to follow your own
rules.
>
>
http://www.lysator.liu.se/c/pikestyle.html
>
> Do you want to write:
>
> y = arctan( x/ sin( t ))
>
> or would you prefer:
>
> y = calculateArctan( x/ calculateSin( t ))
>
> or
>
> y = getArctan( x/ getSin( t ))
>
> ?
calcArctan or calc_arctan would not be bad. Unfortunately, there is no
supporting idiom: the predominant idiom for naming math functions is to
follow math notation. Math notation was developed for conciseness rather
than readability; and there were multiple reasons for that, both
rational (to shorten manuscripts that were expensive to produce) and
irrational (to hide knowledge from uninitiated).
>
> Thus, setters can be written with »set« as they are
> procedures, but getters should just be named after
> the value they return as programmers have always done.
I am all for following traditions till they don't harm the goal and I do
not see following traditions as a worthy goal in itself. As I mentioned
earlier, my main requirement to the code is readability. Not indicating
in a getter name that it is a getter harms readability in some important
contexts. For example, when the code uses getter name in argument to a
function or initializer, how will a reader know whether the code refers
to data or function member?
>
> A C++ programmer always can follow the style of the
> standard library,
They can but they do not have to and it is not always a good idea. C++
library design is full of both good and bad ideas.
and there we have:
>
> getter: cout.precision();
> setter: cout.precision( 12 );
>