• Ollo (unregistered) in reply to noland
    noland:
    Severity One:
    In Perl, it doesn't really matter if you don't do it the "appropriate" way, because to do any task in Perl, there are at least five ways to do it, all equally inappropriate. The only real difference is the number of years added in purgatory.

    Not really sure what this is attempting to suggest.

    $name =~ s/[^\w\d]/_/g;

    Any more elegant way to this? Any other language that hasn't derived from this in one way or the other?

    I guess there's no more elegant way to do this (assuming "elegant" means with the least possible amount of characters). My second (or third) assumption is that there's also no more obfuscated way to do this.

    [repost: bah, didn't click "quote". Also, boozed]

  • (cs) in reply to Xarthaneon the Unclear
    Xarthaneon the Unclear:
    Nagesh:
    Brain damage:
    Perl written by C coders.
    You're lucky. I once had to deal with FoxPro written by COBOL coders.

    I am dealing with java servlets written by VB programmers.

    Underlined is TRWTF. In most circumstances, to boot. I've never understood why, exactly...

    Clearly you have never worked with girl programmers!

  • FTFY (unregistered) in reply to Anon
    Anon:
    And this is why MySQL is so fucking stupid.

    I played around with it once connecting to a MySQL database. It helpfully has a "mysql_escape_string" function for, well, escaping strings. But if you look at the manual pages, you see it's deprecated for "mysql_real_escape_string". WTF!?!

    If "mysql_escape_string" doesn't work, why not just fucking fix it?

    FTFY. (mysql_escape_string and mysql_real_escape_string are both MySQL API functions. PHP did not invent these names)

  • Lazy Boy (unregistered)

    Once again this proves why lazy developers are the best. Any lazy developer would first google for an existing library function that does what he wants before rolling his own.

    Ok I admit in this case common sense would have been enough too as the problem is so general and must so obviously occur all the time that any non-moron would know such a function must exists.

    But php is to blame too because if functions were actual methods or at least named in a consistent and sane way, IDE autocomplete would probably make a google search unnecessary.

  • Valued Service (unregistered) in reply to Seriously?
    Seriously?:
    This is the not coolest thing I have ever read on TDWTF ever. WTF does gender have to do with anything.

    Gender has to do with a lot. Men and women think differently. How they approach problems is different. Whether that means men or women produce better code is up for debate, because I think as long as the code functions well, is logical, and is maintainable by the group working on it, you're doing it right. Interestingly enough, most of the women I met that were programmers were distinguishable from the average woman in how they thought. They thought more like men. Don't confuse a rainbow of personality amongst the genders as a lack of distinction.

    To say that there's no difference between genders is intellectual deceit. You can't eliminate the physical and mental differences just by believing they aren't there hard enough, even if that's what modern secular humanism teaches.

    The big thing here, is that there are significantly less women in the programming profession, and it's not because there is some barrier to entry, it's just a lack of preference in women to be employed as a programmer. So it IS a significant event to see a woman programmer.

    Just as you shouldn't assume a woman programmer is inferior, you shouldn't assume all women are capable programmers.

  • Gerry (unregistered) in reply to Nagesh
    Nagesh:
    Xarthaneon the Unclear:
    Nagesh:
    Brain damage:
    Perl written by C coders.
    You're lucky. I once had to deal with FoxPro written by COBOL coders.

    I am dealing with java servlets written by VB programmers.

    Underlined is TRWTF. In most circumstances, to boot. I've never understood why, exactly...

    Clearly you have never worked with girl programmers!

    I have. MOst of thenwere good - if anything a slightly higher percentage than male programmers. However the sample size is small.

  • (cs)

    In my experience, code like this isn't written, it grows. Someone tried something. Maybe it worked and later was modified. And modified. And modified. Perhaps by "the new guy" - someone different each time who was too scared to change much (if it ain't broke, don't fix it). Or maybe it didn't work and they kept trying stuff until it did. Whatever the reason, I'm sure this isn't how it started out.

  • (cs)

    And that is why you always RTFM.

  • Curtis P (unregistered) in reply to noland
    noland:
    Note: The code above is derived from R.P.'s suggestion in the HTML-comment. Better:
    $name =~ s/\W/_/g;
    ; (We have Perl for that.)

    Not enterprisey enough.

  • Bill C. (unregistered) in reply to CodeBeater
    CodeBeater:
    <?php $string = "Not a single fuck was given that day"; $var = 0; while ($var != count($string)) { echo($string[$var]) } ?>
    So that's why everyone hates PHP. Wow, me too, I hope I never get stuck with it.
  • Ahern Ya (unregistered) in reply to foxyshadis
    foxyshadis:
    corroded:
    We're talking about PHP. Split was deprecated in 5.3.0.

    This is a community of pedants, after all.

    This is a community of assholes who feel better by calling themselves pedants. To prove I'm one, can you point out where PHP is mentioned in the first paragraph? I'd hate to see your software if it makes those kind of assumptions everywhere.
    "...people don't know that there’s a better way"

    Definitely PHP

  • Martin (unregistered)

    Extra WTF points for the `broken' spacebar.

  • (cs) in reply to Valued Service
    Valued Service:
    Interestingly enough, most of the women I met that were programmers were distinguishable from the average woman in how they thought. They thought more like men.
    You've made one mistake there: thinking that most men think like programmers. By and large, they don't (and we have the multitude of WTFs to prove it). Programmers think like programmers, whether they're men or women.
  • Jibble (unregistered) in reply to noland
    noland:
    $name =~ s/[^\w\d]/_/g;
    Any more elegant way to this?

    That's "elegant"?

  • corroded (unregistered) in reply to foxyshadis
    foxyshadis:
    corroded:
    We're talking about PHP. Split was deprecated in 5.3.0.

    This is a community of pedants, after all.

    This is a community of assholes who feel better by calling themselves pedants. To prove I'm one, can you point out where PHP is mentioned in the first paragraph? I'd hate to see your software if it makes those kind of assumptions everywhere.

    Join and split are both functions not found in every programming language, they are in some but not all. When the article is directly referencing PHP code in it, it's fairly safe to assume it's talking about PHP. Unless you're an idiot or something.

  • noland (unregistered) in reply to Jibble
    Jibble:
    noland:
    $name =~ s/[^\w\d]/_/g;
    Any more elegant way to this?

    That's "elegant"?

    Yep. Just an extended sed-command (well known for more than 40 years) on a variable.

    compare this to the PHP-equivalent:

    $contentName = preg_replace("[^\w\d_]", "_", $contentData->name);
  • noland (unregistered) in reply to Jibble
    Jibble:
    noland:
    $name =~ s/[^\w\d]/_/g;
    Any more elegant way to this?

    That's "elegant"?

    Now imagine a world without Perl. The same thing would probably look like this:

    $expression = new regular_expression();
    $class = $expression->create_class();
    $class->add_atom( regular_expression.atoms.WORD_CHARACTER );
    $class->add_atom( regular_expression.atoms.DIGIT );
    $class->add_atom( regular_expression.atoms.UNDERSCORE );
    $class->add_modifier( regular_expression.modifiers.NOT );
    $experession->add_pattern( $class );
    $experession->set_flag( regular_expression.flags.ANY );
    $experession->set_flag( regular_expression.flags.GLOBAL );
    $expression->set_subsitute( "_" );
    $expression->compile();
    $name = $expression.execute( $name );

    Any better? ;-)

  • The Big Picture Thinker (unregistered) in reply to TheSHEEEP
    TheSHEEEP:
    Could someone explain this:

    $key=>$letter

    ... in the foreach?

    What exactly does it do? What is the difference between $key and $letter?

    Right now I only get 2/3 of the WTFs in this code, so please help me!

    Disclaimer: I do not condone PHP. I am just explaining this.

    If you have an array called $letters, and it contains this:

    {'a', 'b', 'c'}

    Then when you do:

    foreach($letters as $k => $v)
    {
        // For the first iteration of this foreach,
        //     $k will be 0
        //     $v will be 'a'
    
        // For the next iteration of this foreach,
        //     $k will be 1
        //     $v will be 'b'
    
        // For the next iteration of this foreach,
        //     $k will be 2
        //     $v will be 'c'
    }

    Basically $k is the "key", which is the index. And $v is the "value", which is the actual contents of the array at that index.

    You don't have to do a foreach like that. If you don't care about the index and just want to walk the array like most languages, you can do this:

    foreach($letters as $v)
    {
    }
  • (cs)

    I can't believe no one posted the shortest (and therefore most cryptic) way to do this in Perl yet:

    $name =~ s.\W._.g;

  • (cs) in reply to Anonymous
    Anonymous:
    Anon:
    And this is why PHP is so fucking stupid.

    I played around with it once connecting to a MySQL database. It helpfully has a "mysql_escape_string" function for, well, escaping strings. But if you look at the manual pages, you see it's deprecated for "mysql_real_escape_string". WTF!?!

    If "mysql_escape_string" doesn't work, why not just fucking fix it? Instead we create a new function with a longer and stupider name. What happens when somebody decides "mysql_real_escape_string" doesn't work right? "mysql_really_really_definitely_now_working_correctly_escape_string_for_real_we_mean_it_this_time"?

    Who uses the mysql extension anyway? PDO has been around for years!

    And yet people still use the old MySQL extensions. One of the reasons I have low opinions of many (not all) web based developers is that the term "parameterized queries" is an enigma to them. Even when you point out that PDO exists (in the case of a PHP developer) they just shrug and say "we always did it this way".

    That and I'm a snobby pretentious git.

  • Noland (unregistered) in reply to superjer
    superjer:
    I can't believe no one posted the shortest (and therefore most cryptic) way to do this in Perl yet:

    $name =~ s.\W._.g;

    See the first page ...

    noland:
    $name =~ s/\W/_/g;
    ; (We have Perl for that.)
  • Shinobu (unregistered) in reply to 3rd Ferguson
    3rd Ferguson:
    1) You're probably not especially smart compared to everyone else in your field
    On the other hand, the chance that you're smarter than even those just one standard deviation below the mean is 84%.
  • (cs) in reply to 3rd Ferguson
    3rd Ferguson:
    Just remember, folks:
    1. You're probably not especially smart compared to everyone else in your field;

    I dispute that.

    If you are reading TDWTF you are probably smarter than 90% of the other 'programmers' out there.

    However, this may not mean you are a 'super programmer', just that 90% of the programmers out there are even crapper than you are.

  • (cs)

    Someone misses streams.

  • (cs) in reply to FTFY
    FTFY:
    Anon:
    And this is why MySQL is so fucking stupid.

    I played around with it once connecting to a MySQL database. It helpfully has a "mysql_escape_string" function for, well, escaping strings. But if you look at the manual pages, you see it's deprecated for "mysql_real_escape_string". WTF!?!

    If "mysql_escape_string" doesn't work, why not just fucking fix it?

    FTFY. (mysql_escape_string and mysql_real_escape_string are both MySQL API functions. PHP did not invent these names)

    Yeah http://dev.mysql.com/doc/refman/5.0/en/mysql-escape-string.html

    This function is always pointed as a PHP failing but it is actually what the underlying library says. PHP does get a lot of flack for being a thin wrapper around a lot of libraries though...

  • (cs) in reply to Noland
    Noland:
    superjer:
    I can't believe no one posted the shortest (and therefore most cryptic) way to do this in Perl yet:

    $name =~ s.\W._.g;

    See the first page ...

    noland:
    $name =~ s/\W/_/g;
    ; (We have Perl for that.)

    I think . is a little shorter than /

  • (unregistered) in reply to TheSHEEEP

    when you do a foreach ( $array as $key => val )

    the $key var assumes the index of the array and the $val var assumes it's value so for instance

    $array = array("foo" => "bar", 12 => true); foreach ( $array as $key => val ) { echo $key . ' ' . $val . ' '; }

    returns "foo bar 12 true"

  • akTed (unregistered) in reply to Anom nom nom

    Your Captcha reads to me as "No Bi's"...homophobic Captcha's unite! :)

    Captcha: DUIS (Driving under the influence, multiple times)

  • asdbsd (unregistered)

    So many comments and no one assumed he's working around unicode multibyte characters.

    PHP has no native unicode string but mbstring extension replaces SOME functions with utf8 aware. As far as I remember, indexing brackets[] still return bytes, not unicode characters (multibyte). So to retrieve a single character you really have to do substr (which handles multibyte fine).

Leave a comment on “All the Pieces”

Log In or post as a guest

Replying to comment #:

« Return to Article