Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Refactoring just to refactor?

by choroba (Cardinal)
on Jun 28, 2019 at 14:16 UTC ( [id://11102084]=note: print w/replies, xml ) Need Help??


in reply to Refactoring just to refactor?

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]

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-26 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found