• Soft Drink Empire (unregistered) in reply to Waratah

    Cool infinite loop, bro.

  • (cs)

    "When I looked at the two example files, everything was at the same place in both files, so rather than use a long winded method to parse the file I think it would be quicker to write code that just grabbed the needed parts directly from the file. After all, the positions in the file are hardly likely to change and the documentation will also state that they should never change. "

    :-)

  • one in the gray mass (unregistered)

    Who did make You the Gods of coding? No one borns knowing everything, the things are learnt through practice usually. What would be Your actions if You were asked to (1) perform a brain surgery on an open road having all the tools needed, or (2) simply make a fire in a wood having no matches, no lighter, no nothing, only wood?

    I'm not saying that the code is bad (although it can be different). But what rights do You have to blame someone for writing such code?

    Personally, I think XML and all the 'tagged' pseudo languages are unnecessary, usually or even in all the cases there is better data format for that specific problem. But current trends force You to use XML and it's parsers everywhere and everytime You have to store or retrieve data - even if it's only a few characters. The tags itself take up more space than the actual data. See the XML for Yourself.

  • jay (unregistered)

    I can't help but wonder if someone told the programmer, "XML is the latest and greatest thing! We must use XML for all future data storage and interchange!" And the programmer said, "Umm, okay. Can you give me an example of one of these XML files? Oh, I see. Okay, I can create a file that looks like that and read it back, sure." And never bothered to ask why he was doing this or what the advantage was supposed to be, nevermind how to do it right.

  • AndyL (unregistered) in reply to one in the gray mass
    one in the gray mass:
    You were asked to (1) perform a brain surgery on an open road having all the tools needed,
    Asking an unqualified person to perform brain surgery is a WTF in and of itself.
    (2) simply make a fire in a wood having no matches, no lighter, no nothing, only wood?
    I would make a bow drill. They're difficult to use, but not impossible. Probably your best bet for unskilled fire-making.
  • Harrow (unregistered)

    Probably the project originally had a perfectly adequate import method using fixed-length fields.

    Then XML was invented, and since no IT manager on the planet knows what the hell it is for, they all decided to use it for everything. So, the export format was changed to XML to make it better. Because it's, you know, better. So, the techs wrote the XML export function, then tweaked it to make the data columns line up reliably to minimize the impact on the already working import code.

    But they didn't document it, because a manager might read the documentation, and discover the ruse.

    -Harrow.

  • (cs) in reply to one in the gray mass
    one in the gray mass:
    What would be Your actions if You were asked to (1) perform a brain surgery on an open road having all the tools needed
    Well, first I would make sure the open road was properly anesthetized...
  • Harrow (unregistered) in reply to one in the gray mass
    one in the gray mass:
    ...What would be Your actions if You were asked to ... perform a brain surgery on an open road...
    The surgery itself is usually quite straightforward, requiring only that you patiently follow the instructions in the manual, skipping no steps. The really difficult part, which stymies most amateurs, is locating the road's brain.

    -Harrow.

  • (cs) in reply to one in the gray mass
    one in the gray mass:
    Who did make You the Gods of coding? No one borns knowing everything, the things are learnt through practice usually. What would be Your actions if You were asked to (1) perform a brain surgery on an open road having all the tools needed, or (2) simply make a fire in a wood having no matches, no lighter, no nothing, only wood?

    I'm not saying that the code is bad (although it can be different). But what rights do You have to blame someone for writing such code?

    Personally, I think XML and all the 'tagged' pseudo languages are unnecessary, usually or even in all the cases there is better data format for that specific problem. But current trends force You to use XML and it's parsers everywhere and everytime You have to store or retrieve data - even if it's only a few characters. The tags itself take up more space than the actual data. See the XML for Yourself.

    Please don't make excuses for that code, or the lack of thought/ignorance which produced it. Second, don't trot out some "XML is always bad" strawman based on your anecdotal experience. (Yes, I have seen XML files in which the tags themselves are a relatively small proportion of the total "characters" in the file.)

    The guy is tasked with reading in XML data, and is either too stupid or too ignorant to take advantage of XML's fundamental qualities. He's treating that file as if it's a fixed length record type of thing, which it most certainly isn't. In short, he's banking that neither the length of the tags or the length of the data will EVER CHANGE. Throw out the XML and can't you see how that would be a terrible idea for almost any type of data storage format?

    What this guy is doing is essentially the same thing as creating an ASCII dump of a relational DB, hoping that the output is always the same, and parsing through the dump as a text file in order to match up DB records based on column position of the data he needs. You might think that's a stupid example, but I have personally seen someone do just that. It was every bit as screwed up as what this guy is doing, and he got schooled. As this guy should be.

    There's no need for "Rights". He's using a hammer to drive in a screw, and should have his tools taken away until he knows what each one is for.

  • TW Andrews (unregistered)

    At least the decision here between altering within a bad structure vs. reimplementing correctly is not a tough one.

  • Anon (unregistered) in reply to one in the gray mass

    [quote user="one in the gray mass" What would be Your actions if You were asked to (1) perform a brain surgery on an open road having all the tools needed[/quote]

    This is why unqualified people aren't asked to do brain surgery. This is also why unqualified people shouldn't be asked to write code and why you shouldn't be asked to write analogies.

  • Gregoire (unregistered)

    It's simple. XML is Chinese for WTF.

  • Someone else (unregistered) in reply to AndyL
    AndyL:
    one in the gray mass:
    You were asked to (1) perform a brain surgery on an open road having all the tools needed,
    Asking an unqualified person to perform brain surgery is a WTF in and of itself.
    (2) simply make a fire in a wood having no matches, no lighter, no nothing, only wood?
    I would make a bow drill. They're difficult to use, but not impossible. Probably your best bet for unskilled fire-making.

    What would you do if someone asked you a rhetorical question?

  • (cs) in reply to Someone else
    Someone else:
    What would you do if someone asked you a rhetorical question?
    Give a rhetorical answer.
  • bob (unregistered)

    Jebus, what a bunch of obnoxious, arrogant dweebs you all appear to be.

  • Hoodaticus (unregistered)

    someone should tell them that XML, like Saxon or DOM, wasn't invented there either.

  • jmucchiello (unregistered) in reply to lolwtf
    lolwtf:
    "<comment>WTF!?</comment>".substr(9, 5)
    OzPeter:
    fw:
    Dan:
    It's not even a WTF. It's an FTW. Fire-That-Wannabe.

    W*nker more like

    WTF? who did you think you were going to offend by leaving out the "a"? And given a choice of 5 potential vowels to insert, how stupid do you think people have to be to not find the correct vowel?

    I'm sure he meant winker. Someone who winks.

    Well you can't keep a winker on staff. Eventually he'll wink at the wrong person and your company ends up caught in a sexual harassment suit.

  • (cs) in reply to bob
    bob:
    Jebus, what a bunch of obnoxious, arrogant dweebs you all appear to be.
    Endeavor to persevere.
  • @Deprecated (unregistered) in reply to one in the gray mass
    one in the gray mass:
    Who did make You the Gods of coding? No one borns knowing everything, the things are learnt through practice usually. What would be Your actions if You were asked to (1) perform a brain surgery on an open road having all the tools needed, or (2) simply make a fire in a wood having no matches, no lighter, no nothing, only wood?

    I'm not saying that the code is bad (although it can be different). But what rights do You have to blame someone for writing such code?

    Personally, I think XML and all the 'tagged' pseudo languages are unnecessary, usually or even in all the cases there is better data format for that specific problem. But current trends force You to use XML and it's parsers everywhere and everytime You have to store or retrieve data - even if it's only a few characters. The tags itself take up more space than the actual data. See the XML for Yourself.

    We were not asked to perform brain surgery, or to start a fire using only wood... we were asked to analyze a function to read an XML file... and if you have even the slightest glimmer of knowledge about XML you would realize OH MY GOD MAKE IT STOP OW OW OWOWOWOW Bluuuuuurgh....

  • Hoodaticus (unregistered) in reply to bob
    bob:
    Jebus, what a bunch of obnoxious, arrogant dweebs you all appear to be.
    Did we insult your kode or something? Do YOU parse XML with nothing but wood as well?

    CAPTCHA: plaga - a disease-infested beach

  • bob (unregistered) in reply to Hoodaticus
    Hoodaticus:
    bob:
    Jebus, what a bunch of obnoxious, arrogant dweebs you all appear to be.
    Did we insult your kode or something? Do YOU parse XML with nothing but wood as well?

    CAPTCHA: plaga - a disease-infested beach

    nope, i don't even work in this profession, just thought it needed saying.

  • Anon (unregistered) in reply to one in the gray mass
    one in the gray mass:
    (1) perform a brain surgery on an open road having all the tools needed, or

    Refuse to and find someone actually qualified to do it? Not a brain surgeon or a murderer so not much good I can do by cutting someone’s head open. It’s an amazing concept don’t you think? Refusing to do thing you’re not qualified for and that you’d likely just cause a bigger mess by trying.

    one in the gray mass:
    (2) simply make a fire in a wood having no matches, no lighter, no nothing, only wood?

    See above, granted in this case I’d of course try if my life depended on it.

    In general I don’t see ignorance as anything more than an excuse. Have I written atrocious code due to ignorance? Yes. Do I think of myself as an idiot in retrospect for not looking into the problem more so I can write proper code? Yes. Do I try to learn from those mistakes and not repeat them in the future? Yes.

    There’s little point in excuses other than to cripple my own future growth and improvement. Likewise I try to avoid getting in situations where I’m doing more damage than good. My ego isn’t such a fragile little thing that acknowledging my own deficiencies would cause me to fall into a decades long depression.

  • Hoodaticus (unregistered) in reply to bob
    bob:
    Hoodaticus:
    bob:
    Jebus, what a bunch of obnoxious, arrogant dweebs you all appear to be.
    Did we insult your kode or something? Do YOU parse XML with nothing but wood as well?

    CAPTCHA: plaga - a disease-infested beach

    nope, i don't even work in this profession, just thought it needed saying.

    We're not arrogant. We all really can write much better code than the sample. I did just six hours ago.

    This site is the America's Funniest Home Videos of code. Excuuuuse us for laughing.

  • (cs) in reply to bob
    bob:
    Hoodaticus:
    bob:
    Jebus, what a bunch of obnoxious, arrogant dweebs you all appear to be.
    Did we insult your kode or something? Do YOU parse XML with nothing but wood as well?

    CAPTCHA: plaga - a disease-infested beach

    nope, i don't even work in this profession, just thought it needed saying.
    Always a good idea to talk down on things you know nothing about. That way you never know how ignorant you sound.

    Brain surgery for amateurs

  • An Oni Moose (unregistered) in reply to bob

    You must be new here.

  • An Oni Moose (unregistered) in reply to An Oni Moose
    An Oni Moose:
    You must be new here.

    Oops, looks like I must be new here, too.

  • netjeff (unregistered) in reply to Code Dependent
    Code Dependent:
    Someone else:
    What would you do if someone asked you a rhetorical question?
    Give a rhetorical answer.

    My favorite of these type:

    If I were to ask you this question, what would your answer be?

  • greginnj (unregistered) in reply to @Deprecated
    @Deprecated:
    one in the gray mass:
    Who did make You the Gods of coding? No one borns knowing everything, the things are learnt through practice usually. [...]

    Personally, I think XML and all the 'tagged' pseudo languages are unnecessary[...] The tags itself take up more space than the actual data. See the XML for Yourself.

    [...] if you have even the slightest glimmer of knowledge about XML you would realize OH MY GOD MAKE IT STOP OW OW OWOWOWOW Bluuuuuurgh....

    Has anyone considered the possibility that "one in the gray mass" is trolling? Seems pretty obvious to me...

  • AshG (unregistered) in reply to lolwtf
    lolwtf:
    I'm sure he meant winker. Someone who winks.
    What made you so suer he didn't mean wenker? Someone who wenks?
  • (cs) in reply to netjeff
    netjeff:
    Code Dependent:
    Someone else:
    What would you do if someone asked you a rhetorical question?
    Give a rhetorical answer.
    My favorite of these type:

    If I were to ask you this question, what would your answer be?

    A former acquaintance of mine (not to be confused with "friend") liked to ask people... particularly those in altered states... "What color is this question?"

    When he tried it on me, my immediate answer was, "Red."

  • (cs) in reply to Ouch!
    Ouch!:
    So their database is an ASCII text file? Run, Forest, run!

    You missed your chance! You could have typed Run, First, run! :P

  • titter.com (unregistered) in reply to Calm Mint

    I propose that from now on, XML used in this context should stand for Excruciatingly Malformed Litter.

  • Hoodaticus (unregistered) in reply to titter.com
    titter.com:
    I propose that from now on, XML used in this context should stand for Excruciatingly Malformed Litter.

    Change the "e" word back to extensible and I think it's perfect!

  • Jordan (unregistered)

    This is some truly inspired foolishness. I mean, who would even think of doing it this way, much less actually going so far as to implement it?

  • T. Oataly Madeup (unregistered) in reply to one in the gray mass
    one in the gray mass:
    Who did make You the Gods of coding? No one borns knowing everything, the things are learnt through practice usually. What would be Your actions if You were asked to (1) perform a brain surgery on an open road having all the tools needed, or (2) simply make a fire in a wood having no matches, no lighter, no nothing, only wood?

    I'm not saying that the code is bad (although it can be different). But what rights do You have to blame someone for writing such code?

    Personally, I think XML and all the 'tagged' pseudo languages are unnecessary, usually or even in all the cases there is better data format for that specific problem. But current trends force You to use XML and it's parsers everywhere and everytime You have to store or retrieve data - even if it's only a few characters. The tags itself take up more space than the actual data. See the XML for Yourself.

    You've got an excellent point! Just the other day I was strolling on the open road, and someone ran up to me with a Macbook. He was screaming incoherent jibberish and we walked to a Starbucks. After I dosed the Apple fanboy with a latte, he calmed down a little (well, maybe he didn't calm down that much), but at least he was speaking something that resembled English.

    He insisted that we walk back to the point where we met, and that I write an XML parser by hand, right there on the open road, even though I've never used a computer in my life. I told him I'd give it my best shot, if he employed me to work for him full-time + benefits and make my official job title "Software Engineer V".

    He negotiated for "Programmer V" and shitty dental, and I agreed.

    Thus an XML parser you've never heard of was born. Hell, I'm a Programmer V .. what right do you have to criticize my parser, you arrogant bastards!?!

  • Jordan (unregistered)

    The funniest thing is wondering what went through the original programmer's head. In my mind, she sat down, opened the XML file, thought "hmm, it's a text file with the values stuck between these fixed-length strings, I could parse this using substrings" and straight away got down to counting characters. Or maybe looking up how to get substrings, then counting stuff. And, when she finished, she sat down and thought, "wow, I'm such a good programmer! That was pretty complicated!"

    The next bit of fun is trying to imagine what I'd do if I got there in time to stop her from doing this bad, bad thing. Or maybe immediately afterwards. I like to imagine that her eyes would pop and she'd become a passionate XML advocate, instead of wondering why they didn't just use a CSV.

  • Hoodaticus (unregistered) in reply to Jordan
    Jordan:
    The funniest thing is wondering what went through the original programmer's head. In my mind, she sat down, opened the XML file, thought "hmm, it's a text file with the values stuck between these fixed-length strings, I could parse this using substrings" and straight away got down to counting characters. Or maybe looking up how to get substrings, then counting stuff. And, when she finished, she sat down and thought, "wow, I'm such a good programmer! That was pretty complicated!"

    The next bit of fun is trying to imagine what I'd do if I got there in time to stop her from doing this bad, bad thing. Or maybe immediately afterwards. I like to imagine that her eyes would pop and she'd become a passionate XML advocate, instead of wondering why they didn't just use a CSV.

    Deserves to be the featured comment.

  • riskreward (unregistered)

    I've done this sort of thing, and I'd do it again. In the right situation. The right situation, means I own the producer and the primary consumer. Secondary consumers can parse the xml, but the primary parses the lines.

  • AshG (unregistered) in reply to Jordan
    Jordan:
    The funniest thing is wondering what went through the original programmer's head. In my mind, she sat down, opened the XML file, thought "hmm, it's a text file with the values stuck between these fixed-length strings, I could parse this using substrings" and straight away got down to counting characters. Or maybe looking up how to get substrings, then counting stuff. And, when she finished, she sat down and thought, "wow, I'm such a good programmer! That was pretty complicated!"

    The next bit of fun is trying to imagine what I'd do if I got there in time to stop her from doing this bad, bad thing. Or maybe immediately afterwards. I like to imagine that her eyes would pop and she'd become a passionate XML advocate, instead of wondering why they didn't just use a CSV.

    I wonder, how did she open the XML in the first place? By double-clicking on it, which had brought up the default application (IE)? IE as we all know does not show every byte of the original XML. It would show "<node></node>" as just "<node />". So she would be sitting there counting characters, and the result would be totally useless.

    My guess is, someone was advanced enough to know to use Notepad for actual file content. Or maybe her supervisor, after she ran to him hollering that the "parser" wouldn't work, pointed out at the error with using IE. Then no thought had occured to the supervisor, like, 'heck, WTF is she having problems with?' No proper code review had followed the incident. But profit was made, so who cares...

  • (cs)

    Reminds me of my last project... Fortunately I fixed the code before it went into production, but my coworker tried to parse some xml.

    He used the xml doc object module. Got a list of children and said "size = node.child[0].value" and "type = node.child[1].value." Sort of completely ignoring the names, and just hoping that they would also be generated in the same order (and that the parser returns them in the order generated)

  • (cs) in reply to riskreward
    riskreward:
    I've done this sort of thing, and I'd do it again. In the right situation. The right situation, means I own the producer and the primary consumer. Secondary consumers can parse the xml, but the primary parses the lines.

    There was a time when I would have agreed with you. But how long will you own both the producer and the consumer? What happens a year from now when you leave and one person takes over the producer and someone else takes over the consumer?

    Or when someone decides to add a bunch of stuff to the XML? Now you have to rewrite BOTH the producer and the consumer, instead of just the producer.

  • (cs) in reply to bob
    bob:
    Hoodaticus:
    bob:
    Jebus, what a bunch of obnoxious, arrogant dweebs you all appear to be.
    Did we insult your kode or something? Do YOU parse XML with nothing but wood as well?

    nope, i don't even work in this profession, just thought it needed saying.

    This explains your lack of understanding. Please allow me to translate the WTF at the top into your esteemed profession.

    A customer places an order. Your colleague asks "would you like fries with that" and upon an affirmative response sets the customer alight in several places.

  • iToad (unregistered)

    The trick is to specify the use of -very- well-formed XML instead of regular well-formed XML. With plain-vanilla well-formed XML, you have to use one of those elaborate and complicated DOM or SAX parsers. By specifying the use of -very- well-formed XML, you can parse using much simpler and faster substring extraction.

    Has this idea been patented yet?

  • darren (unregistered)

    Anyone who is thinking who ask themselves two questions 1. What is this XML all about and 2. Surely there is easier way to extract the data. From there they would discover all the joys of XML. Obviously someone wasn't thinking.

  • JayC (unregistered) in reply to one in the gray mass
    one in the gray mass:
    Who did make You the Gods of coding? No one borns knowing everything, the things are learnt through practice usually. What would be Your actions if You were asked to (1) perform a brain surgery on an open road having all the tools needed, or (2) simply make a fire in a wood having no matches, no lighter, no nothing, only wood?

    I'm not saying that the code is bad (although it can be different). But what rights do You have to blame someone for writing such code?

    Personally, I think XML and all the 'tagged' pseudo languages are unnecessary, usually or even in all the cases there is better data format for that specific problem. But current trends force You to use XML and it's parsers everywhere and everytime You have to store or retrieve data - even if it's only a few characters. The tags itself take up more space than the actual data. See the XML for Yourself.

    Of course it's unnessesary. XML is for humans, with lots of little redundacies so that we can understand the semantics. Also, with a universal parser and various query tools, you can do so many things only dreamable (practically), unless you have readily available parse tree representation of the dialect of your choice.

    The choice to "parse" XML this way is inexcusable. This is not parsing. There are no sanity checks. XML need not have to create a DOM to be parsed. A low level XML parser should be highly efficient and yet still recognize bogus data. With this WTF, unless one knew the nonsense going on behind the scenes, all matter of erroneous matters could occurr, and you woud quite possibly never know. After all, most people would assume that no data representation problems would occur in changing a value of an attribute or a node of freaking XML document! If you are going to use a fixed width data representation, don't dress your data as something it isn't.

  • Kermit (unregistered) in reply to Hoodaticus
    Hoodaticus:
    Do YOU parse XML with nothing but wood as well?
    Is this what porn site developers do?
  • (cs) in reply to AdT
    AdT:
    for (pInput = pInputBuffer, pOutput = pOutputBuffer, szRemainingBytes = szBytesToCopy;
         szRemainingBytes; *pOutput++ = *pInput++, --szRemainingBytes);
    until a University tutor pointed out that for loops were invented to make code more readable.
    That's a bit wasteful.. why not post-decrement the remaining bytes in the comparison clause? Did you really prefix counters with "sz"?
  • Lee K-T (unregistered) in reply to chrismcb
    chrismcb:
    Reminds me of my last project... Fortunately I fixed the code before it went into production, but my coworker tried to parse some xml.

    He used the xml doc object module. Got a list of children and said "size = node.child[0].value" and "type = node.child[1].value." Sort of completely ignoring the names, and just hoping that they would also be generated in the same order (and that the parser returns them in the order generated)

    Reminds me of my current project. But it's not the guy's fault... it's because we didn't specify that the caller might not always send the same xml file with the exact same values...

    And anyway, he explained that the parser was bugged. Sometimes for empty values the output was malformed. Something like "<elem/>" instead of "<elem></elem>". Gosh, how come these java guys never noticed that bug!?! lol...

  • Steve the Cynic (unregistered) in reply to AndyL
    AndyL:
    one in the gray mass:
    You were asked to (1) perform a brain surgery on an open road having all the tools needed,
    Asking an unqualified person to perform brain surgery is a WTF in and of itself.
    (2) simply make a fire in a wood having no matches, no lighter, no nothing, only wood?
    I would make a bow drill. They're difficult to use, but not impossible. Probably your best bet for unskilled fire-making.

    But you don't have any string, rawhide cord, etc. You just have wood. Um, er, let me rephrase that. You just have pieces of wood.

  • amet (unregistered) in reply to bob
    bob:
    Hoodaticus:
    bob:
    Jebus, what a bunch of obnoxious, arrogant dweebs you all appear to be.
    Did we insult your kode or something? Do YOU parse XML with nothing but wood as well?

    CAPTCHA: plaga - a disease-infested beach

    nope, i don't even work in this profession, just thought it needed saying.

    That is what happens when you have people that are proud of their line of work see what some scrub managed to barely get working. In a very ugly and bad way.

    Some things deserve to be hung out for public ridicule. This is one of them.

Leave a comment on “What Could Be Easier Than XML?”

Log In or post as a guest

Replying to comment #:

« Return to Article