in reply to Ruby Before Perl? Nah.
As to the lack of sigils and arrays and hashes both being indexed with square brackets, that gets more into the Ruby tendency to favour interface polymorphism (or as it's often referred to, "duck typing"). So long as what you're calling the [] method on responds to that method, everything is hunky-dory and it allows for some nice flexibility. I think the example given in one of the books was code which was using a string IO instance with << to build up something for output and the temporary objects were killing performance; they swapped to passing in an array which also groks << (and then called join afterwards once) and the app went from terrible multiuser performance back to acceptable (or something along those lines).
Not that this approach doesn't also have issues (e.g. you call method zorch expecting the object to do foo, but instead it does bar and wipes your hard drive . . .), but there is a rationale behind it.
And also there is a more traditional looking for loop, but it's really (mostly) syntactic sugar for calling each:
for var in iteratable puts "Frobnicated: #{var.frobnicate}" end ## is pretty much just the same as this . . . iteratable.each { |var| puts "Frobnicated: #{var.frobnicate}" }
But really that's like persisting to use C-style loops in Perl . . . :)
The cake is a lie.
The cake is a lie.
The cake is a lie.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Ruby Before Perl? Nah.
by Porculus (Hermit) on Jun 06, 2008 at 23:36 UTC | |
by Fletch (Bishop) on Jun 07, 2008 at 15:48 UTC | |
by chromatic (Archbishop) on Jun 08, 2008 at 03:47 UTC |