- 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
Go figure.
Admin
This is the exact same thing as they are doing at log4net. But that is because they also support Mono and .NET v1.1.
Admin
Yeah, but software "engineers" don't trust the code Microsoft wrote. We always want to have code we know; code we can maintain and 'tweak' as needed. Either that or you are getting paid by the SLOC!
Admin
So nobody here has ever written some code that had already been written, if only you'd known about it?
I've been in situations where I know there's a way of doing something, but no about of API/MSDN/Google searching comes up with what I need, so I write it myself. Then a few weeks later someone will say "you should have used xxxx" and lo and behold, yes I should - if I'd know about it at the time.
Admin
I really like that is creating severa objects just to get a string from a text file. Great stuff. On the other hand this reminds me of GetProfileString and GetPrivateProfileString and that I did something similar in the early nineties cause I didn't know they exist.
Admin
Yeah, like programmers are supposed to know everything, right?
This is perfectly normal, the author just didn't know about some part of the API, contrary to what you may believe, it's not always discoverable.
If anything, the stupidity lies in the implementation: why use XPath expression to select parent node and then interate over all of them manually, instead of using XPath expression that directly selects the right key's node?
Admin
So not only did he not know about the existing library (forgivable), but he doesn't understand the concept of a parameterized function (a much worse WTF, IMHO).
Admin
Yeah, right, like you're gonna use .NET if you don't trust Microsoft code in the first place...
Admin
Well that hardly is the point, but the use of web.config and ConfigurationManager is the first thing that you learn when using asp.net.
Admin
I have worked on a program that had about 4 functions to read it's own configuration. They all did the same basic thing (get a variable from the config file), but they went about it a entirly different way. In the end I made good use of the search function in the IDE and replaced all calls with what I considered the best method of the 4. This pattern was repeated for a lot of other functions as well. One function was written about 8 times in different forms.
Then again, the same program was about 70% unused code. About 20% of that was code turned into comments, the other 80% was in its orriginal form (and compiled into the program). My first days on the job I spent searching and deleting code.
Result: a 5MB EXE reduced to 2MB and a load time reduced from 2 minutes to 15 seconds :)
Admin
Admin
That's exactly the point: "Or maybe you didn't know that the solution was built already, right under your nose the whole time"
The first thing I learnt was the ubiquitous hello world. Delving into web.config was certainly not page 1 of the course notes. Just because you know something, doesn't mean that everybody else does, just as not knowing something isn't a WTF.
Admin
Why wouldnt you trust microsoft .net code? The .net framework is open now to see what they do.
Research people.
Admin
Aren't you supposed to use WebConfigurationManager instead of ConfigurationManager when it's a web application? I could be wrong but I thought that's how it worked.
Admin
OK then, if you don't know about the existence of the XML API and just parse the web.config with String.IndexOf("<") wouldn't that be a WTF?
Admin
Admin
To all the apologists: if you're writing over a dozen lines to accomplish something that a moment's thought will show should be common and easy, you're definitely not spending your time right. This programmer did not do something obvious like typing "web.config reading" into Google, because they'd have immediately found what they're looking for in the first hit.
We've all had our moments missing an API that would have been useful and it doesn't make you stupid, but some APIs are definitely more obvious than others and reinventing the wheel is a lot less excusable in those cases.
Admin
Personally, I think it's admirable that H.Y. sat down and read the entire .NET manual before starting Visual Studio. But I think his colleague can be forgiven for not doing so.
Admin
Actually, there's a perfectly legitimate reason for doing this - the System.Configuration assembly requires fully trusted callers.
Admin
The XML parsing is it's own WTF. He knows enough to use XPath to get to the AppSettings node, then he starts iterating; why doesn't he just get the exact node he wants?
Admin
Actually, I think he fell into option 1. He probably didn't trust the person that wrote the code to do that. After all, it was Microsoft.
Admin
I have noticed in software engineering that too much pride leads to too many WTFs.
(I am not criticizing you, Nick, just using your comment as a soap box)
Admin
Yeah but someone who hasn't gotten round to delving into ASP.net, should do some reading first. That's the point, whatever YOU say. If you took a book about ASP.net, it'll be among the first things you're told.
So what do we have here then? Well probably someone who thinks his skills don't require him to get acquainted with a new framework. Thats's a WTF for me.
Admin
The real wtf here is that they used .net.
Admin
Admin
The most proper way to do this is obviously:
for (int i = 0; i < strlen(buffer); i++) { if buffer[i] == '<' { ... and so on... } }
Admin
Admin
That's what the docs are for. I'm really sick of seeing yet another broken, homebrew, C-style string-to-int function in languages like C# and Java. As professionals, it's our responsibility to know and understand our tools (including language libraries) on a level where we can use them effectively and as they were intended.
Admin
Obviously he needed to implement another function to get connection strings - their XML schema is completely different from a key/value pair!
Admin
Admin
Taking into account that the originally proposed solution is considered acceptable by some, I believe this one should really kick a*s as it is superior in terms of performance and lines of code used, with readability about the same.
Admin
Admin
Admin
Perhaps this question has an obvious answer... But was the original code written for 1.1? As in, before ConfigurationManager existed?
Not that there aren't other WTFs (XPath is your friend! As are functions with parameters!) but without knowing whether that code was originally written for .NET 1.1, it seems like the real WTF might be the vicious rush to condemn him for failing to use a library that he might not have had access to...
Admin
I can see arguments both way on this, but I confess to being completely overwhelmed by all the libraries and APIs available. It is made more difficult when you consider all the home grown functions and tools that should be used instead of reinventing the wheel-- and these are often especially poorly documented.
Developing used to be hard because of poor tools and lack of pre-developed components. It is still hard, but now it is because there is so much going on.
Admin
Admin
Admin
We have similar code which was written before ConfigurationManager existed. It's a shame so many people are being so critical without knowing the facts behind the 'story', with others following the herd, while the herd act like ignorant children.
Admin
What were you using, a pre-1.0 version of the framework?
Admin
A friend describes learning curve of Java.
You want to accomplish certain task. You feel like on the bottom of a huge well, and you climb it slowly, step by step, slippery walls, tricky tresholds. Finally you reach the top of the well, then some fucking guru comes and says "Why the hell didn't you use the elevator?"
Java documentation is great at describing what given function does, but utterly fails at mentioning which functions to use if you need to do something. It's like trying to translate a text from english to japaneese, using japaneese-english (not english-japaneese) dictionary.
Admin
I see no elevator here.
You are at the bottom of a huge well. The walls look slippery, with tricky thresholds. The only exit is up, but it's a long way...
Exits: none
You are carrying:
2 big pot pies a buffalo water skin a vorpal sword a scroll marked "Java For Dummies"
You recite a scroll marked "Java For Dummies". You feel yourself flying!
Your Cubicle
Congratulations, you made it out of the well. You find yourself in a cloth-wrapped cube, 6 feet by 6 feet square. In front of you is a desk piled high with work. Better get back to it.
Exits: none
Admin
I never felt comfortable disturbing other employees from their work, just to ask a stupid question. Though, I will admit lack of communication has led to more than a few WTF's here.
Admin
Erm yes looks like I was a bit too general there, there's only certain things you can't do when calling from partial trust, like GetSection() etc...
Admin
I can beat that, twice.
On the first occasion I was working on some coursework in my first year at uni and needed a linked list in Java, so I implemented one and had it at the end of my source file.
Secondly, and slightly more scary, I was looking for something in Windows\System32 on my laptop about a year ago, I don’t recall why, and noticed that there were some table spaces there. This lead to me learning a lot more about Oracle tablespace config than I ever wanted to know as I proceeded to move them to somewhere more suitable, like Oracle\tablespaces.
Admin
If you are using a framework that reads web.config and makes use of that data within the framework's process, there is no excuse for not checking the framework to see if it can provide you with the data you know it already has.
Admin
Admin
An interesting thing about configuration manager is that you can both read and write configuration data using it, however writing to a key only modifies the cached in memory version of web.config, and not the file itself, so that modification will be lost after the application pool recycles.
To actually modify a key within the file takes code similar to this WTF's.
Admin
Admin
Wow. How many different tools do you work with? I'll guarantee you that if I spent all day RTFM I'd get very little actual work done.
So, okay, yes - this one was easy and fairly obvious. But I too am guilty of "rolling my own" methods because I didn't know that something similar already existed in an API, framework, yadda yadda.
I often chuckle at all the comments I see here. Everyone who responds must be excellent coders who never make mistakes or re-invent the wheel.
It's quite a disconnect for me, actually. I'm reminded of when a company I worked for decided to hire in a bunch of "experts" to help us integrate an existing client-server ERP system into a massive online ERP website we were building. They were awfully good at standing around, sipping coffee, and discussing design patterns and the nuances of various languages, etc. But boy oh boy you should have seen their code. We were stuck fixing and re-writing their crap for months after they left.
Admin
But something I dislike about Java is the docs. Its hard to find things, there is no higharchy.
You are forced to read a 3 books to find out about the API.