• A Study in Array#Collect
    Stephen Chu talked about how to beautify statements like customers.collect { |customer| customer.name } in one of his posts . Dr. Nic also has a post talking about the same thing. It's very interesting to see so many people want to get away the cumbersome collect syntax and I am one of these people. To beautify the collect syntax when we need just one field such as customer.name . There are several ways:to use Stephen's syntax: customers.collect_name Dr. Nic's : customers.names And guess what, if you are using Rails, it comes with a Symbol extension...
    read more
  • Permalink: Tuesday, December 04, 2007 11:14 AM
    Posted by ywen | 0 Comments
    Filed under
  • Why I hate test coverage tools
    Because it could lie if we abuse it. I have been in one project where people count acceptance tests (written in FIT) so the test coverage always looks pretty high when the unit tests coverage are actually poor. But the figure gave people there false confidence that their code is in good shape. In another project, a test had only two lines of code, but it actually ran about 5 seconds and touched a lot of code underneath. So by this test alone, it improved the test coverage a lot, looks pretty good eh? Then wait until it failed sometimes. People had...
    read more
  • Permalink: Monday, November 19, 2007 3:42 PM
    Posted by ywen | 1 Comments
    Filed under ,
  • When RSpec meets Validatable
    Jay Fields writes an excellent module called Validatable to provide a class who include the module the ActiveRecord like behavior. For example, you can say validates_presence_of :attribute etc. This page has the RDoc of the module. When I write RSpec for a Validatable class, I ended up writing a stattement like this: @email.validate_only("presence_of/body") @email.errors.on(:body).should_not be_nil Which is basically testing body is a required field. It works, but it looks complicated and hard to understand. The RSpec on Rails plugin provides a...
    read more
  • Permalink: Monday, November 12, 2007 10:36 AM
    Posted by ywen | 0 Comments
    Filed under , ,
  • Law of Demeter and Forwardable
    Dan Manges has an excellent post explaining Law of Demeter and when it makes sense to use Forwardable to comply the principle, or I should say when it doesn't make sense to use the module. The point is, use it when it makes sense. Take his example, customer_name is just not a sensible method for an order. Asking an order for its customer name is a wrong question because all the order should care is who is its customer. The name is irrelevant to the order. In fact, I think by putting cusomer_name method in an order. the encapsulation is actually...
    read more
  • Permalink: Friday, November 02, 2007 1:26 PM
    Posted by ywen | 0 Comments
    Filed under
  • Fluent interface for Ruby delegation
    This is a link to Bryan's blog for Fluent interface for Ruby delegation. We used it in our codebase for better (read: more readable) syntax. You might be interested in.
  • Permalink: Monday, October 29, 2007 5:26 PM
    Posted by ywen | 0 Comments
    Filed under