If only Java supported XML ...

« Return to Article
  • Rohan 2004-09-02 12:06
    Wish I was a consultant...
  • skicow 2004-09-02 12:22
    I love how the variable VERSION contains the string "version".
  • Stephen 2004-09-02 12:46
    The only thing I can really say for this one is: <br> <br>private static WOW = &quot;wow&quot;; <br>&lt;snip&gt; <br>System.WriteLn(WOW); <br> <br>I guess that I am just shocked and amazed thsat some could be oblivious to the world. It is like he lived in some kind of cave or something. Maybe he's a PHB in disguise?
  • Stephen 2004-09-02 12:46
    Ermm... Yea ignore my syntax errors :/
  • Ovidiu 2004-09-02 13:32
    Hey, at least the guy almost has versioning support built-in :)
  • Jeff 2004-09-02 13:42
    private static final char Q_MARK = &quot;?&quot;; <br> <br>I've heard the language committies are considering changing the question mark to &amp;#8225; <br>so we better start coding around that.
  • Jeff 2004-09-02 13:43
    Well, that didn't work. <br>
  • Johnie 2004-09-02 16:07
    I'm just waiting for one that goes: <br>private static final char a = 'a'; <br>private static final char b = 'b'; <br>private static final char c = 'c'; <br>private static final char d = 'd'; <br>private static final char e = 'e'; <br>... <br> <br>System.out.println(h+e+l+l+o+comman+space+w+o+r+l+d);
  • Andrew 2004-09-02 16:18
    I like the way he couldnt spell &quot;APOSTROPHE&quot;
  • The Wolf 2004-09-02 19:56
    Thats just sad?
  • Jannik Anker 2004-09-03 02:53
    Hehe. Apostrope. Wazzah?
  • linuxfood 2004-09-03 03:35
    I'm in awe of this guy... <br> <br>I'm not sure if I should feel scared or just laugh my ass off or both.
  • TheF0o1 2004-09-03 09:22
    To be fair, JAXP was only added as a standard part of the Java platform in J2SE version 1.4.0, just a few years ago. I'd like to know how long ago this code was written. I've seen consultants that have a library of old code that they reuse on different projects.
  • Jeff 2004-09-03 10:50
    I thought a bracket was [ or ] .... what does he call those characters when he needs them?
  • Artik 2004-09-03 11:33
    It's mnot a pelling mistake, i suspect the code comes from a french company
  • J Q Random 2004-09-04 01:47
    Except &quot;apostrophe&quot; in French is &quot;apostrophe&quot;.
  • Hassan Voyeau 2004-09-04 10:12
    This code is absolute rubbish, and I can see no way to defend it...
  • Chris Capel 2004-09-04 15:02
    A theme I've seen come up pretty often (like, twice?) in this blog is defining symbolic constants for literal constants that will not change anytime before armageddon. I don't see how anyone would get the idea that this is a good thing, except if they're paid by code volume and unscruplous. Any ideas?
  • Toni Kingo 2004-09-06 15:11
    But - does Java actually support XML ?
  • Hassan Voyeau 2004-09-06 16:18
    Of course it does -- <a target="_new" href="http://java.sun.com/xml/">http://java.sun.com/xml/</a>
  • cablito 2004-09-06 20:13
    whats wrong with writting portable code?
  • Chris Capel 2004-09-07 08:55
    What's not portable about buffer.append(&quot;&lt;?xml version=\&quot;1.0\&quot;?&gt;&quot;); ?
  • Tuck 2004-09-07 09:01
    As a rule of thumb, you shouldn't have numeric constants in code (other than loop indices). I think this is an example of extending that rule to string and character constants.
  • Johannes Faustus 2004-09-09 11:52
    I hate to say it, but there is some (perhaps minor) justification in Java to this bizarre-looking approach. It's not a perfect coding example -- but how often do we see those? <br> <br> <br>(1) Java, King of String <br> <br>Java has a fairly unusual approach to building strings, at least for those who code in C or C++. When you concatenate, say, a &quot;*&quot; to the end of the Java string str1 (quoting from Sun): <br> <br>Java strings are immutable, they don't change after they're created. What actually happens is that: <br> <br>A StringBuffer is set up <br> <br>str1 is copied to it <br> <br>The &quot;*&quot; is appended to the buffer <br> <br>The result is converted to a string <br> <br>The str1 reference is made to point at that string. <br> <br>The old string that str1 previously referenced is then made available for garbage collection. <br> <br> <br> <br>(2) Premature Optimization, Bane of the Young <br> <br>It's widely known that impressive performance problems in stock Java code come from string concatenation. In fact, in my tattered old copy of Dov Bulka's &quot;Java Performance and Scalability, Volume 1&quot;, the very first optimization (pages 1 - 6) is the use of a string buffer instead of a &quot;destination string&quot; when building a longer string from component strings. There's a very impressive &quot;before and after&quot; performance bar graph, with the &quot;before&quot; bar reaching the top of the printed page and &quot;after&quot; being a thin horizontal line beside it - representing 2200 milliseconds for a naive string-to-string concatenation versus 8 milliseconds for the same operation using a string buffer. <br> <br>As a result, receptive young Java programmers are themselves programmed to avoid string concatenation at any cost. Their little buttocks are peppered with spanks if they concatenate more than (say) two strings together. So the spectacle in this example is far from rare. <br> <br> <br> <br>(3) We're Recycling to Reduce Our Re-Use <br> <br>Many of us would defend the use of constants rather than literals in places where the literal values might change over time. The example code we're excoriating is a bit extreme, but represents a form of good style -- as indicated by this entry from the New Hacker's Dictionary: <br> <br>&quot;magic number&quot;: In source code, some non-obvious constant whose value is significant to the operation of a program and that is inserted inconspicuously in-line (hardcoded), rather than expanded in by a symbol set by a commented #define. Magic numbers in this sense are bad style. <br> <br>And we have to recommend the writer's close attention to constant naming as recommended in &quot;The Elements of Java Style&quot;: <br> <br>[Dictum] 31: Use uppercase letters for each word and separate each pair of words with an underscore when naming constants. <br> <br> <br>However, we must wonder whether there's a little featherbedding going on. Constants - even long lists of obvious constants like we see here - are valuable if they can be used and reused throughout a system. If tomorrow the W3C changes the format of XML such that LEFT_BRACKET becomes, say, &quot;[&quot;, an application using the writer's string constants would be easily updated. However, that can't work when the constants are hidden and private, as they are defined here. We can just imagine, scattered through this application, little private islands of single-use string constants bulking up the line count. <br> <br> <br> <br>(4) Diagnosis <br> <br>It looks like this writer adheres to the letter of the Java law, but has some problems stringing those letters together to make good sense. <br> <br> <br> <br>&quot;If you want truly to understand something, try to change it.&quot; Kurt Lewin <br>
  • Joe User 2004-09-09 16:03
    Enterprise beans are a laugh.
  • Matt 2004-09-09 23:17
    Also, shouldn't he be using single quotes on his chars? <br>private static final char LEFT_BRACKET = '&lt;'; <br>// not (&quot;&lt;&quot;) <br> <br>Wouldn't you get: <br>Type mismatch: cannot convert from String to char
  • Hassan Voyeau 2004-09-10 14:55
    Matt, you are indeed correct, String and char are incompatible types for the assignment operator, and to the best of my knowledge, Java does not have operator overloading. Maybe this programmer is using a preprocessor.
  • Cheli 2004-09-24 07:38
    I used to work in a Cold Fusion shop (am I allowed to post here?) and observed this little gem of css workaround: <br> <br>&lt;cfscript&gt; <br>font = structNew(); <br>font.black = &quot;black&quot;; <br>font.white = &quot;white&quot;; <br>font.etc = &quot;what a blow hole&quot;; <br>&lt;/cfscript&gt; <br> <br>.... <br> <br>&lt;font color=&quot;&lt;cfoutput&gt;#font.black#&lt;/cfoutput&gt;&quot;&gt;
  • Magnus 2004-09-26 15:47
    Could this be a case of imitating the spec a bit too closely? It kind of resembles <a target="_new" href="http://w3.org/TR/2004/REC-xml-20040204/#sec-prolog-dtd">http://w3.org/TR/2004/REC-xml-20040204/#sec-prolog-dtd</a> in a perverse way.
  • andrzej 2004-10-08 07:45
    Hillarious...but one of the respondent's comments about using symbolic constants does make sense many times, albeit not in this example. <br> <br>It can be very useful to localize constant values that might be used in more than one location in the code later one. Say things like initial buffer sizes, attribute names that need to be located, etc. That way if the value ever changes in the future, you just change it in one place. <br> <br>Mind you, if you expect the change to happen, then making it a property or some such from a config file may make more sense. Using the constant only makes sense if you don't expect the value to change. <br> <br>
  • Someone who knows 2004-10-15 20:17
    That's Accenture code, I guarantee it. They ship us crap like this all the time.