Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

    Using blocks for looping and callbacks
      * break/next/return semantics in blocks extremely bizzare
Actually they're pretty sensible (return is anyway, break/next are a bit weird but no more so than the rest), the main issues with blocks is the — mentioned — Proc-v-lambda dichotomy and the — not mentioned — block-not-being-first-class issues. Although it's hinted at with further mentions of magical behaviors surrounding blocks.

Blocks, in and of themselves, are a very good base for implementing flow control.



The break/next/return behavior is not sensible at all. Anybody that comes to ruby with knowledge of other languages with first-class functions will be confused by it, in particular return.

Having said that, once you learn the difference it's not that big a deal.


> The break/next/return behavior is not sensible at all.

They are. Especially return.

> Anybody that comes to ruby with knowledge of other languages with first-class functions will be confused by it, in particular return.

Not necessarily, and especially not if they happen to understand what "block" means, and why Ruby uses "block" not "lambdas" for its core.

Or if they have the slightest inkling of knowledge of Smalltalk and/or Self.

And either way, unless they've already fossilized the difference is easy to learn (and solves important issues in imperative languages)


A return statement in a block is more or less a call to an escape continuation. So is break. Most programmers don't know what an escape continuation is, though once explained can use them. Even if they did, those escape continuations are captured implicitly. There's no reason to believe that people are just going to divine their meaning. And if they're new to Ruby, they're not going to understand what a block is, pretty much by definition. It's a feature that's pretty unique to Ruby.


> A return statement in a block is more or less a call to an escape continuation.

So?

> Most programmers don't know what an escape continuation is

Not that they have any reason to care.

> There's no reason to believe that people are just going to divine their meaning.

I don't think I ever said that.

> And if they're new to Ruby, they're not going to understand what a block is, pretty much by definition. It's a feature that's pretty unique to Ruby.

It's not for any known value of "unique". Blocks are present in most C-like languages, and first-class blocks were introduced by Smalltalk.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: