Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^3: Functional Programming & method rewriting

by elusion (Curate)
on Oct 29, 2004 at 03:16 UTC ( #403584=note: print w/replies, xml ) Need Help??

in reply to Re^2: Functional Programming & method rewriting
in thread Functional Programming & method rewriting

Why type more than you need to?
This philosophy is one I don't agree with, especially when developing code you are going to have to go back and tweak later.
You're right. And I asked the wrong question; or at least an incomplete one. What I meant to ask was: why type more when you're not gaining anything? Your code is more complex, it's partially duplicated, and it's not very readable. I consider myself a strong Perl programmer (and I realize that assumption can be a dangerous one to start with :-), and I had to sit for a minute before I could figure out what it was that you'd done.
Every time I've done a quick shift in the middle of a block of code, I've had to go back and change it later. With @args, I might want to later replace that @args with ($gorp,$slug,@args) = shift() for instance. It leaves a place in the code to do that, and I only have to edit one line to make that change.
Are you sure you don't mean my (@args) = @_;? shift only ever returns one element, so using it in list context is pointless: ($gorp,$slug,@args) = shift() doesn't do anything to $slug or @args.

I don't mean to grill you. I just want to understand and give some (hopefully friendly) advice.

Update: my 200th node! :-)

Replies are listed 'Best First'.
Re^4: Functional Programming & method rewriting
by SpanishInquisition (Pilgrim) on Oct 29, 2004 at 12:50 UTC
    My fault. Ok, so replace ($gorp, $slug, @args) = shift() with ($gorp,$slug) = @_ and you get what I meant, ah well. Please shoot me for only testing with functions taking a single parameter :)

    This stupid mistake of mine was related to me thinking @_ would be accidentally closed around the first block, which isn't true, because @_ is magic... (I was always using @_ before, so, umh, that's why it's odd).

      No it's not because @_ is magic (whatever that means) it's because @_ is localized. And a package Variable anyway.
      Closures only grab lexicals (my variables). @_ is a package variable (local variable).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://403584]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2017-03-28 06:56 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (327 votes). Check out past polls.