From: John B. Matthews on
Recently, the Java example in the Wikipedia article entitled "Adapter
Pattern" [1] was modified to use the keyword "final" in a way that may
be considered superfluous [2]. The revision also incorrectly used the
for-each loop. The example is reasonable, but it differs considerably
from one recently proposed [3]. I've edited the article, but I'd be
grateful for any review or corrections.

[1]<http://en.wikipedia.org/wiki/Adapter_pattern>
[2]<http://stackoverflow.com/questions/500517>
[3]<http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/898c30260012fba3>

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
From: Alan Malloy on
John B. Matthews wrote:
> Recently, the Java example in the Wikipedia article entitled "Adapter
> Pattern" [1] was modified to use the keyword "final" in a way that may
> be considered superfluous [2]. The revision also incorrectly used the
> for-each loop. The example is reasonable, but it differs considerably
> from one recently proposed [3]. I've edited the article, but I'd be
> grateful for any review or corrections.
>
> [1]<http://en.wikipedia.org/wiki/Adapter_pattern>
> [2]<http://stackoverflow.com/questions/500517>
> [3]<http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/898c30260012fba3>
>

Yes, those final keywords were ridiculous. It's kinda tacky for you to
do all these whitespace changes, though - it causes Wikipedia to report
a much larger diff than necessary. It doesn't look like the previous
whitespace was so awful, so I assume you didn't do this on purpose, but
rather your editor did it automatically and you didn't undo it.
Similarly, you seem to have moved a bunch of brackets around. I don't
recall if there's a "standard" indentation style for Java, but either
way people feel strongly about it, and if you start editing brace
placements in an article you just start a tug-of-war between two groups.
The article's also no longer internally consistent re: bracing. The
first half puts open-braces on the same line as the class/method, and
the second half puts them on a new line.

I do think, though, that the final modifiers on the member variables
wasn't superfluous. It's unnecessary in this example, but it
self-documents that the class author wants the object to be immutable.

I don't see what you mean by using the for-each loop wrong? They put a
silly "final" in there, but it doesn't look like you made any other changes.

For what it's worth, I think your horse/animal example is miles better
than this convoluted and useless line/rectangle nonsense.

--
Cheers,
Alan (San Jose, California, USA)
From: markspace on
John B. Matthews wrote:
> Recently, the Java example in the Wikipedia article entitled "Adapter
> Pattern" [1] was modified to use the keyword "final" in a way that may
> be considered superfluous [2]. The revision also incorrectly used the
> for-each loop. The example is reasonable, but it differs considerably
> from one recently proposed [3]. I've edited the article, but I'd be
> grateful for any review or corrections.
>
> [1]<http://en.wikipedia.org/wiki/Adapter_pattern>
> [2]<http://stackoverflow.com/questions/500517>
> [3]<http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/898c30260012fba3>
>


Well I have a few biases here, but it seems I've been blocked from
editing Wikipedia. Apparently someone from the west coast has been
posting harassing comments, and there's a block of a net-block for my
entire ISP. Oh well.

I do mostly agree with Alan's comments though.

From: John B. Matthews on
In article <hs9csj$odc$3(a)news.eternal-september.org>,
Alan Malloy <alan.NO.SPAM(a)malloys.org> wrote:

> John B. Matthews wrote:
> > Recently, the Java example in the Wikipedia article entitled
> > "Adapter Pattern" [1] was modified to use the keyword "final" in a
> > way that may be considered superfluous [2]. The revision also
> > incorrectly used the for-each loop. The example is reasonable, but
> > it differs considerably from one recently proposed [3]. I've edited
> > the article, but I'd be grateful for any review or corrections.
> >
> > [1]<http://en.wikipedia.org/wiki/Adapter_pattern>
> > [2]<http://stackoverflow.com/questions/500517>
> > [3]<http://groups.google.com/group/comp.lang.java.programmer/
browse_frm/thread/898c30260012fba3>
> >
>
> Yes, those final keywords were ridiculous. It's kinda tacky for you
> to do all these whitespace changes, though - it causes Wikipedia to
> report a much larger diff than necessary. It doesn't look like the
> previous whitespace was so awful, so I assume you didn't do this on
> purpose, but rather your editor did it automatically and you didn't
> undo it. Similarly, you seem to have moved a bunch of brackets
> around. I don't recall if there's a "standard" indentation style for
> Java, but either way people feel strongly about it, and if you start
> editing brace placements in an article you just start a tug-of-war
> between two groups. The article's also no longer internally
> consistent re: bracing. The first half puts open-braces on the same
> line as the class/method, and the second half puts them on a new
> line.

Alan Malloy & markspace: Thanks both for commenting. I see what you
mean about the whitespace. I used the "undo" button to restore the
original; if you select both revisions you'll see the two line change
that I alone made.

Re braces: Indeed, the original "//Before" section uses one style and
"//After" uses another. I left that alone. I use either style, as the
occasion demands; but I am unable to resist sharing my favorite brace
joke:

<http://junit.sourceforge.net/doc/faq/faq.htm#organize_1>

> I do think, though, that the final modifiers on the member variables
> wasn't superfluous. It's unnecessary in this example, but it
> self-documents that the class author wants the object to be
> immutable.
>
> I don't see what you mean by using the for-each loop wrong? They put
> a silly "final" in there, but it doesn't look like you made any other
> changes.

IIUC, the interlocutor changed a "for int i" to "for Shape s", but
neglected to update the reference inside the loop, accordingly.

> For what it's worth, I think your horse/animal example is miles
> better than this convoluted and useless line/rectangle nonsense.

The credit goes to markspace.

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
From: Arne Vajhøj on
On 10-05-2010 11:31, John B. Matthews wrote:
> Recently, the Java example in the Wikipedia article entitled "Adapter
> Pattern" [1] was modified to use the keyword "final" in a way that may
> be considered superfluous [2]. The revision also incorrectly used the
> for-each loop. The example is reasonable, but it differs considerably
> from one recently proposed [3]. I've edited the article, but I'd be
> grateful for any review or corrections.
>
> [1]<http://en.wikipedia.org/wiki/Adapter_pattern>
> [2]<http://stackoverflow.com/questions/500517>
> [3]<http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/898c30260012fba3>

Looks fine to me.

I don't like the "one final keyword per line of code" practice.

I would have used the old instanceof and () cast instead
of those Class methods, but that does not seem to be
important for the point.

Arne