Right Under your Nose

« Return to Article
  • It's a Feature 2008-01-23 08:01
    Go figure.
  • Manuel 2008-01-23 08:17
    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 2008-01-23 08:21
    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 2008-01-23 08:21
    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 2008-01-23 08:29
    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 2008-01-23 08:30
    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 2008-01-23 08:30
    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 2008-01-23 08:31
    Yeah, right, like you're gonna use .NET if you don't trust Microsoft code in the first place...
  • zamies 2008-01-23 08:33
    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 2008-01-23 08:34
    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 2008-01-23 08:36
    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 2008-01-23 08:39
    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 2008-01-23 08:59
    Why wouldnt you trust microsoft .net code? The .net framework is open now to see what they do.

    Research people.
  • Matt Thalman 2008-01-23 09:00
    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 2008-01-23 09:03
    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 2008-01-23 09:07
    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 2008-01-23 09:10
    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 2008-01-23 09:11
    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 2008-01-23 09:14
    Actually, there's a perfectly legitimate reason for doing this - the System.Configuration assembly requires fully trusted callers.
  • Elmo 2008-01-23 09:14
    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 2008-01-23 09:14
    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 2008-01-23 09:18
    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 2008-01-23 09:25
    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 2008-01-23 09:26
    The real wtf here is that they used .net.
  • FredSaw 2008-01-23 09:26
    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 2008-01-23 09:27
    The most proper way to do this is obviously:

    for (int i = 0; i < strlen(buffer); i++)
    {
    if buffer[i] == '<'
    {
    ... and so on...
    }
    }
  • JM 2008-01-23 09:29
    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 2008-01-23 09:31
    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 2008-01-23 09:37
    Obviously he needed to implement another function to get connection strings - their XML schema is completely different from a key/value pair!
  • foo 2008-01-23 09:40
    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 2008-01-23 09:42
    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 2008-01-23 09:45
    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 $ 2008-01-23 09:54
    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 2008-01-23 09:59
    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 2008-01-23 10:01
    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 2008-01-23 10:17
    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 2008-01-23 10:30
    <sarcasm>
    Absolutely a WTF, this guy will never work on an enterprise level app.


    1. The results aren't cached.
    2. No Interface reference.
    3. The name of the config file isn't coming from another config file (or the registry).
    4. He doesn't take into account non-string values.
    5. He doesn't throw the exceptions.


    </sarcasm>
  • A developer 2008-01-23 10:45
    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 2008-01-23 10:53
    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. 2008-01-23 11:00
    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 2008-01-23 11:19
    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 2008-01-23 11:27
    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 2008-01-23 11:30
    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 2008-01-23 11:54
    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 2008-01-23 11:59
    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 2008-01-23 12:18
    el jaybird:
    a vorpal sword
    And hast thou hacked the javawock? Come to my arms, my beamish girl (No boys, thankyaverymuch).
  • Jonathan Holland 2008-01-23 12:32
    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 2008-01-23 12:44
    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 2008-01-23 12:56
    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 2008-01-23 12:56
    >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.
  • Badger 2008-01-23 12:58
    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.

    Don't you know programming is an atomic process?? You either know everything or nothing at at all. Instantly.
  • TheCheese 2008-01-23 13:08
    As professionals it is our job to keep vigilant, but at the rate of library/language/technology expansion I believe I'm voting on the side of keeping this post in the spirit of "ha, I've done that". Please, did we REALLY need to put ruby on rails, were the streets not fast enough?

  • ThePants999 2008-01-23 13:22
    el jaybird:
    > examine elevator

    I see no elevator here.

    <snip>
    Quality :-D
  • anonymous coward 2008-01-23 13:31
    I worked at a shop where *the* design was to use web services for the data access layer. They passed the web.config file as an input parameter to the web service. Then, the web service could retrieve such information as the database connection string to be used (different callers used different copies of databases with identical schemas). I don't believe that you can use ConfigurationManager to examine a web.config file outside of the current root.
  • toby 2008-01-23 13:32
    Well at least he read a value from an XML file the "right" way: by using an XPath query to pull out the value. A true WTF would involve something like a "for(int i=0; i < file.Length; i++)" loop to read over each character one at a time and cobbling together some kludgy state machine depending on whether he had recently seen a left-angle-bracket.
  • tedbilly 2008-01-23 13:37
    Whenever a developer is about to write some code they should look at the non-business specific functionality and think "Somebody must have already solved this problem". Either in their company (if it's a large one) or somewhere on the web.

    In fact I find the best programmers are good at finding solutions then tweaking them to the specific business needs. They are always reusing someone else's code.

    Sadly interview processes don't consider that skill. In fact they promote the opposite. Interviews are about proving our domain knowledge. Essentially the knowledge you have in your head.

    However, I'd take a developer with a short memory that can find and adapt other's solutions quickly over a 'think they know it all' type any day. The first won't reinvent the wheel or suffer from 'Not Invented Here Syndrome'.

    By the way I'm a Senior Developer with 20+ years experience and I would never be arrogant enough to assume I know everything. Even if I knew 99% of all that is knowable on any technology a newbie might know the 1% I am missing. Therefore I can learn from anyone.
  • KG 2008-01-23 13:52
    The problem is sometimes it's far more difficult (and takes far more time) to research an existing solution in the API than to roll your own.

    tedbilly:
    In fact I find the best programmers are good at finding solutions then tweaking them to the specific business needs. They are always reusing someone else's code.


    In my college English classes, you would fail if the professor found evidence of plagiarism. I also remember two students who failed one of my CS classes because they shared code with eachother (prof treated it as 1 project grade split between the two students). That, combined with how easy it is to get sued in America for such things, makes me scared of always copying / reusing code from somewhere on the net.
  • Mark 2008-01-23 14:02
    This sort of thing is all to common. I've seen this time after time. Usually the person who wrote it just wasn't aware of the function existing and just went about it the hard way.
  • el jaybird 2008-01-23 14:15
    toby:
    Well at least he read a value from an XML file the "right" way: by using an XPath query to pull out the value. A true WTF would involve something like a "for(int i=0; i < file.Length; i++)" loop to read over each character one at a time and cobbling together some kludgy state machine depending on whether he had recently seen a left-angle-bracket.


    Which, in the end, isn't altogether THAT different from using a SAX parser.

    Kludgy state machine, check.

    DOM FTW.
  • PSWorx 2008-01-23 14:41
    Elmo:
    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);


    Was wondering the same. Though, wouldn't the "correct" XPath be
    //configuration/appSettings/add[@key='{0}']/@value

    ?

    (Ignoring the general WTF that are "key" and "value" elements in any XML scheme...)
  • FredSaw 2008-01-23 14:58
    KG:
    In my college English classes, you would fail if the professor found evidence of plagiarism. I also remember two students who failed one of my CS classes because they shared code with eachother (prof treated it as 1 project grade split between the two students). That, combined with how easy it is to get sued in America for such things, makes me scared of always copying / reusing code from somewhere on the net.
    In college the goal is to learn programming skills (unless you're that guy who thinks it should be all theory). You wouldn't be learning anything if you plagiarized another student's work.

    In the IT business world, the goal is to finish a project on time and on budget, preferably under. Therefore there's no point in you doing what has already been done. And in my 12 years in the business, I have never had to steal someone else's proprietary code; but on an almost daily basis I google some issue and find a website where a solution is offered. This is most often on MSDN or related forums, since I'm a .Net developer.

    There's no shame in using code you didn't write.
  • Sack Scratcherton 2008-01-23 15:01
    This is something that is germane to ASP.NET. If you create a project holding website development code, and it *automatically* creates a file named *.config with some prepopulated data in it, wouldn't you at least look to see if there is a facility that provides a convenient way to read data from that file? Go to any ASP.NET tutorial page, and one of the first things they hit you in the face with is how great the web.config file is.

    Still a pretty weak WTF. Even though it's a pretty inefficient manner to retrieve data from the config, at least it's solid and it works.
  • tedbilly 2008-01-23 15:36
    Fredsaw is correct. We would never use someone's proprietary code. Learning from others who love to share via open source or sites like www.codeproject.com (or similiar) is a way to not only solve business problems quickly, it is a way to grow as a developer.

    I have no interest in hiring developers that learn in a vacuum strictly from writing their own code.
  • NXavier 2008-01-23 15:42
    FredSaw:
    KG:
    In my college English classes, you would fail if the professor found evidence of plagiarism. I also remember two students who failed one of my CS classes because they shared code with eachother (prof treated it as 1 project grade split between the two students). That, combined with how easy it is to get sued in America for such things, makes me scared of always copying / reusing code from somewhere on the net.


    In college the goal is to learn programming skills (unless you're that guy who thinks it should be all theory). You wouldn't be learning anything if you plagiarized another student's work.

    In the IT business world, the goal is to finish a project on time and on budget, preferably under. Therefore there's no point in you doing what has already been done. And in my 12 years in the business, I have never had to steal someone else's proprietary code; but on an almost daily basis I google some issue and find a website where a solution is offered. This is most often on MSDN or related forums, since I'm a .Net developer.

    There's no shame in using code you didn't write.


    Absolutely.

    I wonder how many 'academic' types post here? In the real world, most every developer I know is simply pounding out code to get a project completed on time (it's nice to have a paycheck, ya know.) Anyway, it's not that good code isn't written, it is. It's just that there's so damn much to do that we count ourselves lucky when we find a quality gem that we can ninja ;-)

    After graduating, I struggled with this issue - grab snippets of code where I could or write everything myself. A boss I had at the time told me (and I'm paraphrasing here) "Hey, we are all standing on the shoulders of giants anyway. So, don't waste your time solving problems that have already been solved. You've enough to do with what you can't find existing working code for."
  • NXavier 2008-01-23 15:44
    Addendum: No, I don't mean "ninja" proprietary code. THAT is a no-no.
  • henke37 2008-01-23 17:33
    At least he did not write his own xml parser...
  • Xarium 2008-01-23 20:59
    PSWorx:

    ... wouldn't the "correct" XPath be
    //configuration/appSettings/add[@key='{0}']/@value

    ?


    *APPLAUSE*

    I'm so happy to see decent XPaths in the wild - the sheer amount of stunning WTF'ery I see every day regarding clueless XML/XPath/XSL I'm freakin' lonely here.

    My contribution: the extra / at the start should be dropped - it could potentially be harmful (though unlikely).
  • H.Y. 2008-01-23 21:31
    Wow, that's great :) I didn't think that my submission will ever make it...

    Oh, and the interesting thing is... this developer, an ex co-worker of mine, has won a couple of high-school/university .NET development contests!

    "Go figure", indeed!
  • Cheong 2008-01-23 22:18
    I don't know, but if that program is made before 2002 (i.e.: at the time only beta version of .NET is released) I can understand. (Granted seems even the last version of MSDN documentation for VS2003, at the web.config index section, the only place mention how to read this is example for VB only (topic named "exmaple [Visual Basic]), C# users might simply skipped that.)
  • H.Y. 2008-01-23 23:28
    Nah, it was written when 2.0 was already out there. The code is 1.1, though...
  • Adam 2008-01-24 04:33
    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.


    In all honesty. We're paid well to keep our skills up to date and not require google every time we get a problem.

    In the olden days, the old gits didn't have google and usually the manuals hadn't been written yet (no 18 months of pre-releases to write a manual).

    Then, it was acceptable to write rubbish like this, but not now. All it requires to be a programmer these days is how to use google to find where somebody else has done it.
  • csrster 2008-01-24 05:35
    I must admit to doing various equally crappy things in my early days as a programmer. Knowing where to put configuration parameters and knowing how to read them doesn't seem to be terribly well covered in the average CS degree and I've seen some horrible solutions from my colleagues as well. We're a Java house so I now know that the only right way is to put the stuff on the classpath and read it via a ClassLoader.
  • dkf 2008-01-24 06:41
    Sack Scratcherton:
    Still a pretty weak WTF. Even though it's a pretty inefficient manner to retrieve data from the config, at least it's solid and it works.
    Agreed. For it to have been a true WTF, that code would have had to have used some other part of the ConfigurationManager class to configure the XML parser for web.config. At that point, it would have indicated that someone read straight past the solution on the way to their own home-brew version...
  • yimms 2008-01-24 07:35
    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

    >



    It is pitch black. You are likely to be eaten by a grue.
  • Redeemer 2008-01-24 08:04
    NXavier:

    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.

    -snip-

    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.


    Firstly.. you need to know your tools before use can effectively use them... You neednot be able to quote on which page of the manuaal or doc a particular function is documented, but you should atleast have seen the manual and know to reference it. Also, it is better to waste some time RTFM than to spend on writing something that could be avoided by reading the manual.. and that way you will evenlearn something for the future.

    Secondly... It isnt wrong to be capable of standing and talking about design patterns and nuances of a language isnt bad, as long as you can follow up with the implementation. Not know enough of either part may cause you to generate such WTF pieces...

  • Redeemer 2008-01-24 08:15
    Redeemer:

    Firstly.. you need to know your tools before use can effectively use them... You neednot be able to quote on which page of the manuaal or doc a particular function is documented, but you should atleast have seen the manual and know to reference it. Also, it is better to waste some time RTFM than to spend on writing something that could be avoided by reading the manual.. and that way you will evenlearn something for the future.

    Secondly... It isnt wrong to be capable of standing and talking about design patterns and nuances of a language isnt bad, as long as you can follow up with the implementation. Not know enough of either part may cause you to generate such WTF pieces...



    Yes, i know i have a problem with run on sentences, and that i dont know how to reference a dictionary... incase anyone thought of mentioning
  • I didnt know that 2008-01-24 09:31
    hey.. I just realised...

    I have been googling every single day for daily WTF's.. And waddya know.. There's a site called TheDailywtf.com...

    Well, if only I knew that
  • E 2008-01-24 09:45
    Our useless mentally handicapped "Manager of Architecture" does crap like this not because he doesn't know the function exists, but because he doesn't trust microsoft. He rewrote his own sucky data access layer because microsofts Data Application Blocks are "filled with bugs".
  • Mez 2008-01-24 11:36
    toby:
    Well at least he read a value from an XML file the "right" way: by using an XPath query to pull out the value. A true WTF would involve something like a "for(int i=0; i < file.Length; i++)" loop to read over each character one at a time and cobbling together some kludgy state machine depending on whether he had recently seen a left-angle-bracket.


    Oops....I've done exactly that! In my defence I was in a hurry and couldn't figure out xpath easily, but I realise that's not much of a defence...

    I wonder how much of these WTFs arise from pressured coding vs lack of ability...
  • Arturo 2008-01-24 12:15
    Greg D:

    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.


    I agree. But what do you do when your manager put you under pressure to end your project? You just finish it... sometimes no matter if you end reinventing some wheels.
  • NXavier 2008-01-24 12:43
    Redeemer:
    NXavier:

    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.

    -snip-

    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.


    Firstly.. you need to know your tools before use can effectively use them... You neednot be able to quote on which page of the manuaal or doc a particular function is documented, but you should atleast have seen the manual and know to reference it. Also, it is better to waste some time RTFM than to spend on writing something that could be avoided by reading the manual.. and that way you will evenlearn something for the future.

    Secondly... It isnt wrong to be capable of standing and talking about design patterns and nuances of a language isnt bad, as long as you can follow up with the implementation. Not know enough of either part may cause you to generate such WTF pieces...



    Redeemer,

    Yes - your point is well taken. I don't disagree with you really, it's just that there's a whole whole WHOLE lot of information and documentation out there. It's hard to always know every little thing about every framework/API/library that we employ. It's especially difficult when you've got a deadline, new tools, and managers on your arse at every turn. You know this as well as I do... I think.

    And on the second point, I would be far more impressed if the contractors could have actually implemented something usefull. But I see this a lot. Talking a good game and actually being able to play a good game are two quite different things. My point here should only really be offensive to those who feel more akin to the "talkers."
  • chrismcb 2008-01-24 14:47
    s.:

    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.


    Do you want step by step instructions on how to program? Perhaps you want a large dictionary of which functions to use for a particular program, and perhaps the order of those functions?
  • Paula Bean 2008-01-24 14:57
    The real WTF is that, in the ConfigurationManager documentation, the phrase


    "You do not need to declare an instance of a static class in order to access its members."

    is syntax highlighted
  • Evgeny Brainman - MS dev 2008-01-24 15:39
    Theres nothing wrong with re-inventing the wheel.
    We are programmers are all, not just a bunch of keyboard monkeys that string together pre-written code.

  • MattC 2008-01-24 18:10
    Exactly *one day ago I got my first (and hopefully last) taste of Genuine C# Dot NET -- trying to work out the *same basic issue: getting a value out of System.Configuration.

    If this was a pro C# she should know this cold. But those of you who think the correct syntax to access this can be found with a quick google are *sorely mistaken.

    As I recall (unwillingly, as I'm trying to repress the memory) System.Configuration.Configuration.AppSettings was changed to System.ConfigurationManger.Configuration.AppSettings between .NET 1.1 and 2.0, then to something else for 3 and something else for 3.5
  • NXavier 2008-01-24 18:24
    MattC:
    As I recall (unwillingly, as I'm trying to repress the memory) System.Configuration.Configuration.AppSettings was changed to System.ConfigurationManger.Configuration.AppSettings between .NET 1.1 and 2.0, then to something else for 3 and something else for 3.5


    Ha!

    Which brings up another point: who among us, after countless death marches, frustration with Dilbertian management, and many years of long hours, still eagerly digs into each and every new release of framework documentation?

    Personally, I go in phases of excitement with my career and wondering when I'm going to hit the Powerball so I can wave goodbye to the headaches :-)
  • JimM 2008-01-25 06:45
    Nick:

    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.


    But this isn't quite as annoying as searching the API and finding out that a trivial and very useful function hasn't been implemented and you end up having to write it yourself anyway (Most of my classic ASP pages now start with a definition of IIf as it's not available in VBScript...) And before anyone else says it (I'm sure someone's thinking it): yes, the real WTF is coding classic ASP in VBScript
  • brandon 2008-01-25 16:41
    homebrew C style?

    what's wrong with

    int my_int = atoi(my_string);


    It's not very different from C# or Java.
  • CY 2008-01-27 13:43
    Ohh, no fun at all? inventing the wheel agin and again is - if I´m not misstaken - the programmers first responsability. Why are there than one programming language? Should we stick to assembler, cobol, ada, fortran, basic, hascel, c++, c#, Java, fjölnir, comal, fort, dcl...

    Nope... lets have fun..
  • Greg D 2008-01-28 10:56
    brandon:
    homebrew C style?

    what's wrong with

    int my_int = atoi(my_string);


    It's not very different from C# or Java.


    That's why I said "homebrew". A library call would be perfect. The example I had in mind, written in C#:
    static public int StringToInt(string s1)
    
    {
    int i0 = (int)'0';
    int i9 = (int)'9';
    int val = 0;
    int j;
    if (s1.Length > 0)
    {
    for (int i = 0; i < s1.Length; i++)
    {
    j = (int)s1[i];
    if (j >= i0 && j <= i9)
    val = val * 10 + j - i0;
    else
    return -1;
    }
    return val;
    }
    else
    return -1;
    }


    Really fundamental stuff that's provided by pretty much every language library worth having, and even most libraries that aren't.
  • dazed coder 2008-01-30 15:20
    I only wish I had the time to sit and read all the docs and library listings that come with every language and compiler I write with.

    I can't think of how many times I have to switch from writing the same type of code, one in MS Visual Studio using STL, the other in Carbide C++ on a Symbian platform and trying to do the same thing without STL... If I can't search and find a quick way, Yes, you got it, I wind up just writing whatever I need from scratch to get the job out the door.

    When time is of the essence then the hack comes in until I have to time to research it greater. As long as no memory leaks, I'm happy and my bank account is happy too.
  • Ior 2008-11-14 07:43
    Seems like our guy wasn't too familiar with XPath either or else he wouldn't have needed to have that awkward while loop there, which doesn't even break when the key is found:

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

    and then selectSingleNode
  • Ior 2008-11-14 08:00
    That is:
    ...
    string value = string.Empty;
    XmlNode appSetting = doc.SelectSingleNode(xpQuery);
    if (appSetting != null)
    value = appSetting.Attributes["value"].Value;

    return value;
  • Sebastian Ramadan 2013-12-22 19:34
    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.


    I'm really sick of seeing yet another try/catch used to interrupt exceptions that aren't caused by exceptional circumstances.

    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.


    As a Java programmer, it's your responsibility to know and understand object resurrection on a level where you can use it effectively and as it was intended.