in reply to Shift versus Sanity
Style, readability and maintainability are much more important in most cases. That's why I always assign @_ to a list of lexicals, unless I'm coding a one-liner. In classes for tie, I often use shift and pop in examples.
If I use @_ and the sub is small (5 lines or less), I do shift the object and then use @_, because that saves me an array. Besides, sometimes you want to change the values, in which case you have to use @_.sub TIESCALAR { bless \(my $foo = pop), shift; } sub STORE { ${ +shift } = pop } sub FETCH { ${ +shift } } ### sub foo { my ($self, $foo) = @_; ... } sub foobar { my ($self, %options) = @_; ... }
Some examples of things that I do not like:
I dislike anything using more than one shift.# Bad sub foo { my $self = shift; ... not using @_ anymore } sub bar { my $self = shift; my %options = @_; ... } # Worse sub foo { my $self = shift; my $foo = shift; my $bar = shift; ... } # Awful sub foo { my $self = shift; my $foo = shift; ... my $bar = shift; ... }
- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Shift versus Sanity
by drewbie (Chaplain) on Apr 24, 2002 at 14:14 UTC | |
by Juerd (Abbot) on Apr 24, 2002 at 17:34 UTC | |
Re: Re: Shift versus Sanity
by d_i_r_t_y (Monk) on Apr 25, 2002 at 08:34 UTC | |
by Juerd (Abbot) on Apr 25, 2002 at 09:58 UTC | |
by d_i_r_t_y (Monk) on Apr 25, 2002 at 14:34 UTC |
In Section
Meditations