• It's a Feature (cs)

    Go figure.

  • Manuel (unregistered)

    This is the exact same thing as they are doing at log4net. But that is because they also support Mono and .NET v1.1.

  • ParkinT (cs)

    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!

  • Nick (unregistered)

    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.

  • Cloak (unregistered)

    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.

  • me (unregistered)

    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?

  • snoofle (cs)

    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).

  • JiP (cs) in reply to ParkinT

    Yeah, right, like you're gonna use .NET if you don't trust Microsoft code in the first place...

  • zamies (unregistered) in reply to Nick
    Nick:
    So nobody here has ever written some code that had already been written, if only you'd known about it?

    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.

  • Jeroen B (unregistered)

    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 :)

  • snoofle (cs) in reply to me
    me:
    ...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....
    Very true - sometimes you just don't conjure up the right search phrase...
  • Nick (unregistered) in reply to zamies
    zamies:
    Nick:
    So nobody here has ever written some code that had already been written, if only you'd known about it?

    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.

    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.

  • y0 (unregistered)

    Why wouldnt you trust microsoft .net code? The .net framework is open now to see what they do.

    Research people.

  • Matt Thalman (unregistered)

    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.

  • Vroomfundel (unregistered)
    not knowing something isn't a WTF

    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?

  • Tom_fan_DK (unregistered) in reply to Nick
    Nick:
    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.

    Never heard about that strange entities called "Collegues"? Or, even better, "Experienced Collegues"? ;-)
  • JM (unregistered)

    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.

  • gabba (cs)

    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.

  • Fredrik (unregistered)

    Actually, there's a perfectly legitimate reason for doing this - the System.Configuration assembly requires fully trusted callers.

  • Elmo (unregistered)

    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?

    string xpQuery = string.Format("//configuration/appSettings/add[@key='{0}']", key);
  • Brian (unregistered)

    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.

  • dphunct (cs) in reply to Nick
    Nick:
    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.

    I admit, I have done this. I have since learned to talk to others. Evan as the senior member of the team, I would consult others about things they understood more than I did. You would be surprised what a design review meeting can accomplish.

    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)

  • zamies (unregistered) in reply to Nick
    Nick:
    zamies:
    Nick:
    So nobody here has ever written some code that had already been written, if only you'd known about it?

    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.

    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.

    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.

  • Truth (unregistered)

    The real wtf here is that they used .net.

  • FredSaw (cs) in reply to me
    Nick:
    So nobody here has ever written some code that had already been written, if only you'd known about it?
    me:
    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.

    Guys, let's revisit the first paragraph of the post, okay?
    There are a lot of reasons to reinvent software. Maybe you don't trust the person who wrote it in the first place. Maybe you wrote it back when you didn't know what you were doing, but this time you'll get it right. Or maybe you didn't know that the solution was built already, right under your nose the whole time.
    Notice the continuous use of "you": "Maybe you... maybe you... maybe you..." Obviously, the thrust of the presentation is that we have all done this and can relate! Nobody's pointing a finger and saying, "Look at him, he's so stupid..." We're laughing at ourselves and saying, "Oh, yeah, I've done that too!"

  • el jaybird (unregistered)

    The most proper way to do this is obviously:

    for (int i = 0; i < strlen(buffer); i++) { if buffer[i] == '<' { ... and so on... } }

  • JM (unregistered) in reply to Fredrik
    Fredrik:
    Actually, there's a perfectly legitimate reason for doing this - the System.Configuration assembly requires fully trusted callers.
    Really? What version of the framework are you using, then? The 2.0 System.Configuration on *my* machine doesn't, and indeed I would be very surprised if partial trust applications suddenly couldn't read their own configurations anymore...
  • Greg D (unregistered) in reply to Nick
    Nick:
    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.

    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.

  • GalacticCowboy (cs)

    Obviously he needed to implement another function to get connection strings - their XML schema is completely different from a key/value pair!

  • foo (unregistered) in reply to Nick
    Nick:
    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.

    That's why good shops let their developers talk to each other and don't punish people for asking questions.
  • Vroomfundel (unregistered) in reply to el jaybird
    el jaybird:
    The most proper way to do this is obviously:

    for (int i = 0; i < strlen(buffer); i++) { if buffer[i] == '<' { ... and so on... } }

    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.

  • ThePants999 (cs) in reply to FredSaw
    FredSaw:
    Nobody's pointing a finger and saying, "Look at him, he's so stupid..." We're laughing at ourselves and saying, "Oh, yeah, I've done that too!"
    Sorry, Fred, I'm pointing a finger at him. A second's thought would have led to "hang on, why would we have this standardised place for connection strings if there wasn't an easy way to get at it?", followed by a Google which would have turned up the answer immediately. It's a WTF.
  • T $ (cs) in reply to ThePants999
    ThePants999:
    FredSaw:
    Nobody's pointing a finger and saying, "Look at him, he's so stupid..." We're laughing at ourselves and saying, "Oh, yeah, I've done that too!"
    Sorry, Fred, I'm pointing a finger at him. A second's thought would have led to "hang on, why would we have this standardised place for connection strings if there wasn't an easy way to get at it?", followed by a Google which would have turned up the answer immediately. It's a WTF.
    I probably would have disagreed if he had done one function like this. If it was just the once, I would have been inclined to think he was running out of time, did a quick search, and threw it up there. But the fact that he repeated this block a few lines later on, should have set off some bells in his head. Even if he was absolutely convinced that this was the only way to do it, he should have at least added in a parameter to pass the xpQuery. All things considered, that's WTF-worthy in itself.
  • canuckotter (unregistered)

    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...

  • bob (unregistered)

    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.

  • FredSaw (cs) in reply to ThePants999
    ThePants999:
    FredSaw:
    Nobody's pointing a finger and saying, "Look at him, he's so stupid..." We're laughing at ourselves and saying, "Oh, yeah, I've done that too!"
    Sorry, Fred, I'm pointing a finger at him. A second's thought would have led to "hang on, why would we have this standardised place for connection strings if there wasn't an easy way to get at it?", followed by a Google which would have turned up the answer immediately. It's a WTF.
    Oops, my mistake... a few people are pointing the finger. The rest of us are laughing at ourselves.
  • clively (cs)
    <sarcasm> Absolutely a WTF, this guy will never work on an enterprise level app. <ol> <li>The results aren't cached.</li> <li>No Interface reference.</li> <li>The name of the config file isn't coming from another config file (or the registry).</li> <li>He doesn't take into account non-string values.</li> <li>He doesn't throw the exceptions.</li> </ol> </sarcasm>
  • A developer (unregistered) in reply to canuckotter

    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.

  • JM (unregistered) in reply to A developer
    A developer:
    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.
    System.Configuration.ConfigurationSettings was functionally equivalent. They deprecated it in 2.0 in favor of ConfigurationManager.

    What were you using, a pre-1.0 version of the framework?

  • s. (unregistered) in reply to Nick
    Nick:
    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.

    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.

  • el jaybird (unregistered) in reply to s.
    s.:
    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?"

    examine elevator

    I see no elevator here.

    look

    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

    i

    You are carrying:

    2 big pot pies a buffalo water skin a vorpal sword a scroll marked "Java For Dummies"

    recite scroll

    You recite a scroll marked "Java For Dummies". You feel yourself flying!

    up

    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

  • KG (unregistered) in reply to foo
    foo:
    That's why good shops let their developers talk to each other and don't punish people for asking questions.

    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.

  • Fredrik (unregistered) in reply to JM
    JM:
    Fredrik:
    Actually, there's a perfectly legitimate reason for doing this - the System.Configuration assembly requires fully trusted callers.
    Really? What version of the framework are you using, then? The 2.0 System.Configuration on *my* machine doesn't, and indeed I would be very surprised if partial trust applications suddenly couldn't read their own configurations anymore...

    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...

  • Dexter (unregistered)

    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.

  • Michael (unregistered) in reply to Nick
    Nick:
    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.

    There is a difference between not knowing that an API exists, and not checking the API you are currently using to see if it offers a function to get it's data. It's like using a HashMap and not bother to see if it has a "get(key)" function.

    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.

  • FredSaw (cs) in reply to el jaybird
    el jaybird:
    a vorpal sword
    And hast thou hacked the javawock? Come to my arms, my beamish girl (No boys, thankyaverymuch).
  • Jonathan Holland (cs)

    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.

  • CodingForPretend (cs) in reply to el jaybird
    el jaybird:
    s.:
    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?"

    examine elevator

    I see no elevator here.

    look

    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

    i

    You are carrying:

    2 big pot pies a buffalo water skin a vorpal sword a scroll marked "Java For Dummies"

    recite scroll

    You recite a scroll marked "Java For Dummies". You feel yourself flying!

    up

    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

    Awesome, Java according to Zork!
  • NXavier (unregistered) in reply to Greg D
    Greg D:
    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.

    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.

  • bad boss (unregistered)

    That's what the docs are for.

    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.

Leave a comment on “Right Under your Nose”

Log In or post as a guest

Replying to comment #:

« Return to Article