Comment On Oh, XML

"Having worked in the Computer industry for about twenty years now," Matt writes, "I rarely get the chance to actually write code. But I do get the joy of other people's problems landing at my feet when things go wrong." [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Oh, XML

2008-04-30 08:02 • by JavaCoder (unregistered)
The real WTF is that it is -128 to +127.

Re: Oh, XML

2008-04-30 08:05 • by snoofle
I suppose it all depends upon how many bits you have in your bytes. Personally, I always overdesign a bit (pun intended) and use 9 bits. Problem solved!

Re: Oh, XML

2008-04-30 08:06 • by ParkinT
It is puzzling how an attachment (image, in this case) could be -45 bytes long.
Does it 'leech' data from other files around it?

Re: Oh, XML

2008-04-30 08:09 • by NThenUDie (unregistered)

The real WTF is that someone managed to take what was probably a simple character stream protocol, wrap it in unhelpful XML, declare it enterprise compliant and then collect a bonus or promotion. Nice job!

Re: Oh, XML

2008-04-30 08:11 • by pitchingchris
192242 in reply to 192239
snoofle:
I suppose it all depends upon how many bits you have in your bytes. Personally, I always overdesign a bit (pun intended) and use 9 bits. Problem solved!


The wording of this was kinda funny. Overdesign a bit ! You must be using 3 way bits :)

Re: Oh, XML

2008-04-30 08:12 • by pitchingchris
So much for enterprisey software, it can't even do data validation on the XML !

Re: Oh, XML

2008-04-30 08:14 • by Frank Butcher (unregistered)
192245 in reply to 192238
JavaCoder:
The real WTF is that it is -128 to +127.

Please tell me this is a joke taking the piss out of java coders....

Re: Oh, XML

2008-04-30 08:31 • by Bob (unregistered)
Image data! Wtf?

Re: Oh, XML

2008-04-30 08:33 • by Edward Royce (unregistered)
Hmmmm.

"<bytes>37</bytes>"

Are you telling me that your library is wrapping a "<bytes>" + "</bytes>" tag pair around each and every singl *byte* of image data??

Doesn't that blow up image sizes by 16? A 10k would become 160k. Isn't that a little ridiculous?

Re: Oh, XML

2008-04-30 08:37 • by Will (unregistered)
192249 in reply to 192248
Edward Royce:

Doesn't that blow up image sizes by 16? A 10k would become 160k. Isn't that a little ridiculous?


He said it was enterprisy didn't he...

Re: Oh, XML

2008-04-30 08:38 • by CrazyBomber
192250 in reply to 192248
Edward Royce:
Hmmmm.

"<bytes>37</bytes>"

Are you telling me that your library is wrapping a "<bytes>" + "</bytes>" tag pair around each and every singl *byte* of image data??

Doesn't that blow up image sizes by 16? A 10k would become 160k. Isn't that a little ridiculous?


Oh... My... God...
Really looks that way! :|

Re: Oh, XML

2008-04-30 08:39 • by tag (unregistered)
192251 in reply to 192248
Doesn't that blow up image sizes by 16? A 10k would become 160k. Isn't that a little ridiculous?


Try saving as BMP uncompressed. THAT is ridiculous.

Re: Oh, XML

2008-04-30 08:40 • by Adrian (unregistered)
After reading this column since nears its begining - thought i was getting immune to stupidity of programmers.....

once again i find my self thinking 'OMG did the programmer have any idea of what s/he was doing?'

Re: Oh, XML

2008-04-30 08:42 • by draeath (unregistered)
192254 in reply to 192250
Hopefully the xml is gzipped on-the-fly. We can only hope.

Re: Oh, XML

2008-04-30 08:46 • by ljj116
The real WTF is that the <bytes> tag only contains a single byte....it should be <byte>. </rants>

Re: Oh, XML

2008-04-30 08:46 • by Chucara (unregistered)
Wow.. I had no idea XML could be this useful. Now you can use any random text editor instead of photoshop! Excellent solution once you fix the bug. Again, that would be easy to do with an XML editor. Brilliant!

Re: Oh, XML

