Re: Code Conventions (was: Iterating over an array style question)
On Sat, 27 Nov 2010, Stefan Ram wrote:
=?UTF-8?B?QXJuZSBWYWpow7hq?= <arne@vajhoej.dk> writes:
Let me quote Java Coding Convention:
<quote>
10.5.1 Parentheses
It is generally a good idea to use parentheses liberally in expressions
involving mixed operators to avoid operator precedence problems. Even if
the operator precedence seems clear to you, it might not be to
others-you shouldn't assume that other programmers know precedence as
well as you do.
</quote>
The Java Code Conventions were last modified in 1999.
They also contain other advice that obviously is bad:
?Methods should be verbs (...) runFast();?
http://www.oracle.com/technetwork/java/codeconventions-135099.html
First, ?run fast? is not a verb. ?run? is a verb. ?run fast?
is a verbal phrase.
And an incorrect one - 'fast' is an adjective, not an adverb. It should be
runQuickly, or perhaps runSwiftly.
At least, in English usage as it stood, say, a hundred years ago. Enough
people now use 'fast' as an adverb that it's correct, although to me at
least, it still seems crass.
Next, obviously this advice was not followed even by Sun
engineers, and for good reasons, we have ?main? and ?sin?
If you think 'sin' isn't a verb, you should consult your local priest
immediately!
- not ?run? and (I can't find any verb for a method that is
used to write expressions denotating the sine of a value).
Insinulate. And if it isn't, it should be.
The correct rule in this regard is given by Rob Pike:
?Procedure names should reflect what they do;
function names should reflect what they return.?
I think that's a good rule. Now all we need is for the compiler to be able
to tell verb and noun phrases apart, and to enforce a lack of effects in
noun-named functions, and the presence of at least one effect in
verb-named functions.
http://www.lysator.liu.se/c/pikestyle.html
This, ?sin?, correctly, is a noun, because it names what
is returned.
Although really, under that rule, it should be sine - sin is not a word in
English, it's a mathematical symbol.
tom
--
An unreliable programming language generating unreliable programs
constitutes a far greater risk to our environment and to our society than
unsafe cars, toxic pesticides, or accidents at nuclear power stations. --
C. A. R. Hoare