Imagine you are writing code. Imagine you have a subroutine, foo(), that you think will only ever require one argument, ever.
You're code base is growing and growing. Soon, there are many calls to this mysterious subroutine.
One day, you realize your shortsightedness. You need to pass your subroutine a hash of data. A lot of stuff is using this subroutine and you don't want to break this code, or update it yet. Basically, too much uses the interface to change it.
One solution I've toyed with is creating a wrapper to the old subroutine with a bit of magic like this:
Of course, java/c++ have built in answers for this, but you also have to use subroutine prototypes everywhere to accomplish this.sub foo { return _foo_scalar(@_) if(@_==1); return _foo_hash(@_) unless(scalar(@_) % 2); }
How do you elegantly solve this problem if foo() originally required 2 arguments?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 1: Is it a scalar or a hash?
by tilly (Archbishop) on May 13, 2001 at 22:53 UTC | |
|
Re: Is it a scalar or a hash?
by Masem (Monsignor) on May 13, 2001 at 22:20 UTC | |
by DrZaius (Monk) on May 13, 2001 at 22:43 UTC | |
by MeowChow (Vicar) on May 14, 2001 at 09:39 UTC | |
by Anonymous Monk on May 14, 2001 at 09:22 UTC | |
by MeowChow (Vicar) on May 14, 2001 at 09:34 UTC | |
|
Re: Is it a scalar or a hash?
by Beatnik (Parson) on May 13, 2001 at 21:54 UTC | |
by DrZaius (Monk) on May 13, 2001 at 22:10 UTC |