Because writing out the code to check arguments is longer and less convenient than writing f ($$), I guess?
Yes, I realize it's only a few extra characters, I realize that this example is trivial (since I SIMPLIFY code before posting it), and I realize that the community doesn't seem to like prototypes (possibly for very good reasons)
| [reply] |
I realize that the community doesn't seem to like prototypes
Well — not exactly. The Perl community is fine with prototypes when they’re used appropriately. The problem is, most of us come to Perl with a background in C/C++/Java, see Perl prototypes, and think, “That must be Perl’s way of doing argument checking.” But prototypes have little to do with argument checking; they are all about argument coercion.
This is explained in detail in the classic article Far More than Everything You've Ever Wanted to Know about Prototypes in Perl -- by Tom Christiansen (written by the co-author of the Camel Book, no less). That article is a must-read for every Perl programmer.
Hope that helps,
| [reply] |
Thanks a lot. That article *really* helped.
| [reply] |
I realize that the community doesn't seem to like prototypes.
You probably referring, inter alia, to my comment of yesterday to another of your posts. Just to make things clear, I did not tell you not to use prototypes, I told you not to use prototype unless you really know how to do it and, more importantly, why you are doing it (and I might have added, unless you really know what they are doing). I personally use them only extremely rarely, but there have been few cases where I have found them handy.
| [reply] |