Re: java questions for Interview in coorporate
Supersedes: <naming-20080117010038@ram.dialup.fu-berlin.de>
Joshua Cranmer <Pidgeot18@verizon.invalid> writes:
The Sun Java coding standards specify that a method should be
named as a verb. "capacity" is not a verb, where as
{get,set}Capacity is (verb phrase, actually, but that's beside
the point).
Yes. This is correct.
But I don't know a single person (including Sun)
adhering to this recommendation.
In this case, the recommendation is wrong
and the code of practice is right.
The right rule was given by Rob Pike in 1989:
?Procedure names should reflect what they do;
function names should reflect what they return.?
http://www.lysator.liu.se/c/pikestyle.html
?Procedure? and ?function? in Java, of course, are methods
that have an effect and methods that return a value, respectively.
(I ignore other methods here, for simplicity.)
And ?what they do?, of course, means a verb phrase,
while ?what they return? means a noun phrase.
Pike simple states deep structure rules of any language
beyond which we cannot trespass with impunity.