I'm not sure I would describe it as a functional idea *per se*. It (or 
something similar) appears in Java (especially for handling the UI thread) 
and in JavaScript, and I first came across the general idea when writing UI 
callbacks (in C/C++) although in that case it was "named function plus user 
data" rather than "anonymous closure" but I think there are parallels.

On Wednesday, August 6, 2014 10:05:50 AM UTC+10, Dave Burt wrote:
>
> Hi Dan,
>
> I agree that using proc in case statements is probably more complex than 
> should generally be used, but if you're speaking more broadly when you say 
> "you’ll 
> rarely have a need to use Proc or similar concepts" I'd have to disagree.
>
> The idea of blocks in Ruby (and a Proc is just an object representing a 
> block) is core. It's how we do iteration (#each etc.), it's how we pass 
> code to threads or event handlers, it's used in DSLs in many libraries, and 
> if you don't "get it" you don't get Ruby.
>
> I recall myself struggling with the concept -- it is challenging coming 
> from a procedural background, as it's a functional idea -- but when it 
> clicked, that's when Ruby made sense.
>
> Cheers,
> Dave
>
>
> On Tue, Aug 5, 2014 at 5:22 PM, Dan Harper <[email protected] 
> <javascript:>> wrote:
>
>> On 5 Aug 2014, at 4:24 pm, Tim Moore <[email protected] 
>> <javascript:>> wrote:
>>
>> One thing that hasn't been mentioned yet, and which unfortunately I 
>> couldn't really address in the talk without a long tangent, is *why *would 
>> you want to write code like this in the first place? Is a proc in a case 
>> statement anything but a useless, overly-clever bit of language esoterica?
>>
>>
>> I had the same thought. After some musing, I came to the conclusion that 
>> you should opt for simpler code using simple concepts and cop the penalty 
>> of it being more verbose. Not everyone will agree I’m sure, and that’s cool.
>>
>> The advantages of having simpler code using simple concepts is that your 
>> code is now more easily understood by other developers with a lower level 
>> of Ruby knowledge.  This is the same reason I try to not perform Ruby 
>> gymnastics in tests. If I do decide to use some more complex code, I use 
>> comments to explain what I’m doing.
>>
>> This was probably more important back in the day when hardly anyone used 
>> Ruby, but I still follow it.
>>
>> If you’re just consuming gems (not authoring them) and say, coding in 
>> Rails, you’ll rarely have a need to use Proc or similar concepts. So when 
>> you’re learning, I’d say don’t bother with Proc and fancy Ruby concepts. 
>> Learn other things that will get you more productive at a faster rate.
>>
>> Dan
>>
>>
>> Dan Harper
>> [email protected] <javascript:>
>> Mobile:  0414 344 233
>>
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ruby or Rails Oceania" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>>
>> Visit this group at http://groups.google.com/group/rails-oceania.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rails-oceania.
For more options, visit https://groups.google.com/d/optout.

Reply via email to