Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: Re: Efficiency in maintenance coding...

by perrin (Chancellor)
on Nov 15, 2001 at 02:31 UTC ( [id://125445]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Efficiency in maintenance coding...
in thread Efficiency in maintenance coding...

I'm with dws on this one. His example is much more maintainable than your original one. Hanging out on Perlmonks might make you think that lots of Perl developers are comfortable with throwing around condensed code with unusual uses of for and splitting on <>, but that just isn't the case in the rest of the world. I have a pretty good amount of professional Perl experience under my belt, and I had to stare at your code for a minute to figure out what was going on there.

When people attack Perl, they often do it on the basis of readability. That's why I think it's very important to write clean and understandable code when it's for public consumption. It's not so much a Perl vs. Java thing as a general advocacy thing. Note that I didn't say never to use Perl idioms. Just know the difference between idiomatic and confusing.

Replies are listed 'Best First'.
Re (tilly) 3: Efficiency in maintenance coding...
by tilly (Archbishop) on Nov 15, 2001 at 04:25 UTC
    Maintainable by whom?

    Maintainability is an interaction between code, users, and programmers. I think that most "Perl hackers" would prefer to work with eduardo's code. Most people who put Perl on their resumes would prefer what dws produced.

    I personally prefer working with people who can figure out things like:

    $freq_count{$_}++ for get_words(<>); # Takes one or more strings, returns all words it finds. sub get_words { map /(\w+(?:'[ts])?)/g, @_; }
    (Not that I try to abuse people, but should I find something convenient, I like not having to worry about whether the next person can figure that out.)
      This is difficult subject to discuss without histrionics. I mentioned on the CB one day that I try to avoid the use of $_ because I think it makes code harder to read, and it was not a very popular notion.

      Most of the advanced people on this site would certainly prefer eduardo's version, but my experience has been that many of the people I have to work with every day just don't know Perl well enough to quickly grok stuff like $frequency{$_}++ for (split /\W/, <>) quickly. Because of this, I try to stick to the more standard control structures when I can, and especially avoid stacking up a lot of operations on one line.

      I still use things like map, grep, hash slices, and extended regular expressions, but not when something simpler will work with similar efficiency.

        I try to avoid the use of $_ because I think it makes code harder to read ...

        Well, i suppose you are likewise going to start removing 'it' from your vocabulary. ;)

        But i agree that $_ can be abused.

        jeffa

        L-LL-L--L-LL-L--L-LL-L--
        -R--R-RR-R--R-RR-R--R-RR
        F--F--F--F--F--F--F--F--
        (the triplet paradiddle)
        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://125445]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-26 03:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found