Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: A question of style - declaring lexicals

by jordanh (Chaplain)
on Jun 03, 2004 at 20:18 UTC ( [id://360462]=note: print w/replies, xml ) Need Help??


in reply to A question of style - declaring lexicals

I'm not sure that this is the most important consideration, but I've found that declaring variables as close to the scope as is required, what you call style #1, allows you to pull things out into subs more easily.

This is not only for refactoring, but also for simplifying code by reducing the indentation level. The use of good subroutine names and comments can make things more clear. I don't know, but I always feel that subroutine level comments are clearer.

I tend to use fairly descriptive variable names, making accidental reuse rare. It is a danger though, I agree.
  • Comment on Re: A question of style - declaring lexicals

Replies are listed 'Best First'.
Re^2: A question of style - declaring lexicals
by jordanh (Chaplain) on Jun 07, 2004 at 15:00 UTC
    I'm not sure that this is the most important consideration, but I've found that declaring variables as close to the scope as is required, what you call style #1, allows you to pull things out into subs more easily.

    This is not only for refactoring, but also for simplifying code by reducing the indentation level. The use of good subroutine names and comments can make things more clear. I don't know, but I always feel that subroutine level comments are clearer.

    Update: After reading what tilly had to say, I realized that I'm actually advocating style #2, not #1. I hadn't read what you had to say closely enough!
    Update II: How did this happen? I thought I was updating the parent, but I created a new node... oh well.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-25 11:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found