- 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
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?
Admin
So, use a DOM to avoid using a DOM. Makes perfect sense!
Admin
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.
Admin
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.
Admin
The Real WTF is that no-one has yet chimed in with, "The Real WTF is using VB". Because that would be funny. </sarcasm>
Admin
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?)
Admin
This is why all the good coding jobs are going to India.
Admin
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.
Admin
The real WTF is that the helmet-wearing VB clowns are defending their language before anyone has a chance to criticize it.
Admin
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.
Admin
The real WTF:
Admin
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!
Admin
Yeah, but what really gets me is the fact that their comments are in XMLish. Weird. What advantage does that give you?
Admin
The real WTF is that they're using VB.
Admin
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.
Admin
I'm too sexy for this code, too sexy for this fancy code, oh yeah.
Admin
Using this style of comments give Visual Studio the ability to generate documentation for your classes.
Admin
lol, what a funny image... halfarsed clowns running into each other because their helmets are on backwards!
Admin
Wow, that sounds great - can I buy it off you? :)
Admin
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:
when you can say something like:
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.
Admin
Its VB.NET, so the reason they ignored the built in libraries should be obvious.
You get what you pay for.
Admin
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.
Admin
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".
Admin
We have a say here:
They have discovered the hot water!
Admin
Wait I see the WTF
Should be
otherwise if an error occured, we wouldn't get xml back.
Admin
TRWTF is using XML
Admin
Admin
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.
Admin
Admin
Admin
I think my face just melted...
Nice try, but what if your exception text contains XMl special chars?
Obviously it should be
Admin
Please send me teh codes
Admin
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.
Admin
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.
Admin
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.
Admin
Admin
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)
Admin
Admin
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)
Admin
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.
Admin
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.
Admin
The first clue is the fact that it's in VB at all.
Admin
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...
Admin
I see ...
the wtf is the use of VB.Net that's why VB programmers have bad reputations
Admin
Admin
The function doesn't return xml. It creates a string containing "<x>TextIn</x>" then chops off the xml tags and returns the result.
Admin
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
Admin
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++ ;) )
Admin
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?
Admin
I love the comments:
Now, that's useful...