Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I recently posted a question in which it was kindly mentioned that my use of prototypes was probably inappropriate. I went ahead and did some reading on it, and I'm still a bit curious and have a few questions.
First, why *doesn't* Perl support strict function-argument specification? I can see that prototypes don't really do this, but... I'm surprised that there is no easy way to enforce it. Is this a result of the way Perl seamlessly casts between ints and strings?
Second, many of the prototype-problems seem to come down to the functions accepting "weirdness" despite the prototype. But from the article it did appear that passing reference to data-structures (e.g. sub foo(\%) {}) wasn't too problematic: mainly coming down to issues of "semantic sugar" rather than unexpected behaviour. Is that a misconception?
It still seems "clearer" to my eyes to see the data-types expected of a function specified in its declaration. I'm trying to "adjust" my eye-sight by just taking it out and putting it in comments at the start of the routine, but I figured I should try to understand why I'm doing it this way as best as possible!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Considering Prototypes
by tall_man (Parson) on Jul 28, 2003 at 18:26 UTC | |
|
Re: Considering Prototypes
by sauoq (Abbot) on Jul 28, 2003 at 19:19 UTC | |
|
Re: Considering Prototypes
by chunlou (Curate) on Jul 28, 2003 at 18:42 UTC | |
|
Re: Considering Prototypes
by waswas-fng (Curate) on Jul 28, 2003 at 19:08 UTC | |
|
Re: Considering Prototypes
by adrianh (Chancellor) on Jul 28, 2003 at 19:58 UTC | |
|
Re: Considering Prototypes
by scrottie (Scribe) on Jul 29, 2003 at 05:52 UTC | |
|
Re: Considering Prototypes
by Anonymous Monk on Jul 29, 2003 at 19:27 UTC |