• Rolf (unregistered)

    Hmm

    #include <string.h>

    void addhttp( char *url ) { char http[8] - "http://" (somehow find if it has http or not. I'm not sure how now.) url = strcat( http, url );//not sure if I got this right. :P }

    Yeah captcha got it right with ewww...

  • (cs) in reply to Volmarias
    Volmarias:
    This is no WTF at all, gentlemen! Much like saying "Richard Dawkins" three times in front of your mirror in the dark causes the Dark Lord of Atheism to appear, demanding a sandwich, using the despicable + operator to append one string to another invokes the horrible StringBuilder class! This lazy and ignorant class will naïvely add one string to another, with no thought at all of whether the two strings fit together! Why, with no consideration of breeding or standing, it is no wonder that programs that utilize this anarchist class end up horribly buggy and inefficient, unable to recognize their place next to their betters! This code snippet, on the other hand, wisely places one mere character next to the other, reserving space such that the two do not mingle. This snippet, gentlemen, preserves the purity of the urlString from the mongoloid and frankly simian apings of protocolString, keeping it pure and chaste.

    Gentlemen, when strings can co-mingle freely, our society will be ruined and our downfall terrible to behold, as bastard children will run about the streets, attempting to stick their periods and commas in anything they run across. And that, dear sirs, is not a world I wish to live in.

    You win, thread over.

  • Dink (unregistered)

    I'm surprised he didn't reverse the slashes.

  • PC Paul (unregistered) in reply to Marc
    Marc:
    omg

    !gfmo, shurely?

  • racuna (unregistered)

    !ftw

  • iMalc (unregistered)

    woW

    Hmm, writing that backwards wasn't so effective...

  • (cs) in reply to strictnein
    strictnein:
    Brilliant!

    I do think, however, that this was more a fun little exercise for the original programmer than anything else.

    Some people shouldn't be allowed to have this kind of fun.

  • dkf (unregistered) in reply to brian
    brian:
    this is the most clever piece of code i've seen posted. It's horrible, but still clever.
    Agreed. It's done by someone with too much time on their hands, and no sense of what the cost of such an action would be. As such, it's a classic WTF. Why? Because of the sheer quantity of bumbling management incompetence required to let something as stupidly inefficient go into production. I'm sure I could invent something worse, but not without introducing something obviously stupid and irrelevant (e.g. random numbers).

    (I wonder if this was the Geoff Lane I know...)

    Captcha: alarm (yes, it is alarming!)

  • brendan (unregistered)

    this is another one who can't read documentation. What's the problem with this

    private static const String PROTOCOL = "http://"; static public string PrependProtocol(string urlString){ return PROTOCOL + urlString; // although to be 100% correct // return (urlString.toLowerCase().startsWith(PROTOCOL) ? urlString: // PROTOCOL + urlString); }

  • (cs) in reply to -
    -:
    This must have been made by someone who was just bored. The code does a lot of "advanced" stuff and if a programmer knows how to do that, (s)he also knows about string concatenation.
    You know I used to believe that back when I was naive too. I've seen it more than once, and even in good programmers.
  • anonymous guy (unregistered)

    Perl hackers have a name for this sort of thing: TMTOWTDI

  • (cs) in reply to anonymous guy

    !FTW .gnimmargorp denrael eh erehw rednow I .gnirts deirw a saw tahT .mih no serifkcab ti epoh I

    .sdrawkcab & detrevni si tsop elohw sihT

  • Bay (unregistered)

    and now I know that "What the F---" (WTF) backwards is "For the Win" (FTW). No wonder!

  • iw (unregistered)

    I guess some people's brains are hardwired to think in Polish Notation.

  • (cs) in reply to Rolf
    Rolf:
    #include <string.h>

    void addhttp( char *url ) { char http[8] - "http://" (somehow find if it has http or not. I'm not sure how now.) url = strcat( http, url );//not sure if I got this right. :P }

    Please don't ever try to write C again.

  • Frank Lloyd Wright (unregistered) in reply to Old Wolf

    Fantatsic - o!

    Google doesn't bomb out when searching for that function name, maybe you found a GWTF and they corrected it promptly?

    CAPTCHA: tacos because everyone knows I'm SO Cat.

  • (cs) in reply to Stephen Redd
    Stephen Redd:
    Volmarias:
    using the despicable + operator to append one string to another invokes the horrible StringBuilder class!

    er.... no, the + operator doesn't have anything to do with StringBuilder in C#.

    Whoopsie, was thinking of Java.

  • TK (unregistered)

    Well, it is quite enterprisey. Just needs more abstraction levels and XML.

  • Jon Skeet (unregistered) in reply to Prefect
    Prefect:
    Stephen Redd:
    Volmarias:
    using the despicable + operator to append one string to another invokes the horrible StringBuilder class!

    er.... no, the + operator doesn't have anything to do with StringBuilder in C#.

    It does, but only if you are trying to concatenate about 4 or more strings in one statement that way.

    Hmm... I haven't seen that. Which C# compiler are you talking about? (IIRC, the spec doesn't specify how the values will be concatenated, so a compiler could use StringBuilder if it wanted to, but I haven't seen it.)

    Try this:

    class Test { static void Main() { string a = "a"; string b = "b"; string c = "c"; string d = "d"; string e = "e"; string f = "f"; string g = "g"; string h = "h"; string i = "i"; string j = "j"; string k = "k"; string l = "l";

        string x = a+b+c+d+e+f+g+h+i+j+k+l;
    }
    

    }

    Using the MS C# compiler (1 and 2) that uses String.Concat.

    Jon

  • Noooooooooo! (unregistered)

    How can someone use a word like "prepend" and write such code? Maybe exhausted from searching the dictionary...

  • Keith (unregistered) in reply to Volmarias
    Volmarias:
    Stephen Redd:
    Volmarias:
    using the despicable + operator to append one string to another invokes the horrible StringBuilder class!

    er.... no, the + operator doesn't have anything to do with StringBuilder in C#.

    Whoopsie, was thinking of Java.

    StringBuilder? StringBuffer.

  • Jon Skeet (unregistered) in reply to Keith
    Keith:
    Volmarias:
    <snip>

    Whoopsie, was thinking of Java.

    StringBuilder? StringBuffer.

    Not as of Java 1.5. StringBuilder is the unsynchronized version of StringBuffer, basically, and is used (at least by Sun's compiler) for string concatenation. About time, too - has anyone ever used a StringBuffer in multiple threads?

    Jon

  • Daniel (unregistered) in reply to Dink
    Dink:
    I'm surprised he didn't reverse the slashes.

    This was one of the best replies ever.

    Btw I think this is a brilliant WTF...kinda reminds me of the good old IsTrue days

  • (cs)
  • vP (unregistered) in reply to Rolf
    Rolf:

    void addhttp( char *url ) { char http[8] - "http://" (somehow find if it has http or not. I'm not sure how now.) url = strcat( http, url );//not sure if I got this right. }

    Strings and C are notoriously tricky, so your mistakes are easy to understand.

    You don't check that url pointer points to large enough a buffer. Thus blindly adding characters to it may cause buffer overflows. strcat() won't allow you to use the same variables as both source and destination. It doesn't do any bounds check either.

  • Philip (unregistered) in reply to Neal
    Neal:
    Anyone tried to do a Google code search on:

    PrependProtocol(string urlString)

    I get "Your search term - - could not be parsed: missing ) (PrependProtocol(string)"

    is this a Google wtf, I've never seen an unparsable search on Google?

    Captcha: bathe - yeah, I feel like I need a bath after this snippit

    Google codesearch queries are actually regular expressions. To search for a string containing paranthesis, you need to escape them with a backslash.
  • bRain Man (unregistered) in reply to Steeldragon
    Steeldragon:
    !FTW .sdrawkcab & detrevni si tsop elohw sihT

    WTF? I was able to read all that reversed text without any trouble at all? Sign of a backwards brain? Slhoud I wrory?

    -L

  • (cs) in reply to vP
    vP:
    Rolf:

    void addhttp( char *url ) { char http[8] - "http://" (somehow find if it has http or not. I'm not sure how now.) url = strcat( http, url );//not sure if I got this right. }

    Strings and C are notoriously tricky...

    Agreed, though most people make them harder than they should be. All that's necessary is to read the standard and, as Dan Pop was fond of saying, engage your brain. If you're not willing to do those to things, stay the hell away from C.

    vP:
    You don't check that url pointer points to large enough a buffer.

    Since nothing gets appended to the object pointed to by "url", that hardly matters.

    vP:
    strcat() won't allow you to use the same variables as both source and destination.

    strcat always uses the same object as its first source operand and its destination. Using objects that overlap for the two source operands produces undefined behavior, but this code manages to avoid that particular error.

    vP:
    It doesn't do any bounds check either.

    That's obvious, if you understand C, but correct. So, hey, you get one out of three.

    Here's what's actually wrong with the posted code:

    void addhttp( char *url )

    The object pointed to by "url" is not modified; it should be const-qualified. Of course, since the function ought to have side effects, either the object pointed to by url should be modified, or the function's return type should be "char *" and it should allocate a new string.

    If the function is intended to modify the object pointed to by url, some might also want the function to take a size_t parameter containing the size of that object, so the function would know whether there's room for the result. Of course the resulting string is always a fixed amount larger than the input, so the function could just require that the caller supply a sufficiently large buffer. I take no position on the matter in this case, since I wouldn't implement this functionality in this manner in the first place.

    char http[8] - "http://"

    Minus instead of equals. No trailing semicolon. Unnecessary size specification on the "http" array, since it's the same size as the initializer.

    url = strcat( http, url );//not sure if I got this right.

    If url is null, you've just invoked undefined behavior. If the string pointed to by url has nonzero length, you've just overflowed the http object, and invoked undefined behavior. Assigning to url only changes the value of the pointer in this function; it has no side effects, since the function then returns.

    (We'll assume this is C99, or a C++ implementation being used as a halfassed C implementation, and allow the // comment delimiter.)

    But #include <string.h> was right, as were the lines with the curly braces, so the defect rate, measured by SLOC, was only around 50%.

  • blu.knite (unregistered) in reply to Steeldragon
    Steeldragon:
    !FTW .gnimmargorp denrael eh erehw rednow I .gnirts deirw a saw tahT .mih no serifkcab ti epoh I

    .sdrawkcab & detrevni si tsop elohw sihT

    ...ti ot em taeb uoy tub ...tsrif sdrawkcab dna detrevni gnitsop tuoba gnikniht no flesym etalutargnoc ot tuoba tsuj saw I

    erus ton m'I ...ymmuy :ahctpac

  • Joshua Norman (unregistered)

    "This is either madness... or brilliance!"

    ("Remarkable how often those two traits coincide.")

  • Chris (unregistered) in reply to strictnein
    strictnein:
    Brilliant!

    I do think, however, that this was more a fun little exercise for the original programmer than anything else.

  • Chris (unregistered) in reply to Chris
    strictnein:
    Brilliant!

    I do think, however, that this was more a fun little exercise for the original programmer than anything else.

    Don't you mean "Brillant!" ?

    (sorry about the double post, I had a brillant moment myself!)

    Chris

  • Anonymous (unregistered) in reply to blu.knite
    blu.knite:
    Steeldragon:
    !FTW .gnimmargorp denrael eh erehw rednow I .gnirts deirw a saw tahT .mih no serifkcab ti epoh I

    .sdrawkcab & detrevni si tsop elohw sihT

    ...ti ot em taeb uoy tub ...tsrif sdrawkcab dna detrevni gnitsop tuoba gnikniht no flesym etalutargnoc ot tuoba tsuj saw I

    erus ton m'I ...ymmuy :ahctpac

    (: .em rof gnipyt-esrever eht od ot 'cat' gnisu ot gnitroser m'I .ylkciuq sa stsop hcus epyt t'nac I taht si FTW rehto ehT

    D: !stsop lamron sa tsaf sa tsomla meht daer I .sdia yna tuohtiw yltcerid stsop eseht daer nac I !FTW

  • Mr Steve (unregistered)

    !!!LFOR

    daehkcid a tahw

  • (cs) in reply to Anonymous
    Anonymous:
    (: .em rof gnipyt-esrever eht od ot 'cat' gnisu ot gnitroser m'I .ylkciuq sa stsop hcus epyt t'nac I taht si FTW rehto ehT

    ?etisoppo eht siht sI. 'tac' fo draeh ev'I ?'cat' s'tahW

  • alexandru savu (unregistered)

    Incredible code. Really negative iq :)

  • Skye (unregistered)
  • Chad (unregistered) in reply to Prefect

    my head just caved in

  • E- (unregistered)

    oh i get it! the browsers add http for you. that's really funny that he didn't need to do that catnation

  • Marcelo (unregistered) in reply to strictnein

    That was my second impression, and I strongly believe in it.

  • Tone (unregistered) in reply to Anonymous
    Anonymous:
    I like how the google ads on the side are for such relevant items as 'Bass Strings' and 'String Cheese'.

    I Laaaauuuugggghed!

  • puz (unregistered) in reply to RON

    Gross. Totally un-greppable

  • Will (unregistered)

    "When your only tool is a hammer, everything looks like a nail."

    Well, at least he got the job done. Granted, there should have been some checks to see it the string already had "http://", but if it works...

  • ic (unregistered)

    Was Brian an old asm coder? Then it is right, but wrong in java.

  • aju (unregistered)

    Being to lazy to learn any kind of code, and too cheap to pay for someone to do it for me, I think I know what happened. When I borrow (steal) someone else's code I often make it do things it was never meant to do. So you find code that maybe appends one letter to the front of something, you really don't know how it works, or why, and try to make it append many letters. It comes out backwards, no problem, I'll just reverce my input. I still don't know what I am doing, but it works.

    AJU,I'm not a coder, but I'm related to one.

  • Random (unregistered) in reply to scubasteve

    //return (urlString.reverse() + "//:ptth").reverse();

    even better, (urlString.reverse() + "http://".reverse()).reverse();

    of course you can swap arbitrary blocks without copying this way, i.e. reverse a, then reverse b, then reverse ab. Someday some weenie is going to ask about it on a "programming quiz" for a job application, so it's a good one to know.

  • Jay Liew (unregistered)

    Hey take it easy -- we're in 2007 but I guess some of us still get paid by the number of lines of code you write!!

  • Joe Blow Jr Programmer (unregistered)

    Come on guys - this is obviously done to waste time or something. A guy who knows about enumerators, padding, etc., will certainally know concat.

  • mike (unregistered) in reply to brian
    brian:
    this is the most clever piece of code i've seen posted. It's horrible, but still clever.

    and your name is "brian"! cooincidence ?

  • (cs) in reply to bRain Man
    bRain Man:
    Steeldragon:
    !FTW .sdrawkcab & detrevni si tsop elohw sihT

    WTF? I was able to read all that reversed text without any trouble at all? Sign of a backwards brain? Slhoud I wrory?

    -L

    No, you should spellcheck ...

Leave a comment on “Some Call it Concatenation”

Log In or post as a guest

Replying to comment #:

« Return to Article