Do you know where your variables are? | |
PerlMonks |
Re: Apparent Inconsistencies in Perl Function Namingby Dominus (Parson) |
on Nov 26, 2000 at 20:42 UTC ( [id://43382]=note: print w/replies, xml ) | Need Help?? |
Says princepawn:
> uniformity/genericity --- you know those generic sorting algorithms thatSince you asked, it works really well. Perl achieves a lot more genericity than C++, which you meantioned earlier. The specific feature you brought up doesn't cause any problems in practice. Let's take your example and suppose that you wanted to write a sorting function. You write it, but it only works on arrays. In C++ it might also work on a string, because a string is an array. But in Perl, if you pass a string, expecting the characters in the string to be sorted into order, it doesn't work. Is this a big deal? No. Why not? Two reasons: First, sorting the characters in a string is a very unusual operation, so it does not come up very often. But primarily because if someone did want to use your function to sort the characters in a string, they would just use split to turn the string into an array and pass the array of characters. Perl's genericity mechanisms are a lot stronger than those in C++. Consider several C++ classes where objects in each class will be joined to gether in linked lists. Each class has a 'next' member which will be used to point to the next object in the list. Now you want to write a C++ function that will traverse a list of objects of any class. Oops, you can't. The only solution is to use the ridiculous templating mechanism to tell C++ how to generate one separate traversal function for each class! But in Perl this task is trivial: That's all. One function handles every possible kind of object, as long as the object has a next member. It even handles the classes that haven't been defined yet. It can even be made to handle classes where the link member is named something other than next. (That's a one-line change.) This is impossible in C++. Even the humongous templating feature does not help.
I'm going to stop picking on C++ now. It's unfair, because C++ is such a shoddy language.
The short answer to your dig about Perl being a 'non-orthogonal' language is that Larry is really smart, and he put in the orthogonality in the places where it was important, and not in places where it wasn't.
In Section
Seekers of Perl Wisdom
|
|