Re: Iterating over an array style question
On 11/24/2010 11:57 PM, Eric Sosman wrote:
On 11/24/2010 9:15 PM, Lew wrote:
[... concerning `weight[i]*a[--i]' ...]
Java programmers should be expected to know the language if they're
being paid to know the language. [...]
On occasion, Lew, you have scolded people for ignoring naming
and formatting conventions, the reason (sometimes stated, sometimes
implied) being that sticking with familiar conventions improves
readability. That is, you see value in following patterns beyond
those that the language itself enforces. I put it to you that
package FEDEX;import java.math.BigInteger;public class clown
{public static void main(String[]BigIntiger){System.out.
println(new String(new clown("Champagne Charlie"));}private
String JFrame;public clown(String Pattern){clown IOException
=this;IOException.JFrame=new String(Pattern);}public String
tostring(){return JFrame+" is my name!";}}
... is perfectly legal Java, which "Java programmers should be expected
to know." Are we agreed?
However, I don't think you'd argue that a Java programmer should
Good point, Eric.
Again, I am not saying that the style in question is good, only that it is not
unclear. The obfuscation caused by eliminating whitespace was not at issue in
the idiom under question, so there's a bit of apples and oranges comparison in
your example. What was at issue, or at least what I was addressing, was
whether the semantics of a particular idiom
x = weight[i]*a[--i]; (sic)
were clear. Once again, as I stated upthread, "clear" and "desirable" are not
perfect synonyms. I will graciously grant that the idiom could be unclear to
careless reading or careless readers, neither of which have any business in
code maintenance, and that it might cost two or three seconds in extra
ratiocination by the poor, poor hapless maintenance programmer. As a matter
of polish and style, and assistance to debugger step-throughs, it does make
sense to recast this expression as
{
final int j = i--;
x = weight [j] * a [i];
}
But now we can argue aimlessly and endlessly that the code is too "verbose",
the argument proffered by people who aren't busy calling one names for finding
legal Java semantically unambiguous.
What astounds me is the frenzy to which some people are driven by the
suggestion that a programmer should have minimal skills in their profession.
Why is that such a horrid, heretical thing to suggest? There seems to be a
body of apologists that programming should be made easy for people unfamiliar
with the programming language, that it should not require even elementary,
introductory knowledge.
I am bemused.
--
Lew