austinbv / dino

Dino is a ruby gem that helps you bootstrap prototyping with an Arduino
MIT License
389 stars 84 forks source link

Pass a block instead of a Proc object. Only Button implemented as a matter of principle #9

Closed dovadi closed 11 years ago

dovadi commented 11 years ago

I prefer this:

button.down do
  puts "button down"
end

button.up do
  puts "button up"
end

instead of:

button_down = Proc.new do
  puts "button down"
end

button_up = Proc.new do
  puts "button up"
end

button.down do
  button_down
end

button.up do
  button_up
end

Issue: backward compatibility

dam5s commented 11 years ago

I wonder why it was not using blocks from the beginning, so I'm going to let Austin merge this. There might be a reason... I don't know.

austinbv commented 11 years ago

I like this a lot I just don't like changing the interface of buttons, it would be nice if you could pass them a proc, or yield a block.

dovadi commented 11 years ago

OK, it's your call, but again I would choose for a block. I wouldn't maintain the proc option just for backward compatibility. In my view it would introduce extra complexibility, a lot of extra test code to maintain and this for a very young library with, I assume, flexible users who would easily adapt to the new api :-)

austinbv commented 11 years ago

Very valid point

jcasimir commented 11 years ago

For the audience I work with (kids), I think the block is easier to understand. They're already familiar with them from core Ruby (dealing with enumerations, etc).

To us as experienced programmers, the difference between a Proc and block is actually quite small. But to new devs this might very well be the first time they ever see Proc.

austinbv commented 11 years ago

With that said let's merge this in and release the gem.