• Barf 4 eva (unregistered) in reply to Sunstorm

    lol.. ppl love to reinvent the wheel, and usually with lots of imperfections...

    However, I'm all for saying goodbye to DOM and hello to Xlinq. Very eloquent. Very intuitive. The perfect replacement.

  • Ugly Bag of Mostly Water (unregistered)

    Looking at this makes me want to drink. Heavily.

  • Random Person (unregistered) in reply to lw42

    Whoa whoa whoa...don't make any major architecture changes to this Enterprise VB.NET app (snicker) so quickly.

    First, we need to assign some people to find out what will happen when ex.ToString() does not parse neatly into XML? This code could be called recursively and cause a StackOverflowException! Will this StackOverflowException be caught by the Exception Handler and parsed correctly?

  • Gary (unregistered)

    My God. All they need to do is use frames! Problem solved!

  • Greg (unregistered) in reply to DaveK
    DaveK:
    You wouldn't get that from any other guy!
    No you wouldn't, but why did you add a link to Rick Astley???
  • Josh (unregistered) in reply to lw42

    Ah, but don't forget:

    Catch ex As Exception
    
            Return "<error><![CDATA[" + ParseText( ex.ToString() ) + "]]></error>"
    
        Finally

    Since you don't know what's in ex.ToString()....

  • (cs) in reply to Greg D
    Greg D:
    Why say something like:
    Dim SomeXml As String = "<foo>" + SomeText + "</foo>"
    when you can say something like:
    Dim SomeXml As String = "<" + "foo" + ">" + """" + "" + SomeText + """" + "" + "<" + "/" + "foo" + ">";
    See? Now you're doing fewer allocations of immutable strings...
    Ignoring the extra quotes that appear in the result of the second version; those 2 statements are otherwise identical at runtime. All constant expressions are collapsed to their simplest form by the compiler.

    You can check this yourself by looking at the resulting IL.

    But your point is still good and I'd like to add; People who optimize, rarely know how to.

  • gagongsiraulo (unregistered) in reply to Grovesy
    Grovesy:
    Wait I see the WTF
        Catch ex As Exception
            Return ex.ToString
        Finally
    
    

    Should be

    
        Catch ex As Exception
            Return "<error>" + ex.ToString() + "</error>"
        Finally
    

    otherwise if an error occured, we wouldn't get xml back.

    Wait! you forgot to place it inside CDATA section Return "<error>" +"<![CDATA[" + ex.ToString() + "]]>" + "</error>" so our error result is not malformed..

    hmm.... how bout let's do

    String errorXml = "<error>" +"<![CDATA[" + ex.ToString() + "]]>" + "</error>" XmlDocument docError = new XmlDocument(); docError.LoadXml(errorXml); return docError.OuterXml

    There... we always get a well-formed xml.. good

  • (cs) in reply to Bosshog
    Bosshog:
    Claxon:
    In my defense, it's a program that only I use to speed up my workload and not a final product being sold / used by anyone else.

    Wow, that sounds great - can I buy it off you? :)

    Sure! I charge by the line though....

  • 28% Genius (unregistered) in reply to Vroomfundel
    Vroomfundel:
    The real WTF here is that they did it in VB.NET. I don't believe someone would do stuff like that in C#.

    As Dijkstra said, "It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration".

    Dijkstra said this about the orignal BASIC in the sixties that had only IF ... THEN GOTO as a control structure. The main problem with VB is that it is a bit verbose.

  • NeoMojo (unregistered) in reply to jamspoon
    jamspoon:
    The function doesn't return xml. It creates a string containing "<x>TextIn</x>" then chops off the xml tags and returns the result.

    however it would change "this < that" into "this < that"

    Basically it is a complicated way to escape text for xml.

  • wtf (unregistered)

    The real WTF is that in Javascript there is no function to htmlentities() a string, and if you do need to for some reason, your only choice is indeed creating a text node through the dom inside some other container node, then getting it's innerHTML.

    P.S. Ok I know this one is not about javascript, I'm just pointing out an even bigger WTF than the one in this story.

  • Shill (unregistered) in reply to wtf
    wtf:
    The real WTF is that in Javascript there is no function to htmlentities() a string, and if you do need to for some reason, your only choice is indeed creating a text node through the dom inside some other container node, then getting it's innerHTML.

    P.S. Ok I know this one is not about javascript, I'm just pointing out an even bigger WTF than the one in this story.

    Huh? First, let's separate JavaScript the language from the library for the particular implementation of JavaScript. Nobody expects a language to have a built in facility for escaping HTML so I assume you are complaining about the libraries supplied by the implementation.

    Most JavaScript is run within a browser. Why would you need a function to HTML-escape text within the browser environment? Presumably to display the text in the page. Since the best-practice way to display the text is to use the DOM and that already has the escaping built-in there is no need.

    If you are not in the browser, you are in an environment like MS JScript(.NET) or Netscape's server side JavaScript. Somebody has already posted how to do this in JScript. I'm not going to do the research for you, but I bet Netscape's server-side JavaScript has something to do this as well.

    I imagine TRWTF in this case is that you are using document.write().

  • (cs) in reply to foo
    foo:
    This is why all the good coding jobs are going to India.
    You call that a good coding job?

    Feh.

  • (cs) in reply to operagost
    operagost:
    Vroomfundel:
    The real WTF here is that they did it in VB.NET. I don't believe someone would do stuff like that in C#.

    As Dijkstra said, "It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration".

    I hear this from conceited programmers all the time, and I wonder whether he was talking about modern, structured Basics or the old Microsoft BASICs that were understandably limited because they ran on systems with fewer than 16 KB of RAM. I, unfortunately, had to learn BASIC on a home computer because they didn't let 7 year olds use timesharing on mainframes, but I did learn how to do structured DEC BASIC programming later on in college. I even have a book from the late 1980s called, strangely enough, "Strictly Structured BASIC".
    Ah, the memories. I was doing OK at an interview for a local job here in Birmingham, around twenty years ago, before I got stumped by the question "How would you write structured Basic?"

    Biting back the comment "by using a whole 'nother language," I thought about this.

    Me:"Gosubs?" Interviewer:No. Try again. Me:"Ummmm ... ASTs? Jump tables?" Interviewer:No. Try again. Me:"OK, I fail." It turned out that their entire concept of structured Basic revolved around two concepts, both of indubitable genius:

    (1) Write the original code with line numbers spaced at 20, not 10 (thus leaving far more room for patching) and (2) Ensure that every "module" starts on a line number N where N%1000 is zero.

    And no, on balance, I suspect that Dijkstra is right and you are wrong. There are always outliers, of course, and you might be one of them. Your comment that you "hear this from conceited programmers all the time" suggests that you are, at the very least, defensive, and indeed that you are still trying to defend your skills in Basic (VB, VB.Net, whatever) for no apparent reason.

    Welcome to the world of programmers. We don't mind people who've moved on from BBC Basic; we just object to cleaning up the mess left behind by 90% of the "Basic" community.

  • umm... (unregistered)

    90% of the comments here only point to the fact that Microsoft should stop giving away free IDEs...

  • /dev/null (unregistered)

    In an imperfect world, at least its organized and in functions. I am maintaining this website where all xml requests are generated via StringBuffers and processing thereof request is handled in the most clumsy fashion imaginable. Now this project commenced in 2006 so jaxb was available, or xmlbeans, or castor...but Bradley(Must be the troll from Dilbert) decided this was the best and quickest solution.

    Teaser code :

    public String formatRespXml(AbstractBean reqBean, String responseXML) { String formattedXML=""; String postTxn = reqBean.getPostTxn(); if (postTxn == null || postTxn.equals("")) { // retrieve user information to display on application screen String[] values = TxnFactory.getValues(responseXML, UserUtils.PATHS); formattedXML = TxnFactory.createTxnXML(values, UserUtils.NODES); }else{ StringBuffer formattedResponse = new StringBuffer();

        //get count
        int counter=0;
        //String count = Resources.getNodeValue(responseXML,"count(/z/r/ad)");
        String status = Resources.getNodeValue(responseXML, GeneralConstants.INTERFACE_STATUS_PATH);
        String matches = Resources.getNodeValue(responseXML,"/z/r/avr");
    
        Session session = reqBean.getSession();
        if(matches.equals("1")){
        	session.setAttribute(SessionConstants.ADDRESS_VERIFICATION_STATUS, GeneralConstants.ADDRESS_VERIFIED);
        }else{
        	session.setAttribute(SessionConstants.ADDRESS_VERIFICATION_STATUS, GeneralConstants.ADDRESS_NOT_VERIFIED);
        }
    
    
        if(!matches.equals("")){
        	counter = Integer.valueOf(matches);
        }
    
        formattedResponse.append("<resp><stat>");
        formattedResponse.append(status);
        formattedResponse.append("</status>");
        formattedResponse.append("<a>");
        formattedResponse.append(matches);
        formattedResponse.append("</a>");
    
        for(int i=1; i <= counter; i++)
        {
        	String var = "/z/r/ad[" +i+"]/";
        	String adl1 = Resources.getNodeValue(responseXML,var +"address-line1");
        	String adl2 = Resources.getNodeValue(responseXML,var +"address-line2");
        	String city = Resources.getNodeValue(responseXML,var +"postal-town");
        	String postcode = Resources.getNodeValue(responseXML,var +"postal-code");
        	String country = Resources.getNodeValue(responseXML,var +"country");
        	formattedResponse.append("<ad>");
        	formattedResponse.append("<adl1>");
                formattedResponse.append(GeneralConstants.CDATA_START);
        	formattedResponse.append(adl1);
                formattedResponse.append(GeneralConstants.CDATA_END);
        	formattedResponse.append("</ad1>");
    
        	formattedResponse.append("<adl2>");
        	formattedResponse.append(GeneralConstants.CDATA_START);
                formattedResponse.append(adl2);
                formattedResponse.append(GeneralConstants.CDATA_END);
        	formattedResponse.append("</adl2>");
    
        	formattedResponse.append("<c>");
                formattedResponse.append(GeneralConstants.CDATA_START);
        	formattedResponse.append(city);
                formattedResponse.append(GeneralConstants.CDATA_END);
        	formattedResponse.append("</c>");
    
        	formattedResponse.append("<pc>");
                formattedResponse.append(GeneralConstants.CDATA_START);
        	formattedResponse.append(postcode);
                formattedResponse.append(GeneralConstants.CDATA_END);
        	formattedResponse.append("</pc>");
    
        	formattedResponse.append("<cy>");
                formattedResponse.append(GeneralConstants.CDATA_START);
        	formattedResponse.append(country);
                formattedResponse.append(GeneralConstants.CDATA_END);
        	formattedResponse.append("</cy>");
        	formattedResponse.append("</ad>");
        }
        formattedResponse.append("</resp>");
        formattedXML = formattedResponse.toString();
        }
    
        return formattedXML;
    }
    

    I believe with JAXB the code base could be reduced by 40%.

  • Dave (unregistered)

    "What on Earth do we need XML-Navigation and Nodes for," they'll often rhetorically say,

    I don't think that word means what you think it means!

  • Henry Miller (unregistered) in reply to Stephen
    Stephen:
    We've got patents on this so don't any of you cowboys even think about ripping us off!

    At one job they asked if we had anything patentable, and I seriously considered submitting our stupid redundancy scheme (which wasn't as redundant as it looked) just so nobody else could do something that stupid without getting sued. I didn't though.

  • Xanadu (unregistered)

    The real wtf here is that they used .net

  • v (unregistered)
       dom = Nothing
       Node = Nothing
    

    I hate guys who set local variables to null in finally.

  • Coffe (unregistered) in reply to Stiggy

    No the real WTF is using Dotnet for string manipulation, way to fancy.

  • Latte (unregistered) in reply to Josh
    Josh:
    Ah, but don't forget:
    Catch ex As Exception
    
            Return "<error><![CDATA[" + ParseText( ex.ToString() ) + "]]></error>"
    
        Finally

    Since you don't know what's in ex.ToString()....

    You mean like "]]"? Using CDATA sections to escape anything unknown i a common WTF.

Leave a comment on “Far Too Fancy”

Log In or post as a guest

Replying to comment #:

« Return to Article