15 ms·
I've always felt that blocks were Ruby's gimmick. They're neat, and I'd like to have them in Python. But I get the feeling that this is just a bikeshed issue.
by j_baker 17y ago
I've always felt that blocks were Ruby's gimmick. They're neat, and I'd like to have them in Python. But I get the feeling that this is just a bikeshed issue. People show them off because they're easy to understand. There's absolutely nothing wrong with that.
However, I get the feeling that they're not Ruby's strongest feature. Python's coolest features (metaclasses, descriptors, and other things) wouldn't make sense if you'd just read a blog post on them. I suspect Ruby is the same way.
- jamesbritt 17y ago"However, I get the feeling that they're not Ruby's strongest feature." Perhaps the strongest feature is the underlying architecture that allows for blocks, the general idea that behavior is a data type you can pass around. And since you can alter the properties of objects at different levels (instances, classes, meta-classes), you can alter not just the more conventional values (int, strings) but an object's (and system of objects) very nature.
- Scriptor 17y agoVery true, I think Ruby's metaprogramming is an example of the kind of strong feature you were talking about. I don't use Ruby, but I remember reading about it in the Poignant Guide and being really impressed at how it can make code look very different, basically one way to make a DSL.
- bad_user 17y agoIt's not a bike-shed issue. Surely the other features are great, and Python has lots of powerful abstractions. But once you have closures with a light-weight syntax, as Ruby has, the APIs start to look a lot more different. For example, take this example ... v = [ x for x in collection if x % 2 == 0 ] for item in v: print item In Ruby the equivalent would be ... collection.find_all{|x| x % 2 == 0}.each do |item| puts item end Yes, the Python example is elegant, but Ruby doesn't need extra baked-in features like list-comprehensions. It doesn't need a bunch of other features as well, like generators, or generator expressions, or with statements. There are a lot of PEPs in Python that cover use-cases for Ruby's blocks, trouble is there are still use-cases that aren't covered. Guido is partially right though ... adding blocks in Python wouldn't be pythonic because blocks wouldn't be orthogonal with lots of other Python features. They should've been added from the start, and now it's kind of late.
- extension 17y agoBlocks push the language across some kind of line that makes it feel right to use λ-expressions everywhere. They may seem trivial but I've come to realize that such minutiae can make or break a programming language and can be pivotal in deciding how the language is used.