We don't bite newbies here... much | |
PerlMonks |
Re^3: Perl 5's greatest limitation is...?by tilly (Archbishop) |
on Jul 28, 2005 at 07:25 UTC ( [id://478858]=note: print w/replies, xml ) | Need Help?? |
Here is an example. In Ruby when you write x[foo] then Ruby calls the [] method on x with foo as an argument. Unless that is followed by an = in which case you call the []= method instead. So by providing those two methods, that piece of syntax is supported. And lots of core data types provide those two methods. The result is that x[foo][bar][baz] might be the equivalent of $x[$foo][$bar][$baz] in Perl, or perhaps $x{$foo}{$bar}{$baz} in Perl, or perhaps $x{$foo}[$bar]->($baz) - and that is before you get into user-defined types! In Perl the first one of those might create anonymous arrays, and the second might create anonymous hashes. In Ruby if you're accessing something that isn't there it has to be an error because there aren't enough syntactical hints around to guess what the programmer meant. The flip side of that is that in Ruby to create something that, say, acts like a hash backed by a dbm, all that you have to do is define a class with those two methods, and make those methods do the right thing. If you also want to add a locking method for your dbm class, you just have to add the locking method. And it works. tie in Perl only looks impressive because Perl's syntax is constantly setting up expectations about what the syntax does. Therefore causing that syntax to do something other than what it looks like it should do is very surprising. Ruby's syntax sets no such expectations, and so making the syntax do something new does not look impressive. Until you sit down and realize that making something sophisticated look routine is a pretty impressive accomplishment!
In Section
Meditations
|
|