• Justn (unregistered)

    "So, why did you do this?"

    "...in the name of science; I thought it was obvious."

  • Anonymous Paranoiac (unregistered)

    All together now, "TRTWF is..."

    CAPTCHA: "minim" a fashion term referring to low-rider jeans which contain the minimum amount of denim.

  • someGuy (unregistered)

    you know, I thought the meme of being 'frist/first' had finally died off... now I see the mods are actually deleting those entries... good on ya, guys

  • J (unregistered)

    The second "if" is superfluous, but otherwise the code is not overly WTF-y.

    if (substr($string,0,7) != "http://" ) { $string = "http://" . $string; }

    $string = substr_replace($string,"",0,7);

    Sure, it could still be shortened into just
    if (substr($string,0,7) = "http://" ) { $string = substr_replace($string,"",0,7); }
    or even better,
    if (substr($string,0,7) = "http://" ) { $string = substr($string,7); }
    (assuming that this is a snippet of PHP)

    The purpose is clear - removing the http:// prefix. To credit of the author of the code... it seems to do that (as long as the string is in lowercase).

  • Andrew (unregistered)

    This code must have been from Aperture Science.

  • Captain Obvious (unregistered)

    This would make sense if a user was expected to copy/paste a url from their address bar to share with another user. To create a link in html, http:// must be there or else it will be interpreted as a relative path to the domain. You have to trust the users to not inject crap which is easier if each post is linked to a real name.

  • (cs)

    So this is the Hokey Cokey for the modern age?

    "You put the http:// in "You put the http:// out "In, out, in, out, "You shake it all about!"

  • Captain Obvious (unregistered) in reply to Captain Obvious

    So I only read the first one. They probably don't appear right after each other, or there is code to put in https after the second.

  • NaN (Not a Name) (unregistered) in reply to J
    J:
    The second "if" is superfluous,

    I think the word you want is nefarious

  • (cs) in reply to Captain Obvious

    For readability, I stripped out the line numbers as supplied by the submitter- and these were directly in sequence as shown here.

  • TheSHEEEP (unregistered)

    I don't see a WTF here.

    This is a built in unit test to make sure the code removes the leading "http://".

  • (cs) in reply to Anonymous Paranoiac
    Anonymous Paranoiac:
    All together now, "TRTWF is..."

    CAPTCHA: "minim" a fashion term referring to low-rider jeans which contain the minimum amount of denim.

    Actually, TRWTF is the number of unregistered users who haven't figured out that the captchas are Latin words.

  • Flyover (unregistered) in reply to PedanticCurmudgeon
    PedanticCurmudgeon:
    Anonymous Paranoiac:
    CAPTCHA: "minim" a fashion term referring to low-rider jeans which contain the minimum amount of denim.
    Actually, TRWTF is the number of unregistered users who haven't figured out that the captchas are Latin words.

    WHOOOSH

    sorry, couldn't resist

    Captcha: tation - what you do when you medi-tate in a corner of your (medi)tation mat.

  • (cs) in reply to Captain Obvious
    Captain Obvious:
    So I only read the first one. They probably don't appear right after each other, or there is code to put in https after the second.

    Why would you think that, when it's a so much more obvious WTF when they're together?

    I once saw a 400+ line section of a COBOL program that laboriously computed the value of TOTAL-HOURS, followed immediately by:

    MOVE ZERO TO TOTAL-HOURS

    ...and believe me, you know the meaning of WTF after you've spent 45 minutes trying to figure out what that section of code does: Only to discover that the only resulting value is zeroed.

  • (cs) in reply to Steve The Cynic
    Steve The Cynic:
    So this is the Hokey Cokey for the modern age?

    "You put the http:// in "You put the http:// out "In, out, in, out, "You shake it all about!"

    HOKEY COKEY? You don't even know the lyrics! It's hokey pokey, and the third line is "You put the http:// in and" Geez! Let me provide a link... oh... it's a difference in location, it seems, and hokey cokey is valid... ok, well... um... nevermind.
  • Dave (unregistered)

    WTF GNDN style!

  • F (unregistered) in reply to PedanticCurmudgeon
    PedanticCurmudgeon:
    Anonymous Paranoiac:
    All together now, "TRTWF is..."

    CAPTCHA: "minim" a fashion term referring to low-rider jeans which contain the minimum amount of denim.

    Actually, TRWTF is the number of unregistered users who haven't figured out that the captchas are Latin words.

    TRWTF is the number of users who haven't figured out that some of them are not actually Latin words, but slightly mangled versions of Latin words.

  • (cs) in reply to F
    F:
    PedanticCurmudgeon:
    Anonymous Paranoiac:
    All together now, "TRTWF is..."

    CAPTCHA: "minim" a fashion term referring to low-rider jeans which contain the minimum amount of denim.

    Actually, TRWTF is unregistered users.

    TRWTF is the number of users who haven't figured out that some of them are not actually Latin words, but slightly mangled versions of Latin words.

    There, fixed. Better now?

  • Anonymous (unregistered) in reply to someGuy
    someGuy:
    you know, I thought the meme of being 'frist/first' had finally died off... now I see the mods are actually deleting those entries... good on ya, guys

    Censorship is not OK.

  • Anonymous (unregistered) in reply to Anonymous
    Anonymous:
    Censorship is not OK.

    Think of it as a human Spam filter.

  • Lucy M (unregistered)

    ...what.

    I'm a newish programmer, so my reading of that went something like:

    "what is it doing?" "wait, what? it can't be doing that" "no, it IS doing that" "WHY is it doing that?!"

    [baffled]

  • Robert Hanson (unregistered)

    It is common to reduce a problem to one you've already solved. I imagine the original code removed the http://.

    Later, someone noticed that sometimes the string did not begin with http://.

    "I know, if it does not begin with http://, add it. Then all the strings passed in will begin with http://, and we already handle that case."

    My father tells a story: A mathematician wants to read a book, but the room he is in is dark, and the light is off. In order to read, he turns on the light.

    The next day, the mathematician wants to read a book, and the light is on in the room. He first turns off the light, reducing the problem to the one he solved the previous day.

  • Martin (unregistered) in reply to J
    J:
    The purpose is clear - removing the http:// prefix. To credit of the author of the code... it seems to do that (as long as the string is in lowercase).

    Let's just hope none of their URL's use https, either.

  • (cs) in reply to TheSHEEEP
    TheSHEEEP:
    I don't see a WTF here.

    This is a built in unit test to make sure the code removes the leading "http://".

    Sure, but how can we be positive that the first bit of code actually puts in a leading "http://" to remove? We need to put in a unit test for that as well, to make sure our second unit test is working correctly!

    Oh, yeah, And then we need to remove it before we put the code in production. I always forget that part.

  • quack (unregistered) in reply to Steve The Cynic

    Did we already forget that "premature optimization is the root of all evil"?

    The hardest thing to code around is a bad client or manager. Imagine coding a medium-complexity desktop app for a web designer without the luxury of a prototype to throw away...

  • me (unregistered)
    you know, I thought the meme of being 'frist/first' had finally died off... now I see the mods are actually deleting those entries... good on ya, guys

    OK, so I see it falls to me to make the obvious and not particularly funny joke:

    if (substr($string,0,5) == "frist" ) {
         $string = substr_replace($string,"",0,5);
    }
  • (cs) in reply to Flyover
    Flyover:
    PedanticCurmudgeon:
    Anonymous Paranoiac:
    CAPTCHA: "minim" a fashion term referring to low-rider jeans which contain the minimum amount of denim.
    Actually, TRWTF is the number of unregistered users who haven't figured out that the captchas are Latin words.

    WHOOOSH

    Actually, a minim is a semi-obsolete term for a half-note in music notatation.

  • (cs)

    GN DN Do doo dee do do. GN DN Do do dee do. GN DN Do do dee do do dee do do do do-do-doo

  • foo2 (unregistered) in reply to Anonymous
    Anonymous:
    someGuy:
    you know, I thought the meme of being 'frist/first' had finally died off... now I see the mods are actually deleting those entries... good on ya, guys

    Censorship is not OK.

    Nor is being a dickhead (boring & predicable at that).

  • (cs)
    if (substr($string,0,7) == "http://" ) {
         $string = substr_replace($string,"gasstation://",0,7);
    }
    

    Ladies and gentlemen......I present to you, Apple Maps.

  • (cs)

    Also, this code will be great with super-short URLs:

    http://thenextweb.com/2009/12/06/worlds-shortest-url-shortener/

    Definitely not going to throw an exception, especially an index out of range one...

  • Cap'n Spanky (unregistered) in reply to Steve The Cynic
    Steve The Cynic:
    So this is the Hokey Cokey for the modern age?

    "You put the http:// in "You put the http:// out "In, out, in, out, "You shake it all about!"

    I heard that the author of the Hokey Cokey lyrics died recently, and that they'd had a hard time getting him into his coffin. It all started when they put is left foot in.
  • RFmich (unregistered)

    I talked with the author of that piece of code he told me "Hey back off ... I'm a scientist"

  • Spewin Coffee (unregistered)

    When an engineer is in a hurry, the extra if-statements don't really hurt anything. It makes sense if only just a bit verbose. A real TDWTF would have been if this code parsed each character of "http://" individually, implemented their own string comparison routine, AND broke on parsing "https://" URLs.

    TRWTF is making everyone look up "GNDN" on the Internets. References to "Jeffries tubes" are going to plague us in the near future.

  • (cs) in reply to SCSimmons
    SCSimmons:
    TheSHEEEP:
    I don't see a WTF here.

    This is a built in unit test to make sure the code removes the leading "http://".

    Sure, but how can we be positive that the first bit of code actually puts in a leading "http://" to remove? We need to put in a unit test for that as well, to make sure our second unit test is working correctly!

    Oh, yeah, And then we need to remove it before we put the code in production. I always forget that part.

    But wait: If we remove it before we put the code in production, that will invalidate all the unit tests! So I guess we'll have to put it back, run all the unit tests again, take it out, put it back...

  • (cs) in reply to someGuy
    someGuy:
    you know, I thought the meme of being 'frist/first' had finally died off... now I see the mods are actually deleting those entries... good on ya, guys

    Oh, my! How will we know we're reading TDWTF comments?

  • (cs) in reply to Robert Hanson
    Robert Hanson:
    My father tells a story: A mathematician wants to read a book, but the room he is in is dark, and the light is off. In order to read, he turns on the light.

    The next day, the mathematician wants to read a book, and the light is on in the room. He first turns off the light, reducing the problem to the one he solved the previous day.

    You know that invites this, right?

    A [computer programmer] wants to read a book, but the room he is in is dark, and the light is off. In order to read, he [writes a routine that] turns on the light.

    The next day, the [computer programmer] wants to read a book, and the light is on in the room. He first [writes a routine that] turns off the light, [so that he can reuse the code from] the previous day.

  • Techpaul (unregistered) in reply to Coyne
    Coyne:
    Robert Hanson:
    My father tells a story: A mathematician wants to read a book, but the room he is in is dark, and the light is off. In order to read, he turns on the light.

    The next day, the mathematician wants to read a book, and the light is on in the room. He first turns off the light, reducing the problem to the one he solved the previous day.

    You know that invites this, right?

    A [computer programmer] wants to read a book, but the room he is in is dark, and the light is off. In order to read, he [writes a routine that] turns on the light.

    The next day, the [computer programmer] wants to read a book, and the light is on in the room. He first [writes a routine that] turns off the light, [so that he can reuse the code from] the previous day.

    All I can say is Shampoo Rinse Repeat

  • The captchas come from the Lorem Ipsum text (unregistered) in reply to someGuy
    someGuy:
    you know, I thought the meme of being 'frist/first' had finally died off... now I see the mods are actually deleting those entries... good on ya, guys
    Yes, and every time I post an animated gif or an unfunny one-line response they delete it too.

    It's like they don't want this place to become 4chan.[image]

    (they should at least fix akismet, seeing as there are at least three comments per story complaining about it. Fucking akismet.)

  • Bill (unregistered)

    So why isn't your post deleted yet? Or this one for that matter? Yes, I posted a lame post, just so they'd delete it. I want my stuff to be deleted. I never get featured, but at least this way, I'll know somebody somewhere was indirectly aware of my pathetic existence for a brief moment.

    Or, as an even worse insult, they could ignore me completely and leave this here.

    What to do? What to do???

  • Captcha:erat (unregistered) in reply to Bill

    Here, I replied to you.

  • Martin (unregistered)

    GNDN is by the way a Star Trek reference - it means "goes nowhere, does nothing".

    http://en.memory-alpha.org/wiki/Power_relay

  • Meep (unregistered) in reply to Anonymous
    Anonymous:
    someGuy:
    you know, I thought the meme of being 'frist/first' had finally died off... now I see the mods are actually deleting those entries... good on ya, guys

    Censorship is not OK.

    Sure it is. TDWTF is a private entity and has every right to censor or alter any content hosted on their services, provided the original authors' gave them license to do so.

    That is their freedom of expression. Rights work both ways, after all.

  • Juan (unregistered)

    This is a "letter of the law vs spirit of the law" thing...

    Requirements: 1.3.4.1) The input string shall be a valid URL, and shall be validated to ensure that it contains the protocol prefix. .... 3.5.6.3) Before being used, all validated URL strings shall have the "http://" prefix stripped....

    etc.

    THis person probably just had requirements that seemed to conflict....so they did the sensible thing and (rather than arguing with the BA who wrote the requirements) implemented both to the best of his ability.

  • (cs) in reply to cellocgw
    cellocgw:
    Flyover:
    PedanticCurmudgeon:
    Anonymous Paranoiac:
    CAPTCHA: "minim" a fashion term referring to low-rider jeans which contain the minimum amount of denim.
    Actually, TRWTF is the number of unregistered users who haven't figured out that the captchas are Latin words.

    WHOOOSH

    Actually, a minim is a semi-obsolete term for a half-note in music notatation.

    Nowhere near obsolete in Europe, only in the US where the language was terminally simplified by Websterites.

  • (cs) in reply to RFmich
    RFmich:
    I talked with the author of that piece of code he told me "Hey back off ... I'm a scientist"
    "... okay no worries, we'll take this slowly, then."
  • (cs) in reply to Bill
    Bill:
    So why isn't your post deleted yet? Or this one for that matter? Yes, I posted a lame post, just so they'd delete it. I want my stuff to be deleted. I never get featured, but at least this way, I'll know somebody somewhere was indirectly aware of my pathetic existence for a brief moment.

    Or, as an even worse insult, they could ignore me completely and leave this here.

    What to do? What to do???

    Oh fuck off, wanker.

    (Sorry, couldn't resist revisiting an old meme.)

  • Tim (unregistered)

    Whilst obviously not ideal, this is a case of data normalisation. Get all the data into a normalised form (in this case, with a leading "http://") and then you can manipulate it safe in the knowledge that it's not going to blow up.

    That of course assumes that you get the normalisation correct. The code as shown could for example produce URLs of the form "http://https://example.com".

  • Ken (unregistered)

    Logic is hard. You shouldn't expect all programmers to be good at it.

  • (cs)

    TRWTF is processing URLs manually instead of using the URL parsing library that comes with your language.

Leave a comment on “The GNDN Protocol”

Log In or post as a guest

Replying to comment #:

« Return to Article