Registered: Oct, 2006
Re: The Adventures of a Pythonista in Rubyland/2 - No Comprehension
Posted: Nov 2, 2008 8:22 AM
> Not to me either. But I find the frequent claims that
> Ruby might as well be plain English a bit of an
Yeah, I agree with that. I personally prefer ruby because I find blocks an intuitive and flexible language feature, but honestly I don't use it very often.
> To be fair, select and map are specific to lists (or
> arrays or whatever). And technically for comprehensions
> are not specific to lists. They can be used with any
> iterable object or with methods that yield values.
Well, select() and map() don't have to be specific to Lists (although they may be in ruby, I'm not sure.) They both simply rely on iteration. I really think that the features are semantically equivalent. It's the classic trade off: language or libraries?
List comprehensions (and their more advanced friends) put feature design in the hands of the language designers by requiring new syntax in the language to support new features.
Blocks/closures delegate that responsibility to library designers by providing a general syntax for succinctly representing small functional units that library designers can use to provide features with.
The former, if done well, can have a more intuitive reading syntax since the language designer has free reign with the parser. Additionally, the language designer can implement the feature as they see fit rather than accepting the standard evaluation semantics of the language, since they control the whole environment.
The latter has the advantage that the language stays smaller and that library developers can add features as they see fit, rather than convincing some language weenie to add syntax for it.
In general, I come down in favor of the latter. However, seeing Microsoft's work on LINQ has shown me that you have to be pragmatic about the decision and that certain things are fundamental enough to warrant additional syntax in a language.
> And, of course, you can do the same kind thing as you
> shown above in Python. I don't really care that much, I'm
> just a casual Python user. I haven't found any really
> strong argument for learning Ruby though.
I think ruby is worth learning just because it's such a strange little language, with it's special block parameters, flexible parsing rules (which I've grown to despise) and interesting culture. But then there are lots of things worth learning and only so much time in the day.