News for hackers. Stuff that matters.
Re:Why Python doesn't need blocks by andrewvc on Monday June 30, 2014 @11:31AM (#7965542)
This is one of those pieces that is simultaneously very correct and very wrong. Technically, it's mostly correct, but the fact is Ruby has blocks, lambdas, and the ability to pass around a method attached to an object instance. That gets you a superset of functionality really. It's just all syntactic sugar.

As a lisper I could easily point my finger at ruby blocks and point out they're more complicated than just always using a function, but the fact is, in practice, it just doesn't matter. Ruby blocks cover 95% of the cases you hit in a pretty way, and when they don't you can still use lambdas!

Now macros, those are a better solution to what blocks, but it's a 95% solution, so I've stopped caring.

Re:Why Python doesn't need blocks by lloeki on Monday June 30, 2014 @02:19PM (#7966613)
> It's just all syntactic sugar.

I disagree. Blocks are the fundamental building blocks (!) of various constructs that are derived from them. They're 'thinner' than lambdas, procs and methods. Blocks alone are only part of a system, which, together with binding allows one to build lambdas, iteration constructs, and various other features. Comparing them head-on to functions or lambdas therefore makes no sense. For example, where Python has 'hardcoded' generator expressions, a Ruby developer can leverage blocks to make his own generators. The same goes for features such as with, which are syntactically defined in Python, but which are customary to simply implement with blocks in Ruby. Combining instructions such as next and continue with yield return values and arguments, along with rebinding allows one to define new constructs and syntaxes without paying the price of Lisp's purity (which basically mandates that the language is made of sexprs).

Re:Why Python doesn't need blocks by bryanlarsen on Monday June 30, 2014 @11:42AM (#7965615)
Sure, once you understand the differences between bound and unbound methods, blocks, lambdas and Proc's. That's a lot to understand for something that's fairly simple in many other languages.
Re:Why Python doesn't need blocks by andrewvc on Monday June 30, 2014 @12:48PM (#7966045)
You don't need understand that much. If all you know is "a block is just fancy syntax for passing an optional lambda into a method", that will suit you just fine. Does it capture 100% of the nuances of a block? No. But it's a fine bit of functional knowledge. If you throw in calling Object#method(:foo) returns what amounts to lambda {|args| Object.foo|args| } you have 99% of what you'll ever need.
Re:Why Python doesn't need blocks by mcphage on Monday June 30, 2014 @01:50PM (#7966449)
> That's a lot to understand for something that's fairly simple in many other languages.

That's what's so nice about how Ruby does it; you don't need to understand any of that to use blocks. As you learn the language, you learn those things, but none of them are required to get started.

Re:Why Python doesn't need blocks by angersock on Monday June 30, 2014 @12:17PM (#7965852)
Surely that's not really that difficult to understand?