Pathologically Eclectic Rubbish Lister | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
If the function takes a simple list of arguments with perhaps some trailing arguments being optional, then I will often write: just because it is simple, takes up little space, and is easy to read. But if my argument handling is more advanced, or I find myself changing what arguments the function accepts, or I feel a need to add comments, or for probably quite a few other reasons, I will instead use something much closer to: because it is much easier to make changes to. Note that I don't use a bare shift mostly because I really like to be able to scan for just "@_" in order to see where any argument handling is happening. I don't want to scan for that plus "shift", "pop", $_[, and several others. I also like that it makes the code a bit easier for non-Perl programmers to read (which makes it easier to have the code accepted by coworkers and managers) and clearly documents that I didn't write the code thinking I was dealing with @ARGV and then later moved it into a subroutine and broke it. I also use the asymetrical spacing around the assigment operator to make it clearer that I didn't mean to write == (no, that isn't a likely source of confusion for this code, but you have to follow that convention for all assignments for it to work well). And I don't line up the expressions like: as I think this scales really poorly when you decide to rename some variable and suddenly you feel obliged to reindent a bunch of nearby parts of lines, especially since no editor I've seen comes even close to automating or even assisting much in such primping. And I certainly don't prematurely nano-optimize for run-time speed since development time is usually much more important and run-time speed is usually much more improved by careful algorithm design than such pre-benchmarking.
:)- tye (but my friends call me "Tye")In reply to (tye)Re: Shift versus Sanity
by tye
|
|