• Badger (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.

    Don't you know programming is an atomic process?? You either know everything or nothing at at all. Instantly.
  • TheCheese (unregistered) in reply to Greg D

    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?

  • (cs) in reply to el jaybird
    el jaybird:
    > examine elevator

    I see no elevator here.

    <snip>

    Quality :-D

  • anonymous coward (unregistered)

    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 (unregistered)

    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.

  • (cs)

    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 (unregistered) in reply to tedbilly

    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 (unregistered)

    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 (unregistered) in reply to toby
    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.

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

  • (cs) in reply to KG
    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 (unregistered)

    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.

  • (cs) in reply to FredSaw

    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 (unregistered) in reply to FredSaw
    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 (unregistered) in reply to NXavier

    Addendum: No, I don't mean "ninja" proprietary code. THAT is a no-no.

  • (cs)

    At least he did not write his own xml parser...

  • Xarium (unregistered) in reply to PSWorx
    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. (unregistered)

    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 (unregistered)

    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. (unregistered) in reply to Cheong

    Nah, it was written when 2.0 was already out there. The code is 1.1, though...

  • Adam (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.

    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 (unregistered)

    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 (unregistered) in reply to Sack Scratcherton
    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 (unregistered) 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

    It is pitch black. You are likely to be eaten by a grue.

  • Redeemer (unregistered) in reply to NXavier
    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 (unregistered) in reply to Redeemer
    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 (unregistered)

    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 (unregistered)

    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 (unregistered) in reply to toby
    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 (unregistered) in reply to Greg D
    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 (unregistered) in reply to Redeemer
    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."

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

    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 (unregistered)

    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 (unregistered)

    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 (unregistered) in reply to MattC
    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 (unregistered) in reply to Nick
    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 (unregistered) in reply to Greg D

    homebrew C style?

    what's wrong with

    int my_int = atoi(my_string);
    

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

  • CY (unregistered) in reply to Greg D

    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 (unregistered) in reply to brandon
    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 (unregistered) in reply to Greg D

    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 (unregistered) in reply to Nick

    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 (unregistered) in reply to Ior

    That is: ... string value = string.Empty; XmlNode appSetting = doc.SelectSingleNode(xpQuery); if (appSetting != null) value = appSetting.Attributes["value"].Value;

    return value;

  • Sebastian Ramadan (unregistered) in reply to 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.

    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.

Leave a comment on “Right Under your Nose”

Log In or post as a guest

Replying to comment #:

« Return to Article