Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re^5: Perl is more intuitiveby Joost (Canon) |
on Aug 19, 2005 at 14:08 UTC ( [id://485139]=note: print w/replies, xml ) | Need Help?? |
That's true, but rubys library design is based on the idea that you should not tie down the type of a variable in the syntax, because if you do that, polymorphism becomes a lot more difficult (c.f. Java's interfaces, or C++'s multiple-inheritance).
Take this simple function:
The name of the parameter is "array", but because there is no type indication, this will work just as well with a File (print each line) a Set (print every element of the set), a Struct or some other object that happens to have an each() method that works like this. According to the idiom, an each method should "walk through" a collection - as long as you use idiomatic design, your code will remain relatively easy to interpret. I like this strategy, but as you noted, it does have some drawbacks if you want to figure out what a complex piece of code does exactly, or when the idiom is broken.
In Section
Meditations
|
|