Add_multi



  • I've now been working at new job for a few months. Code is all Perl. I thought I'd share a small function. Bug reports coming in saying that it returns "1 resultses" in some cases, but "2 results" as expected. Behold

    
    sub add_multi {
    my $txt = shift;
    my $multi = shift;
    
    if ($multi) {
    if($txt =~ /(s|z|x|sh|ch|es)$/ ) {
    $txt .= 'es';
    } elsif($txt =~ s/(y)$/i/ ) {
    $txt .= 'es';
    } elsif($txt =~ s/(f)$/v/ ) {
    $txt .= 'es';
    } elsif($txt =~ s/(ex|ix)$/ic/ ) {
    $txt .= 'es';
    } elsif($txt =~ s/(us)$/i/ ) {
    } else {
    $txt .= 's';
    }
    }
    
    return $txt;
    }
    

    Notes: indentation was correct, seemed to have lost them via copypasta. In some places the logic was incorrect for the second param. There are other unrelated problems with this code.



  • I'm finding those regices a little confusing.



  • I can't spot how it gets "1 resultses". Is "result" being sent through this method twice?

    <snark>On the other day, I could have used something like this a few daies ago for a natural language processing project. It lices ok, but the transformations sometimes go wrong. I did a demo of queries against a restaurant menu and the cheves were quite upset that it didn't pluralise jus correctly.</snark>



  • @flabdablet said:

    regices

    +1



  •  @flabdablet said:

    I'm finding those regices a little confusing.

    Indeed. Two of the regexes serve no purpose. The rest do weird stufves.



  • @Faxmachinen said:

    regexes

    You mean "regular expressions"?



  • ugh... I'm in no mood to read Perl (or any other $ sign crippled language for that matter) code today.



  • @pjt33 said:

    I can't spot how it gets "1 resultses". Is "result" being sent through this method twice?

    Sorry, forgot to mention that the call was add_multi("results", $results==1) instead of ("result", $results!=1) in other parts of the code.



  • @Zemm said:

    Sorry, forgot to mention that the call was add_multi("results", $results==1) instead of ("result", $results!=1) in other parts of the code.

    This is Perl. There's more than one way to do it a different way every time.


  • SockDev

    @Zemm said:

    resultses
     

    Glad to see Gollum's found something useful to do.

     



  • @toon said:

    @Faxmachinen said:

    regexes

    You mean "regular expressions"?

     

     

    You mean "pedantic dickweeds?"

    Whoosh!



  • @Zemm said:

    } elsif($txt =~ s/(f)$/v/ ) {
    $txt .= 'es';
    }

    Should throw a TolkienException :)

     




  • @RaceProUK said:

    @Zemm said:

    resultses
     

    Glad to see Gollum's found something useful to do.

     

    I think you mean Mace Windu:


     



  • @pjt33 said:

    …upset that it didn't pluralise jus correctly.

    Tell them it serves them right for being pretentious gits who don't use the word "gravy".



  • @da Doctah said:

     I think you mean Mace Windu:


     

    Now there's a coincidence, I just discovered Backstroke of the West for the first time earlier this morning (courtesy of the TvTropes page on Darths and Droids).

     



  • @RaceProUK said:

    @Zemm said:

    resultses
     

    Glad to see Gollum's found something useful to do.

     

    Q: "What box has no hinges key or lid yet inside a golden treasure is hid?"

    A: add_multi("eggs", true);



  • @DaveK said:

    I just discovered Backstroke of the West for the first time earlier this morning (courtesy of the TvTropes page on Darths and Droids)
     

    :O



  • Didn't I post "do not want" in another thread a few days ago? Suuure you found it on tvtropes.



  • @blakeyrat said:

    Didn't I post "do not want" in another thread a few days ago?

    I have no fucking idea.  You don't seriously believe I bother reading 90% of the tedious shit you post, do you?  Hahahahaaahaaaaa!

    @blakeyrat said:

    Suuure you found it on tvtropes.

    I sure did, Patrick.




  • But how does the code know what to do when the input is "dwarf"? If it produces "dwarves", the little people will be offended, but there's always that Tolkien minority who will be up in arms (axes?) about "dwarfs"!



  • I found equivalent code in the main JavaScript file. The lead programmer hates "third party" solutions, even going so far as to rewrite jquery utility functions such as $.trim(). So the main js file is a large $.extend({ stuff }). Because they might remove trim at any time but not extend? Or there's no chance of wanting to change from jquery and its $ object? I need to post his version of trim, since it was wrong (on my phone atm)! Anyway the js version is called "addMulti" so that it has a different name than the Perl version. Implemented with the same logic.



  • @Zemm said:

    The lead programmer hates "third party" solutions, even going so far as to rewrite jquery utility functions such as $.trim().
     

    Any reason behind his hate?

    Just curious to mistrust of externally-developed modules.



  • @Cassidy said:

    Any reason behind his hate?

    Just curious to mistrust of externally-developed modules.

    The only real reason I have been given was that once the soap perl module was updated to one that had a bug which broke several payment gateways. It's not clear to me whether it was a legit bug or they were using the module for a side effect or something. I like cpan but he avoids it unless absolutely necessary. Another example is his version of json encoding uses single quotes as he prefers that, which of course does not work for strict json parsers, so the module is used in these cases.

    There's also a set of serialization functions that are apparently really fast (it is generally faster than other methods) but uses += operators which are of course really slow in internet explorer.

    Yesterday he was even complaining about ckeditor doing something funny, but I wasn't involved with that discussion, so I'm not sure about details.



  • @Zemm said:

    The only real reason I have been given was that once the soap perl module was updated to one that had a bug which broke several payment gateways.
     

    Kinda comes with the territory. Things may change over time so updates could bring newer functionality at the expense of deprecating existing features.

    It sounds like he's relying upon every upgrade to have backwards compatibility. Or module upgrades aren't performed in a test environment to assess their impact before deploying to staging/production.

    Don't tell me that if he rolls his own, he's never going to remove features over time and find it breaks some of his driving code.



  • @DaveK said:

    @blakeyrat said:
    Didn't I post "do not want" in another thread a few days ago?
    I have no fucking idea.  You don't seriously believe I bother reading 90% of the tedious shit you post, do you?  Hahahahaaahaaaaa!@blakeyrat said:
    Suuure you found it on tvtropes.
    I sure did, Patrick.
    Patrick?  I'm pretty sure his name is Jimmy.

     


     



  • @Cassidy said:

    Kinda comes with the territory. Things may change over time so updates could bring newer functionality at the expense of deprecating existing features.

    On of the points of difference of our solution is that it integrates with a large number of third parties. Since it's e commerce that means payment gateways, shipping companies, accounting packages, comparison sites and email marketing. plus others probably too. I think he does lose sleep that one of those APIs will change and break everything.
    @Cassidy said:

    Or module upgrades aren't performed in a test environment to assess their impact before deploying to staging/production

    They've been vague when it comes to details here too. There are separate testing sites (albeit on the same physical servers, so I guess system-wide changes can't easily be tested: this is changing within a week: we are finally getting a server in the office


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.