2008-04-30 08:47 • by JavaCoder (unregistered)
192257 in reply to 192245
Frank Butcher:
JavaCoder:
The real WTF is that it is -128 to +127.

Please tell me this is a joke taking the piss out of java coders....


Two's complement is not a joke.

Re: Oh, XML

2008-04-30 08:47 • by dkf
192258 in reply to 192248
Edward Royce:
Are you telling me that your library is wrapping a "<bytes>" + "</bytes>" tag pair around each and every singl *byte* of image data??
There is one way to fix this problem. Convert each of those to something like this (with namespaces omitted for brevity):

<bytes>

<bit number="0" lsb="true">1</bit>
<bit number="2">1</bit>
<bit number="5">1</bit>
<bit default="true">0</bit>
</bytes>

By doing this, you eliminate the interoperability problem of just how to represent bytes and instead have something that is easy to interpret unambiguously every time!!

Re: Oh, XML

2008-04-30 08:48 • by snoofle
192259 in reply to 192242
pitchingchris:
snoofle:
I suppose it all depends upon how many bits you have in your bytes. Personally, I always overdesign a bit (pun intended) and use 9 bits. Problem solved!


The wording of this was kinda funny. Overdesign a bit ! You must be using 3 way bits :)

This forum has featured numerous articles on state
x>2 booleans, and of course, the original

Re: Oh, XML

2008-04-30 08:49 • by cthulhu (unregistered)
Another problem with this technique is that bytes alone mean nothing to most people and you can't tell the dimensions of the image. A better solution would probably be:

<Row>
<pixel>Green</pixel>
<pixel>Yellow</pixel>
<pixel>Red</pixel>
</Row>

There are many standardized color charts that could be utilized that I believe cover all possible real-life colors, eg:

<pixel>Sunset Orange</pixel>
<pixel>Light Green</pixel>
<pixel>Reddish</pixel>
<pixel>Lime Green</pixel>
<pixel>Sea Breeze Blue</pixel>
<pixel>Woodchip Brown</pixel>

This way the underlying encoding for images could be understood by anyone. This might be a worthwhile project for anyone with sufficient XML skills.

Re: Oh, XML

2008-04-30 08:50 • by Tobias (unregistered)
I bet somewhere deep in the code there is a loop over all the bytes of the image data that looks like this:

public String toXML(ByteIterator bIt) {

StringBuilder sb = new StringBuilder("<attachments xmlns=...>");
while(bIt.hasNext()) {
sb.append("<bytes>");
sb.append(toHexString(bIt.next()));
sb.append("</bytes>");
}
sb.append("</attachments>");

return sb.toString();
}


But more probably it is done by String-concatenation with "+" for performance reasons (Don't have to instantiate this crappy StringBuilder etc) ...

kind regards
Tobias

Re: Oh, XML

2008-04-30 09:02 • by The_Assimilator (unregistered)
The goggles, they cannot stop the bleeding from my eyes!

Seriously, the developer who wrote that serialization "code" should be forced to print it out and eat it. Matt, please tell me you fired that guy on the spot...

Re: Oh, XML

2008-04-30 09:13 • by Anonymous (unregistered)
192266 in reply to 192251
tag:
Doesn't that blow up image sizes by 16? Isn't that a little ridiculous?

Try saving as BMP uncompressed. THAT is ridiculous.

Well, you can always use PNG at 64 bit per pixel with compression turned off...

Re: Oh, XML

2008-04-30 09:20 • by Enterpriser (unregistered)
This code is horrible. Even if the app _was_ expecting numbers in the range 0-255, COMPUTERS ARE NOT MAGICIANS. How are they supposed to know what such generic numbers are representative of. If this was using a real enterprise approach it would be:

<attachments xmlns = "http://webservices..." >
<bytes>
<integer prime="true">
<positive>
<odd>37</odd>
</positive>
</integer>
</bytes>
<bytes>
<integer prime="false">
<positive>
<even>80</even>
</positive>
</integer>
</bytes>
...

and if I knew how to format with this thing, you would even be able to read it!

Re: Oh, XML

2008-04-30 09:23 • by xtremezone
The real WTF is that it appears a byte is stored in an element called "bytes"... :-/
Enterpriser:
...and if I knew how to format with this thing, you would even be able to read it!

There are [code][/code] tags, but they add extra line breaks...

Re: Oh, XML

2008-04-30 09:24 • by vt_mruhlin
192269 in reply to 192248
Edward Royce:
Hmmmm.

"<bytes>37</bytes>"

Are you telling me that your library is wrapping a "<bytes>" + "</bytes>" tag pair around each and every singl *byte* of image data??

Doesn't that blow up image sizes by 16? A 10k would become 160k. Isn't that a little ridiculous?


Well it's worse than that. Those bytes are being written out as 1 to 3 digits of ASCII, with an optional negative sign. 160k would be your best case scenario and only applicable if the bytes were between 0 and 9. Worst case scenario would be 200k though, so not much more....

These guys should totally do an efficiency enhancement feature to make the thing smaller by putting it in signed hex format (-80 through 79). That way you potentially save one byte per byte...at least until your local standards nazi comes and deems that the values be written as -0x80 through 0x79....

Re: Oh, XML

2008-04-30 09:29 • by mauhiz (unregistered)
<comment xmlns = "http://thedailywtf..." >
<bytes>79</bytes>
<bytes>77</bytes>
<bytes>71</bytes>
...

Re: Oh, XML

2008-04-30 09:29 • by Morten (unregistered)
Enterprise Heaven! This is why god invented HPC's!!

My God, even I know how to use Base64 strings for straight out of the box Xml serialization of binary files...

Re: Oh, XML

2008-04-30 09:42 • by Outlaw Programmer
192274 in reply to 192271
The Real WTF is only hinted at here. The fix was, of course, to write a "BytesConverter class" that parses the XML, adds 128 to each element, then writes it back into XML to be consumed by the client.

Seriously though, I have a feeling this is actually the 2nd implementation of the Web Service. The first implementation was the sane one where the content type is set as image/jpg and an image is returned. The CTO then steps in, says "This is not Enterprisy enough! It doesn't fit in with our framework!" Then the junior dev goes back to square one and this monstrosity is the result.

Re: Oh, XML

2008-04-30 09:59 • by joelkatz
192277 in reply to 192248
TRWTF is that XML contains a perfectly reasonable way to specify arbitrary chunks of binary data. It does not involve wrapping every single byte in its own tag. Base64 encoding is perfectly nice too.

But why follow a standard when you can make up your own half-assed way? Then when it breaks, you never know who to blame because nobody knows what the right way is.

Re: Oh, XML

2008-04-30 09:59 • by hacketihackhack (unregistered)
192278 in reply to 192248
Yeah it is rediciolus. Why not just base64-encode the thing and wrap it in a tag?

But OTH gzipping it at transport level wouldn't make it THAT much bigger, since the byte tags are all the same.

Re: Oh, XML

2008-04-30 10:01 • by hacketihackhack (unregistered)
192279 in reply to 192267
Oh I love the redundancy of that one!

Re: Oh, XML

2008-04-30 10:04 • by TwelveBaud (unregistered)
192280 in reply to 192256
Chucara:
Wow.. I had no idea XML could be this useful. Now you can use any random text editor instead of photoshop! Excellent solution once you fix the bug. Again, that would be easy to do with an XML editor. Brillant!
fixed. :P

Re: Oh, XML

2008-04-30 10:05 • by bold (unregistered)
Remembering that XML's golden selling point is "human readable", image expression should be more like this:

<image scale="(about yay big)">
<background>
<color-palette class="sunsetty"><not-too value="orange"><possibly-some-kind-of type="clouds" class="whispy"/></not-too>
</background>
<overlay origin="(in the middle(left a bit))">
<sort-of a="dog"><with a="tail"><but more-like="ref:horse"/></with></sort-of>
</overlay>
<paint-brush style="wooden-handled">
<set id="horse" merge="(closing one eye hold up your thumb)" canvas="linen">
<paint style="jackson-pollock"/>
<paint style="something nice"/>
</set>
<paint inspiration="shetland pony"/>
</paint-brush>
</image>

Re: Oh, XML

2008-04-30 10:08 • by xtremezone
192284 in reply to 192260
cthulhu:
Another problem with this technique is that bytes alone mean nothing to most people and you can't tell the dimensions of the image. A better solution would probably be:

<Row>
<pixel>Green</pixel>
<pixel>Yellow</pixel>
<pixel>Red</pixel>
</Row>

There are many standardized color charts that could be utilized that I believe cover all possible real-life colors, eg:

<pixel>Sunset Orange</pixel>
<pixel>Light Green</pixel>
<pixel>Reddish</pixel>
<pixel>Lime Green</pixel>
<pixel>Sea Breeze Blue</pixel>
<pixel>Woodchip Brown</pixel>

This way the underlying encoding for images could be understood by anyone. This might be a worthwhile project for anyone with sufficient XML skills.

I don't know if this is meant to be serious or not... I'm no XML expert (or fan), but I think that "entity references" (if I'm thinking of the right thing) would be more efficient and reliable than string colors.
<!-- You could also probably just define the integer value instead of the string. Whatever. -->

<!ENTITY sunset-orange PUBLIC "Sunset Orange">
<!ENTITY light-green PUBLIC "Light Green">
<!ENTITY reddish PUBLIC "Reddish">
<!ENTITY lime-green PUBLIC "Lime Green">
<!ENTITY sea-breeze-blue PUBLIC "Sea Breeze Blue">
<!ENTITY woodchip-brown PUBLIC "Woodchip Brown">
(etc...)

<pixel>&sunset-orange;</pixel>

<pixel>&light-green;</pixel>
<pixel>&reddish;</pixel>
<pixel>&lime-green;</pixel>
<pixel>&sea-breeze-blue;</pixel>
<pixel>&woodchip-brown;</pixel>

Assuming that an error would be thrown if the reference didn't exist (i.e. typed the wrong name). For the record, I've only taken a single XML class (which I hated) and haven't really used it since so I could be completely wrong. =P Again, I'm no fan of XML.

Re: Oh, XML

2008-04-30 10:10 • by luptatum (unregistered)
192285 in reply to 192248
Just converting a byte array to a string will double the size... If you have one byte 0xFF.ToString("X") == "FF" as a string which is two bytes long (in ASCII and excluding other encoding types) WTF! Why oh why do people do these things?!?!

[quote user="cthulhu"]This way the underlying encoding for images could be understood by anyone. This might be a worthwhile project for anyone with sufficient XML skills[/quote] plz send teh codz!!!

If you build it, someone will buy and use it...

[quote user="Tobias"]ut more probably it is done by String-concatenation with "+" for performance reasons (Don't have to instantiate this crappy StringBuilder etc) ... [/quote[
heh as you said, the real wtf for the people who write this crap is this string builder waste of programming cycles you write about...

Re: Oh, XML

2008-04-30 10:23 • by Chandler (unregistered)
192289 in reply to 192260
I am thoroughly inspired. This may have to become a side proejct for me.

Re: Oh, XML

2008-04-30 10:32 • by Physics Phil
192292 in reply to 192285
luptatum:

Tobias:
ut more probably it is done by String-concatenation with "+" for performance reasons (Don't have to instantiate this crappy StringBuilder etc) ...

heh as you said, the real wtf for the people who write this crap is this string builder waste of programming cycles you write about...

I may be missing the sarcasm here, but using + for String concatenation in Java is just a shorthand for creating a new StringBuilder, combining all the strings in the line, and then returning the resulting String. This means that at best, with excellent compiler optimisation, you would get the same performance as using StringBuilder manually, and most likely the performance would be worse. In my copious free time I may get around to testing this, but I doubt I will have time in the near future.

Addendum (2008-04-30 10:47):
luptatum:

Tobias:
ut more probably it is done by String-concatenation with "+" for performance reasons (Don't have to instantiate this crappy StringBuilder etc) ...

heh as you said, the real wtf for the people who write this crap is this string builder waste of programming cycles you write about...

I may be missing the sarcasm here, but using + for String concatenation in Java is just a shorthand for creating a new StringBuilder, combining all the strings in the line, and then returning the resulting String. This means that at best, with excellent compiler optimisation, you would get the same performance as using StringBuilder manually, and most likely the performance would be worse. In my copious free time I may get around to testing this, but I doubt I will have time in the near future.

EDIT: Even the complete WTF which is the emacs image editor uses a saner format for image data.

(an even bigger WTF is the emacs video editor(http://1010.co.uk/gneve.html), which is almost as crazy as SSDS, except that the commands make sense and it actually does something useful)

Re: Oh, XML

2008-04-30 10:43 • by Merlin (unregistered)
192300 in reply to 192248
Edward Royce:
Hmmmm.

"<bytes>37</bytes>"

Are you telling me that your library is wrapping a "<bytes>" + "</bytes>" tag pair around each and every singl *byte* of image data??

Doesn't that blow up image sizes by 16? A 10k would become 160k. Isn't that a little ridiculous?


It's even nicer if you try loading the XML-Document into a .NET XMLDocument. The parsed structure will have a memory footprint that could scale up to 10 times the string size.

Re: Oh, XML

2008-04-30 10:43 • by Anonymous (unregistered)
192301 in reply to 192292
Physics Phil:
I may be missing the sarcasm here

Yes.

Re: Oh, XML

2008-04-30 10:46 • by xmlicious (unregistered)
XML is like violence: if it doesn't solve your problem, you're not using enough of it.

Re: Oh, XML

2008-04-30 11:02 • by DropDeadThread
This isn't retarded enough for my taste. How about:

<image>
<pixel>
<row>0</row>
<col>0</col>
<color>#CF00D9</color>
</pixel>
...
<pixel>
<row>999</row>
<col>99</col>
<color>#00FF00</color>
</pixel>
</image>

That's more like it!

Re: Oh, XML

2008-04-30 11:09 • by larry (unregistered)
BTW, it's from -128 to 127 in two's complement systems, and that's usually how you see bytes signed unless they did something for extra weirdness. </dweeb>

Re: Oh, XML

2008-04-30 11:12 • by punissuer
192315 in reply to 192260
cthulhu:
<pixel>Reddish</pixel>
You make me smile.

Java bytes

2008-04-30 11:20 • by Steve (unregistered)
Regarding the 0 - 255 vs -128 - 127 conundrum, I've been programming in Java seriously for about five or six years (after about 15 or so years in C, starting with classic K&R and progressing to ANSI C when it became prevalent) and like the language a lot.

But since I have to deal with raw image data (and I mean RAW, as it comes off imaging devices in some strange format only an engineer could love), the designer's choice to not include unsigned data types, particularly unsigned byte, makes me want to scream sometimes.

I've never understood why that was necessary.

As for the XML, I'm afraid some of my early efforts looked like that.

I'm better now.

Slightly.

Re: Oh, XML

2008-04-30 12:11 • by Anon (unregistered)
192336 in reply to 192292
Physics Phil:
luptatum:

Tobias:
ut more probably it is done by String-concatenation with "+" for performance reasons (Don't have to instantiate this crappy StringBuilder etc) ...

heh as you said, the real wtf for the people who write this crap is this string builder waste of programming cycles you write about...

I may be missing the sarcasm here, but using + for String concatenation in Java is just a shorthand for creating a new StringBuilder, combining all the strings in the line, and then returning the resulting String. This means that at best, with excellent compiler optimisation, you would get the same performance as using StringBuilder manually, and most likely the performance would be worse. In my copious free time I may get around to testing this, but I doubt I will have time in the near future.


Oh dear.

Java (and .Net) Strings are immutable.

If you are using
s += "new string";
in a loop you aren't appending to an existing String, you are creating a new String each time, leaving behind a bunch of unreachable Strings to be garbage collected.

String s = "";

for (int i = 0; i < 100; ++i) {
s += "xx";
}


The above code creates 100 String objects... the first contains "", the second contains "xx", the third contains "xxxx", etc. Of those, the only String that remains reachable after the loop completes is the String object containing 200 'x' characters. The above loop has created String objects containing 9900 characters, none of which are reachable when the loop ends, all of which have to be garbage collected.

StringBuilder sb = new StringBuilder("");

for (int i = 0; i < 100; ++i) {
sb.append("xx");
}
Strings s = sb.toString();


The above code on the other hand creates a single StringBuilder which contains 200 characters to be garbage collected.

Obviously a loop of 100 iterations appending two characters isn't that big a deal, but try a loop of 1000 iterations appending four characters... 1998000 characters in 1000 unreachable Strings have to be garbage collected.

I can't believe this had to actually be explained to anyone.

Explained again at http://java.sun.com/developer/JDCTechTips/2002/tt0305.html

Re: Oh, XML

2008-04-30 12:15 • by vt_mruhlin
192338 in reply to 192312
DropDeadThread:
This isn't retarded enough for my taste. How about:

<image>
<pixel>
<row>0</row>
<col>0</col>
<color>#CF00D9</color>
</pixel>
...
<pixel>
<row>999</row>
<col>99</col>
<color>#00FF00</color>
</pixel>
</image>

That's more like it!


Not so fast there chief. What if we want to use a greater color depth in the future? And how will a human reading this know whether the rows and columns are measured from the top left, bottom left, etc? What if we want to make it 3D?


<pixel>
<euclideanCoordinates>
<origin>center</origin>
<row>-150</row>
<col>-300</col>
<z>0</z>
</euclideanCoordinates>
<color>
<red>0x00</red>
<green>0xFF</green>
<blue>0x00</blue>
</color>
</pixel>
<pixel>
<polarCoordinates>
<degrees>90</degrees>
<dist>4</dist>
</polarCoordinates>
<color>
<red>0x0000</red>
<green>0x0000</green>
<blue>0xFF00</blue>
</color>
</pixel>


Now that's an Enterprise Business Solution.

Re: Oh, XML

2008-04-30 12:18 • by NaN (unregistered)
192339 in reply to 192274
Outlaw Programmer:
The Real WTF is only hinted at here. The fix was, of course, to write a "BytesConverter class" that parses the XML, adds 128 to each element, then writes it back into XML to be consumed by the client.


The Real WTF is that there are programmers who do not know about two's complement.

Re: Oh, XML

2008-04-30 12:46 • by mister (unregistered)
192348 in reply to 192338
vt_mruhlin:
Not so fast there chief. What if we want to use a greater color depth in the future? And how will a human reading this know whether the rows and columns are measured from the top left, bottom left, etc? What if we want to make it 3D?
---snip---
Now that's an Enterprise Business Solution.

What? And limit yourself to rgb colors? No transparency?
This is how it should be done:


<pixel>
<euclideanCoordinates>
<origin>top-left</origin>
<row>-150</row>
<col>-300</col>
<z>0</z>
</euclideanCoordinates>
<rgbColor>
<red>0x00</red>
<green>0xFF</green>
<blue>0x00</blue>
<alpha>1.0</alpha>
</rgbColor>
</pixel>
<pixel>
<polarCoordinates>
<origin>center</origin>
<degrees>90</degrees>
<dist>4</dist>
<z>0</z>
</polarCoordinates>
<cmykColor>
<cyan>0x0000</cyan>
<magenta>0x0000</magenta>
<yellow>0xFF00</yellow>
<black>0x00FF</black>
<alpha>0.5</alpha>
</cmykColor>
</pixel>
<pixel>
<sphericalCoordinates>
<origin>bottom-right</origin>
<zenith>60</zenith>
<azimuth>30</azimuth>
<dist>5</dist>
<z>2</z>
</sphericalCoordinates>
<rybColor>
<red>0xFFFF</red>
<yellow>0x0000</yellow>
<blue>0x00FF</blue>
<alpha>0.75</alpha>
</rybColor>
</pixel>

Re: Oh, XML

2008-04-30 12:50 • by t saint (unregistered)
This looks to me like the provider was using Apache Axis or some similar toolkit.
IIR the Axis implementation does this with byte arrays if you use the wrapped style. Thing is that if you use the RPC style then multirefs are implemented which some security appliances don't really like.
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment