• ais523 (unregistered)

    So they're creating a node using the library, and then extracting the text that they just added from it with string manipulation functions, so they end up with the escaped version? That's actually a reasonable solution to the problem (maybe not the best, but reasonable), it's just that the problem should never have existed in the first place.

    By the way, how come when I click on 'preview', my CAPTCHA gives back the same word but with a different test image next to it?

  • Sunstorm (unregistered)

    So, use a DOM to avoid using a DOM. Makes perfect sense!

  • (cs)

    This must be testing code because it seems too off to really work in practice. On an added plus, it puts built in exception handling right into the parsed xml, how cool <sarcasm/> is that ! Although the code doesn't really seem to match the article too well, or the comments. You expected some string parsing or something, but it still used the DOM. Obviously, they don't know about the built in xml serialization features yet.

  • MrWibble (unregistered)

    Oh god. I felt a little bit of my brain dribble out of my ear after reading that code. It's incredible how much damage they managed to do in such a few lines of code.

  • Stiggy (unregistered)

    The Real WTF is that no-one has yet chimed in with, "The Real WTF is using VB". Because that would be funny. </sarcasm>

  • Chris (unregistered)

    It looks like they were using DOM before, judging by the comments. I've found the DOM API in Java to be a real resource hog, and I'd expect it to be the same in any implementation. However, that's not a good reason to go off and write some half arsed replacement when there's a lot of simpler XML API's - for instance, SAX is often a better choice than navigating a DOM tree, especially if your XML is quite "flat" (in other words, elements don't nest deeply).

    (Captcha "appellatio" - is that where you suck off an apple?)

  • foo (unregistered)

    This is why all the good coding jobs are going to India.

  • NeoMojo (unregistered)

    I agreed with the first comment about this being a good way to escape a string for XML, but then I looked on google and found this page which does the job in one line.

  • magi (unregistered)

    The real WTF is that the helmet-wearing VB clowns are defending their language before anyone has a chance to criticize it.

  • A. Coder (unregistered)

    That looks like something that my last company would have produced.

    They manually parsed all XML rather than using the DOM / Serializing the damn thing. Then disciplined me for trying to use XML Serialization.

  • Walter (unregistered) in reply to ais523

    The real WTF:

    Catch ex As Exception Return ex.ToString
  • Stephen (unregistered)

    I agree with them, the .NET one is far too functional, so in our library we parse text by entering the string values into an efficient queue system where we email the incoming values to the most efficient available technie.. he gets given a parse session ticket that he logs back into our bespoke administration system and enters the validated/normalized result back to the system..

    We find that the parsing does take a little longer than the .NET version, but it does allow us to normalize badly formed XML..

    We've got patents on this so don't any of you cowboys even think about ripping us off!

  • Ezrec Nebarb (unregistered)

    Yeah, but what really gets me is the fact that their comments are in XMLish. Weird. What advantage does that give you?

  • Anonymous (unregistered)

    The real WTF is that they're using VB.

  • (cs)

    Maybe the reason they have their own string manipulation is that they don't (or didn't when the system was first created) know how to use the ".NET Fancy stuff"... I've been guilty of that myself in the past, when I had to grab data from a basic xml file, had no time to spend on it, and already had a working string parsing function. So I just used that "for the time being", and never upgraded it. Yes I'm lazy (but hey I'm a programmer, isn't the reason that we do what we do because we're too lazy to do a certain activity manually 1000 times over?). In my defense, it's a program that only I use to speed up my workload and not a final product being sold / used by anyone else.

  • Roman (unregistered)

    I'm too sexy for this code, too sexy for this fancy code, oh yeah.

  • Walleye (unregistered) in reply to Ezrec Nebarb
    Ezrec Nebarb:
    Yeah, but what really gets me is the fact that their comments are in XMLish. Weird. What advantage does that give you?

    Using this style of comments give Visual Studio the ability to generate documentation for your classes.

  • Stu (unregistered) in reply to magi

    lol, what a funny image... halfarsed clowns running into each other because their helmets are on backwards!

  • Bosshog (unregistered) in reply to Claxon
    Claxon:
    In my defense, it's a program that only I use to speed up my workload and not a final product being sold / used by anyone else.

    Wow, that sounds great - can I buy it off you? :)

  • Greg D (unregistered)

    For a moment I thought that this might have come from someone else in my own workplace. Then I noticed that the article said they used "StringBuilders". Hah! The guy who wrote the project I inherited saw StringBuilders for what they are, silly extra letters invented to give you carpal tunnel 2 years sooner! Why use a StringBuilder when you can just concatenate all those yummy immutable strings?

    What? You say that it's less efficient? Well, alright then. How about this- we still use strings, but we break down the XML into all of its constituent syntactical elements and concatenate each of those separately? Why say something like:

    Dim SomeXml As String = "<foo>" + SomeText + "</foo>"

    when you can say something like:

    Dim SomeXml As String = "<" + "foo" + ">" + """" + "" + SomeText + """" + "" + "<" + "/" + "foo" + ">";

    See? Now you're doing fewer allocations of immutable strings, so it's all okay! Right? Right?! All we need to do is right a few thousand more lines just like that one, and we'll be set!

    I really hate this guy.

  • Anonymous (unregistered) in reply to Stephen

    Its VB.NET, so the reason they ignored the built in libraries should be obvious.

    You get what you pay for.

  • 604 (unregistered) in reply to Stephen

    I've unfortunately done something similar but the incoming documents were anything from horrible word/pdf-generated html, malformed sgml/xml, with the goal of creating SGML/XML that conformed to some other dtd/schema.

  • Vroomfundel (unregistered) in reply to Stephen

    The real WTF here is that they did it in VB.NET. I don't believe someone would do stuff like that in C#.

    As Dijkstra said, "It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration".

  • bd (unregistered)

    We have a say here:

    They have discovered the hot water!

  • (cs)

    Wait I see the WTF

        Catch ex As Exception
            Return ex.ToString
        Finally
    
    

    Should be

    
        Catch ex As Exception
            Return "<error>" + ex.ToString() + "</error>"
        Finally
    

    otherwise if an error occured, we wouldn't get xml back.

  • (cs) in reply to Stiggy
    Stiggy:
    The Real WTF is that no-one has yet chimed in with, "The Real WTF is using VB". Because that would be funny. </sarcasm>

    TRWTF is using XML

  • (cs) in reply to pitchingchris
    pitchingchris:
    This must be testing code because it seems too off to really work in practice.
    No, it does work, really! Did you try it?
    pitchingchris:
    On an added plus, it puts built in exception handling right into the parsed xml, how cool <sarcasm/> is that !
    Wow, I want some of what you're smoking! Wrapping a try...except around the code that does the parsing doesn't in any way "put exception handling" into the results.
    pitchingchris:
    Although the code doesn't really seem to match the article too well, or the comments. You expected some string parsing or something, but it still used the DOM. Obviously, they don't know about the built in xml serialization features yet.
    Ah, I see what you're overlooking here; serialization doesn't interact with the DOM in the way you're thinking. Check out http://tinyurl.com/3datyd for a fuller explanation.
  • Konamiman (unregistered)

    In fact, VB and C# are themselves too fancy. I write my .NET code directly in MSIL. This really boost performance on my enterprise-ready applications.

  • Greg (unregistered) in reply to DaveK
    DaveK:
    Ah, I see what you're overlooking here; serialization doesn't interact with the DOM in the way you're thinking. Check out http://tinyurl.com/3datyd for a fuller explanation.
    Don't tell me you're too blind to see! You're trying to say that DOM never is going to give up and never is going to let us down, right? It's not going to run around and desert us? It won't make us cry, nor say goodbye, or tell a lie and hurt us.
  • JM (unregistered) in reply to Vroomfundel
    Vroomfundel:
    The real WTF here is that they did it in VB.NET. I don't believe someone would do stuff like that in C#.
    Wow... just wow. The fact that you could believe that shows a horribly misplaced faith in the abilities of C# programmers. If you believe C# programmers are necessarily smarter than VB.NET programmers, to the point where they would not make mistakes like this, then there's this lovely bridge I'd like to sell you.
    As Dijkstra said, "It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration".
    And as Flon said, "There does not now, nor will there ever, exist a programming language in which it is the least bit hard to write bad programs." You'll find that C# programmers do not have it any more difficult in this regard than programmers in any other language.
  • (cs) in reply to Grovesy

    I think my face just melted...

    Grovesy:
    Wait I see the WTF
        Catch ex As Exception
            Return ex.ToString
        Finally
    
    

    Should be

    
        Catch ex As Exception
            Return "<error>" + ex.ToString() + "</error>"
        Finally
    

    otherwise if an error occured, we wouldn't get xml back.

    Nice try, but what if your exception text contains XMl special chars?

    Obviously it should be

    Return "<error>" + ParseText(ex.ToString()) + "</error>"
    
  • Joon (unregistered) in reply to Bosshog

    Please send me teh codes

  • Bored at day job (unregistered)
    Finally dom = Nothing Node = Nothing End Try

    I see this all too often mistake in .NET. Explicitly destroying your objects in a finalizer prevents the optimizer from handing unneeded objects the Garbage Collector. The optimizer knows if you never call an object again, and allows the garbage collector to sweep it even when this function is still in operation. Using that name at the end of a function means that there is still a reference to this oject in the code, and won't touch it. This is of course only when the Assembly is compiled in Release mode. While in this method it might not be too much a problem, but functions with large loops, something like this can waste a lot of memory. This is often the habit of classic VB programmers that are ported to the .NET language. And a hard habt for them to break.

    The only time you need to do this is if the Documentation decalrs that you should manually clear the object due to some unmanaged resource that is allocated inside the object. And by today's version of the Frameworks, not many objects contain unmanaged resources that would require this.

  • Mark B (unregistered)

    I cant say I agree with them but it would seem like even MS thought it co do with an overhaul since there is now all the classes for Linq to Xml with XElement, XDocument etc replacing all of the XmlElement, XmlDocument etc.

  • SomeCoder (unregistered)

    Well, as someone who has suffered through using .NET for 4 years, I will say this: the .NET XML libraries really, really suck.

    That said, this code is NOT the answer. Eyes, goggles, do nothing.

  • lw42 (unregistered) in reply to Grovesy
    Grovesy:
    (...snip...) Should be
        Catch ex As Exception
            Return "<error>" + ex.ToString() + "</error>"
        Finally
    
    otherwise if an error occured, we wouldn't get xml back.
    Surely you mean
        Catch ex As Exception
            Return "<error>" + ParseText( ex.ToString() ) + "</error>"
        Finally
    
    After all, if you've got a tool to clean up strings for XML, why not use it?
  • Garbage man (unregistered)
    I see this all too often mistake in .NET. Explicitly destroying your objects in a finalizer prevents the optimizer from handing unneeded objects the Garbage Collector

    Gah! When will people learn how the garbage collector works?!

    This is not calling a finalizer it's simply setting the object refs to null so the objects are eligible for garbage collection.

    The fact that they drop out of scope on the next line and are eligible for collection anyway is TRWTF (aside from the willful abuse of the XML libraries of course)

  • (cs) in reply to Vroomfundel
    Vroomfundel:
    The real WTF here is that they did it in VB.NET. I don't believe someone would do stuff like that in C#.

    As Dijkstra said, "It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration".

    I hear this from conceited programmers all the time, and I wonder whether he was talking about modern, structured Basics or the old Microsoft BASICs that were understandably limited because they ran on systems with fewer than 16 KB of RAM. I, unfortunately, had to learn BASIC on a home computer because they didn't let 7 year olds use timesharing on mainframes, but I did learn how to do structured DEC BASIC programming later on in college. I even have a book from the late 1980s called, strangely enough, "Strictly Structured BASIC".

  • (cs) in reply to Garbage man
    Garbage man:
    I see this all too often mistake in .NET. Explicitly destroying your objects in a finalizer prevents the optimizer from handing unneeded objects the Garbage Collector

    Gah! When will people learn how the garbage collector works?!

    This is not calling a finalizer it's simply setting the object refs to null so the objects are eligible for garbage collection.

    The fact that they drop out of scope on the next line and are eligible for collection anyway is TRWTF (aside from the willful abuse of the XML libraries of course)

    thank god... someone beat me to it.. I was going to be less polite :)

    There are even some circumstances where setting an object ref to null is usefull (such as a long running function)

  • (cs) in reply to Grovesy
    Grovesy:
    Garbage man:
    I see this all too often mistake in .NET. Explicitly destroying your objects in a finalizer prevents the optimizer from handing unneeded objects the Garbage Collector

    Gah! When will people learn how the garbage collector works?!

    This is not calling a finalizer it's simply setting the object refs to null so the objects are eligible for garbage collection.

    The fact that they drop out of scope on the next line and are eligible for collection anyway is TRWTF (aside from the willful abuse of the XML libraries of course)

    thank god... someone beat me to it.. I was going to be less polite :)

    There are even some circumstances where setting an object ref to null is usefull (such as a long running function)

    I think that was just a typo and he meant to say "finally block."

    Then again, he's not destroying anything, just setting the references to null.

    Then again, why would you destroy the object in its finalizer when a finalizer gets called when the object is being destroyed?

    Eeeeehhh long story short: don't try to beat the garbage collector.

  • Some Programmer (unregistered) in reply to operagost
    operagost:
    Vroomfundel:
    As Dijkstra said, "It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration".
    I hear this from conceited programmers all the time, and I wonder whether he was talking about modern, structured Basics or the old Microsoft BASICs that were understandably limited because they ran on systems with fewer than 16 KB of RAM.

    I think Dijkstra's comment reflects a time when fewer people had a chance at computer exposure, much less programming exposure. His observation was that those exposed to BASIC were poor programmers. Given that software development is a challenging field even for smart people, Dijkstra was probably not too far off the mark; his comment was accurate, but not necessarily for the right reason.

    I think a better (modern) version of this would be "It is practically impossible to teach good programming to students that have no desire to move beyond BASIC: they cannot understand the limits they need to move beyond."

    I myself began programming in Microsost BASIC 2.0 on a Commodore 64. This worked out fine from Age 5 to 12; after that I taught myself 6502 assembly language out of necessity. Eighteen years later, I'm still searching for the ultimate language; haven't found it yet, and don't expect to find it in my lifetime.

  • Eric (unregistered)

    The first clue is the fact that it's in VB at all.

  • (cs) in reply to Outlaw Programmer
    Outlaw Programmer:
    Grovesy:
    Garbage man:
    I see this all too often mistake in .NET. Explicitly destroying your objects in a finalizer prevents the optimizer from handing unneeded objects the Garbage Collector

    Gah! When will people learn how the garbage collector works?!

    This is not calling a finalizer it's simply setting the object refs to null so the objects are eligible for garbage collection.

    The fact that they drop out of scope on the next line and are eligible for collection anyway is TRWTF (aside from the willful abuse of the XML libraries of course)

    thank god... someone beat me to it.. I was going to be less polite :)

    There are even some circumstances where setting an object ref to null is usefull (such as a long running function)

    I think that was just a typo and he meant to say "finally block."

    Then again, he's not destroying anything, just setting the references to null.

    Then again, why would you destroy the object in its finalizer when a finalizer gets called when the object is being destroyed?

    Eeeeehhh long story short: don't try to beat the garbage collector.

    Wait,, when the destroyer is destroying the thing that needs destroying, the subject tries to destroy the destroyer which is destroying the destroyer which is infact itself.

    My brain went all wobley there...

  • Freddoo (unregistered)

    I see ...

    the wtf is the use of VB.Net that's why VB programmers have bad reputations

  • (cs) in reply to Greg
    Greg:
    DaveK:
    Ah, I see what you're overlooking here; serialization doesn't interact with the DOM in the way you're thinking. Check out http://tinyurl.com/3datyd for a fuller explanation.
    Don't tell me you're too blind to see! You're trying to say that DOM never is going to give up and never is going to let us down, right? It's not going to run around and desert us? It won't make us cry, nor say goodbye, or tell a lie and hurt us.
    You wouldn't get that from any other guy!
  • jamspoon (unregistered) in reply to Grovesy

    The function doesn't return xml. It creates a string containing "<x>TextIn</x>" then chops off the xml tags and returns the result.

  • Stephen E. Baker (unregistered) in reply to Some Programmer
    Some Programmer:
    operagost:
    Vroomfundel:
    As Dijkstra said, "It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration".
    I hear this from conceited programmers all the time, and I wonder whether he was talking about modern, structured Basics or the old Microsoft BASICs that were understandably limited because they ran on systems with fewer than 16 KB of RAM.

    I think Dijkstra's comment reflects a time when fewer people had a chance at computer exposure, much less programming exposure. His observation was that those exposed to BASIC were poor programmers. Given that software development is a challenging field even for smart people, Dijkstra was probably not too far off the mark; his comment was accurate, but not necessarily for the right reason.

    I think a better (modern) version of this would be "It is practically impossible to teach good programming to students that have no desire to move beyond BASIC: they cannot understand the limits they need to move beyond."

    I myself began programming in Microsost BASIC 2.0 on a Commodore 64. This worked out fine from Age 5 to 12; after that I taught myself 6502 assembly language out of necessity. Eighteen years later, I'm still searching for the ultimate language; haven't found it yet, and don't expect to find it in my lifetime.

    I'm pretty sure Dijkstra was just full of himself, and didn't like BASIC - and wouldn't like C# either.

    "Object-oriented programming is an exceptionally bad idea which could only have originated in California" - Edsger Dijkstra

  • (cs)

    this guys clearly know nothing about .net...

    xx = nothing is deprecated! should be xx.dispose (if the object is disposable)...

    and using a mid, shows you that the code is vb6 migrated, or the guys know nothing about OOP!

    (and yes, you could write nice code in VB.net, if you learned it after C or C++ ;) )

  • Sebastian Andersson (unregistered) in reply to Eric

    Exchanging Begin with { and End with }, and writing the type before the variable name instead of after it, in what way does it make you into a better programmer?

  • JarFil (unregistered)

    I love the comments:

    ParseText(ByVal textIn As String) As String

    ''' <param name="textIn"></param> ''' <returns>String</returns> ''' <remarks></remarks>

    Now, that's useful...

Leave a comment on “Far Too Fancy”

Log In or post as a guest

Replying to comment #:

« Return to Article