There's more than one way to do things | |
PerlMonks |
Re: Perl 5's greatest limitation is...?by tilly (Archbishop) |
on Jul 28, 2005 at 04:35 UTC ( [id://478817]=note: print w/replies, xml ) | Need Help?? |
Programming by syntax doesn't scale. Because Perl uses syntax and specialized operators to differentiate its types, Perl's type system is necessarily extremely limited. Furthermore there are things you sometimes would like to do which you either can't, or have to do a lot of extra work to do, because the type system gets in your way. The language that convinced me of this is Ruby. There everything is an object, and the syntax that exists is just syntactic sugar around method calls. Provide the right methods, and the syntax will work for your objects. The example that I give to illustrate why this is nice is tie. In Perl you can't directly make your objects into data types other than scalars. The solution is tie. (Which relies on magic, and because of how this is internally implemented it has been a common source of bugs.) But what if you want to create something that is almost a hash, but has a couple of extra methods? (For instance you have a dbm, and you want to expose some locking methods.) In Perl you either have to use a scalar and have people use -> often, or they have to resort to tied to get your extra methods. By contrast in Ruby there is no need for something like tie. Just create an object with the right methods and it can be used like anything else with those methods. Want a hash that has locking methods? You can easily write one! The syntax is nicer than Perl. Conceptually it is simpler so people don't get so confused. Furthermore because this isn't implemented with if statements everywhere in the code, it isn't buggy. What does Ruby give up for this? Autovivification can't be made to work. So Perl gets some convenience in return for a barrier to scaling in complexity.
In Section
Meditations
|
|