Tuesday, June 26, 2012

Curry in Ruby

While I was wandering around Proc and Lambda in Ruby, I found very useful method Proc#curry. This method answer the question that bugs me for a while, is there an easy way to make Curry happen in Ruby? Let look at the example how to use it.


Start with a simple method:
def sum(x,y,z)
x+y+z
end
puts sum(2,3,4)
=> 9
view raw sum.rb hosted with ❤ by GitHub
Manually currying: 
sum = -> x { -> y { -> z { x + y + z } } }
puts sum[2][3][4]
=> 9
view raw manual_sum.rb hosted with ❤ by GitHub
But with Proc#curry, you can heavily simplify your code like this:
sum = ->x,y,z { x + y + z }.curry
puts sum[2][3][4]
=> 9
view raw curry_sum.rb hosted with ❤ by GitHub
Pretty neat!

Sunday, June 3, 2012

Benefits of TDD

I just read a blog post about TDD and really like it, TDD for Those Who Don't Need It. It reminds me to my first impression when I start practicing TDD more than a year ago, it allows us to not have to to hold everything in our head.

By the way, that post also mentions to other TDD benefits. I want to note it down here just for a reference.
  • Not have to hold everything on our head. Just follow errors.
  • Confidence to refactor
  • Better design
  • Documentation
  • Regression

Collectd PostgreSQL Plugin

I couldn't find this link when searching with google https://www.collectd.org/documentation/manpages/collectd.conf.html#plugin-postgresq...