A little afternoon WTF

L

Lew

Ewwww! Emacs!

Why do you use that waste of cycles instead of opening sixty xterms most
running vim instances like Real Men do?

Food fight!
<http://en.wikipedia.org/wiki/Editor_war>

Aside from the sexism of your comment, "ClasslessCasteException", you fail to
realize that REAL Real Coders use chisels and rocks and code all their source
in cuneiform.

If you make a mistake, the client gets to throw the rocks at your head. That
teaches you to get it right the first time.
 
M

Mike Schilling

Lew said:
Aside from the sexism of your comment, "ClasslessCasteException", you
fail to realize that REAL Real Coders use chisels and rocks and code
all their source in cuneiform.

And get snippy with the ones that haven't upgraded to cuneiform one dot
three dot many.
 
A

Arne Vajhøj

Tom said:
Oh god, i've [sic] just spotted another one: the hardcoded CRLF! This
is a
linux [sic]-only project (up to and including developing on linux
[sic] VMs - the
only time you'd ever look at this file would be on a linux [sic]
machine),
and XML normalises all line breaks to LF anyway. Why would you do that?
Perhaps in multi-platform environment, the coder had occasion
to open up the XML in a windows [sic] text editor.

All but one of which handle LF-terminated lines just fine.

You have tried all editors on Windows?

Arne
 
A

Arne Vajhøj

Horse pucky. It's XML, which is UTF-8 encoded by default, and also
explicitly in this example. So it's not even ASCII. And the XML spec
says all XML uses new lines only. Raw carriage returns are translated to
newlines if they are encountered in the input text.

<http://www.w3.org/TR/xml/#sec-line-ends>

If you want to quote specifications, be sure to quote the correct one.

The fact that an XML parser must return LF for CR LF does not
by magic change the rules for transports protocols and lines
of text files. If you send an XML file with N lines over the
network you expect to get an XML file with N lines not
an XML file with 1 line that if it does not get truncated
is parsed identical.

Arne
 
A

Arne Vajhøj

Yes, but ""+int is in fact seen all over the place, just
like graffiti, infomercials, and pop-unders.


Yes, but it's reality.

It certainly is.

But we can still note that it is not good style.

Arne
 
A

Arne Vajhøj

Or int + String:

System.out.println(i + "is the answer");

That somewhat makes sense.
But people who don't realize that that works will often do

System.out.println("" + i + "is the answer");

just to be sure. It's at most a venial sin.

Sure, but it should still be noted that it is not good style.

Arne
 
A

Arne Vajhøj

Using a StringBuilder with precise size estimate I discovered speeded
my static macro code up by 10%. I suspect then that any sort of
framework would similarly benefit. However, he did not specify an
estimate, thus defeating the point of manual StringBuilders.

I somewhat doubt that the value of the improvements is worth
the effort developing it and maintaining it for most real world
apps.

Arne
 
A

Arne Vajhøj

For what it's worth, here's some code I wrote in 2003. It's part of a
JUnit test for a custom XML parsing framework.

private final static String header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

private final static String doc1 =
header
+ "<root foo='bar' baz='quux'>"
+ "<property name='var' value='value'/>"
+ "<property name='nested' value='var'/>"
+ "yabba dabba doo"
+ "<nested blah='blah blah' subst='${var}' nested-subst='${${nested}}'/>"
+ "</root>";

I didn't use an XML writer because I didn't see any particular point in it.

In 2003 I don't think the Java XML API's had anything.

Arne
 
A

Arne Vajhøj

quote:
" String s = new String( "abc" );
" To avoid littering the constant pool with redundant Strings, this
" should be written:
" String s = "abc";

Huh? The first litters the heap with a redundant copy, but
how does it litter the constant pool?

It obviously does not.

But "constant pool" sounds cool.

Arne
 
A

Arne Vajhøj

For your edutainment, some code (lightly anonymised) seen while digging
into code written by some (now-departed) contractors today:

private static String header = "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
"<initech:tps-report><initech:coversheet> etc";

WTF: the empty string literal on the first line. What did they think
that was for?

Some obscure formatting preference.
Secondary WTF: writing XML by hand rather than using StAX or something.
That i'm less outraged about, because it's ordinary ignorance, rather
than the special kind of brainwrong reflected in the primary WTF.

StAX was only added in 1.6.
Oh god, i've just spotted another one: the hardcoded CRLF! This is a
linux-only project (up to and including developing on linux VMs - the
only time you'd ever look at this file would be on a linux machine), and
XML normalises all line breaks to LF anyway. Why would you do that?

Most likely someone that only knows Windows.
Still, at least it's not this, from the other end of the project:

private static final String TEST_DATA_QUERY = new
StringBuilder().append(" select * ")
.append(" from tps_report, tps_folder where tps_folder.id=tps_report.id ")
.append(" and tps_folder.id=2057 ").toString();
Horrible.

I've got no beef with the SQL, that's fine, but WTF: the explicit
StringBuildering. The surplus spaces at the end of the strings and the
lack of indentation on the append lines are the icing on the cake. The
way the where clause is half on the same line as the from and half not
is good too.

None of this is strictly incorrect - it all works - but there's
something distinctly *wrong* about it. It doesn't fill you with
confidence that the important things are done correctly. Nor does
actually looking at the important things, as it happens, because one
immediately sees that they aren't.

I think the standard term is "code smell" - in this case I would
make it "code stink".

Arne
 
L

Lew

Tom said:
Perhaps in multi-platform environment, the coder had occasion
to open up the XML in a windows [sic] text editor.
All but one of which handle LF-terminated lines just fine.
You have tried all editors on Windows?

That is a very valid point - no, I have not.

I obviously was thinking only of the few common ones with which I am familiar,
and generally are found on any modern Windows system.

I stand corrected.
 
S

Stefan Ram

Tom Anderson said:
private static String header = "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
"<initech:tps-report><initech:coversheet> etc";

(After having read this, and also having read some of the
responses:) All of the code I see in the OP is well within
the range of what I do /not/ deem to require any criticism
from me. I myself might not have written it like this, but
it is perfectly readable to me, and there are good reasons
to hard-code XML as string literal sometimes. And every
Java programmer understands the intention of writing
»( "" + 2 )«, you might even think of »""+« as the
»three-character toString operator«.
 
A

Arne Vajhøj

(After having read this, and also having read some of the
responses:) All of the code I see in the OP is well within
the range of what I do /not/ deem to require any criticism
from me. I myself might not have written it like this, but
it is perfectly readable to me, and there are good reasons
to hard-code XML as string literal sometimes. And every
Java programmer understands the intention of writing
»( "" + 2 )«, you might even think of »""+« as the
»three-character toString operator«.

But as you said: you would not write it this way.

And my guess is that is because someone many years
ago told that is was not good style.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top