Justin Collins
8/16/2006 10:04:00 PM
Simen Edvardsen wrote:
> On 8/16/06, Huw Collingbourne <huw@delthisbitdarkneon.com> wrote:
>>
>> "He Fa" <hfashina@hotmail.com> wrote in message
>> news:7d906db0cf97f3b16d1da58da69f53f6@example.com...
>> > James Gray wrote:
>> > I decided to just press on with my loose grasp of procs
>> > and blocks and dive into:
>> >
>> > "Programming Ruby:The Pragmatic Programmer's Guide, First Edition (*)
>> >
>> > Hopefully, it'll just hit me or I'll have to find a new hobby
>>
>>
>> I suspect you may be getting a bit too obsessive about those darn'
>> blocks
>> and procs. While blocks can be useful for all kinds of things, they
>> are not
>> 'central' to programming in Ruby. Some Ruby programmers tend to get a
>> bit
>> obsessive about blocks, procs, lambda functions and the like. If you
>> find
>> this stuff baffling (and unless you already have experience of a
>> language
>> such as Smalltalk or Scheme in which blocks are a 'natural' part of the
>> language), they may initially seem very baffling indeed, my advice
>> would be
>> to use blocks only where they are absolutely required - namely, for
>> iterating over collections of things as when, for example, iterating
>> over
>> the items in an array using the each() method.
>>
>
> Ruby's standard library is filled with methods that (often optionally)
> take blocks as arguments. Ignoring them isn't gonna do you any good. A
> closure is a function that remembers the environment it was defined
> in, and if you don't understand the concept of a function, programming
> is not for you.
>
>> I wouldn't worry at all about using blocks as 'nameless functions' or
>> passing and 'yielding' them. These can be useful in certain
>> circumstances
>> but then again, you could spend a lifetime doing perfectly productive
>> programming in Ruby without ever doing any of those things ;-)
>>
>
> Ignoring closures, which are extensively used within Ruby's standard
> library and a large part in what makes the language so good for many
> tasks, is not going to do you any good at all.
Perhaps not, but it's like that advice they give for taking tests...if
you find yourself getting hung up on a particular question, skip it and
come back to it later.
Except, you have much more time to skip blocks/closures for now and come
back to them later than problems on a test.
If it doesn't make sense now, get familiar with other parts of Ruby and
then come back to blocks, if it's getting frustrating.
-Justin