- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
The real WTF is that it is -128 to +127.
Admin
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!
Admin
It is puzzling how an attachment (image, in this case) could be -45 bytes long. Does it 'leech' data from other files around it?
Admin
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!
Admin
The wording of this was kinda funny. Overdesign a bit ! You must be using 3 way bits :)
Admin
So much for enterprisey software, it can't even do data validation on the XML !
Admin
Admin
Image data! Wtf?
Admin
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?
Admin
He said it was enterprisy didn't he...
Admin
Oh... My... God... Really looks that way! :|
Admin
Try saving as BMP uncompressed. THAT is ridiculous.
Admin
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?'
Admin
Hopefully the xml is gzipped on-the-fly. We can only hope.
Admin
The real WTF is that the <bytes> tag only contains a single byte....it should be <byte>. </rants>
Admin
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!
Admin
Two's complement is not a joke.
Admin
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!!
Admin
Admin
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.
Admin
I bet somewhere deep in the code there is a loop over all the bytes of the image data that looks like this:
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
Admin
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...
Admin
Admin
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!
Admin
The real WTF is that it appears a byte is stored in an element called "bytes"... :-/
There are [code][/code] tags, but they add extra line breaks...Admin
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....
Admin
Admin
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...
Admin
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.
Admin
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.
Admin
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.
Admin
Oh I love the redundancy of that one!
Admin
Admin
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>Admin
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.
Admin
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...
Admin
I am thoroughly inspired. This may have to become a side proejct for me.
Admin
Addendum (2008-04-30 10:47):
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)
Admin
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.
Admin
Admin
XML is like violence: if it doesn't solve your problem, you're not using enough of it.
Admin
This isn't retarded enough for my taste. How about:
That's more like it!
Admin
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>
Admin
Admin
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.
Admin
Oh dear.
Java (and .Net) Strings are immutable.
If you are using
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.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.
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
Admin
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?
Now that's an Enterprise Business Solution.
Admin
The Real WTF is that there are programmers who do not know about two's complement.
Admin
Admin
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.