NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
Re: What We Can Learn From Other Languages (Score:1)
I'm not sure if the first example is fair. Simple method overloading in Java or C++ is generally used for functions that can take different parameter types, which isn't an issue in Perl, or to have functions with optional parameters which again isn't much of a problem in Perl:
I think that method overloading is more tied to the fact the a language is statically typed and not necessarily something
Re: What We Can Learn From Other Languages (Score:2)
Well, you say it's not much of a problem, but look at the snippet you posted:
Can $foo be 0? Your code says 'no', but that might or might not be what you meant. Also, by the time you've finished the $foo line, you no longer can easily tell whether or not you even passed an argument for $foo.
In my original example, the code might do strange things if too many arguments are passed, or if they're not integers, even though that's what's expected. Params::Validate helps to mitigate many of these problems, but doesn't do anything for the multi-method dispatch bugs which can arise from sloppy programming (i.e., you dispatch to different methods based on the arguments or you have an ugly if/else construct). I've seen so many bugs arise from problems just with this.
Reply to This
Parent
Re: (Score:1)
Some of these problems could be solved efficaciously with method overloading. Nevertheless, I still think that method overloading is mainly a necessity of static typing. Which for me is a more useful language feature and one that we have learned from since it will be included in Perl 6.
John.
--