Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I still use the expression style where possible. The recommendation in Perl Best Practices makes several arguments in favour of the block form, but I don't find them convincing:

A block stands out more clearly.
It probably does, but when the expression is simple enough, e.g. just /$pattern/, I don't see why a scope around it is needed.
It avoids mistakes when a function in the expression eats the list as arguments.
The mistake is either recognised by Perl itself, giving a compile-time error like Too many arguments for substr, or by a test.
It saves you time when you later need to refactor the expression into something more complex.
Adding a { and replacing a , with } doesn't take so much time. Also, many simple expressions stay simple.

Regarding refactoring for refactoring: I do it sometimes to my personal projects. It makes me more familiar with the code again, I touch parts I haven't seen for years, which means I can find and fix bugs faster when needed. Also, it makes me feel comfortable when reading the code or showing it to someone else. At work where the codebase is huge and changes must be supported by a ticket, I only refactor subs I need to touch for other reasons, and the refactor is always committed in a separate commit before the actual changes.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

In reply to Re: Refactoring just to refactor? by choroba
in thread Refactoring just to refactor? by Lady_Aleena

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-25 12:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found