Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I'm not sure if this discussion still interests you. If not, feel free to ignore this reply. I am not trying to prove you wrong, I just don't want my point of view to be misunderstood.

I agree that you are forced to change the code when a parameter is added, but I'm hard-pressed to come up with any situations where adding parameters _shouldn't_ warrant changing the code.

It's not the fact that you have to change the code, it's how you have to change the code. Using a series of shift lines, there is a lot more code overhead than using a list assignment from @_. Overhead often causes problems, especially when modifying existing code. When it can be avoided, I think it should.

Being explicit about exactly what parameters a subroutine takes in is just being clear

How is a list of variable names not explicit? Granted, the shift lines are more spread out, and perhaps more visible. But a list of variables in the first few lines of a subroutine is not exactly obfuscation. I think both are pretty clear. The shift lines may be marginally more clear, but not enough that it matters.

For what reason would you want to maintain the original @_ array? I can't see any reason that maintaining the original argument array has any advantage over individual arguments created by shift.

As I said before, I tend to look at it from the other point of view: for what reason would you want to destroy the original @_ array? I just get an uneasy feeling clobbering something unnecessarily. So, when there is an alternative way of doing something, and the alternative is better or equal in other ways, then I'll use it.

Keep in mind, I am not saying shifting parameters is never warranted. I do it frequently. There are many cases where destroying @_ makes perfect sense, and in those cases, I have no problem whatsoever. It's just in the "default case", when there is no reason to destroy it, I don't.

Feel free to disagree with me - for now I can't see any merit to your exceptions to using "shift'.

Hopefully you see it as a friendly disagreement. I do not mean to be confrontational, I just do not prefer the shift-by-default method of accessing subroutine arguments. I'm a bit disappointed that you don't see any merit to my reasons. I certainly see merit in yours, I just don't agree that it's the right thing to use most of the time.


In reply to Re^5: How to pass two lists to a sub? by revdiablo
in thread How to pass two lists to a sub? by YAFZ

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 romping around the Monastery: (6)
As of 2024-04-19 12:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found