Skip to content

Instantly share code, notes, and snippets.

View cpytel's full-sized avatar

Chad Pytel cpytel

View GitHub Profile
@cpytel
cpytel / gist:4176695
Created November 30, 2012 16:09
Ask Giant Robots question from Nathan Long
Ben - I watched your talk, "Refactoring from Good to Great", and really enjoyed it.
I'm curious about how you apply the Law of Demeter in your programs.
Suppose you have a time-tracking app for your consulting business. The billing calculation
for a task might include looking up `task.project.contract.client.state.tax_rate`.
Clearly this is bad, and will make testing difficult; that's a lot of objects to set up
before making an assertion about a task! But I don't like the idea of littering the
task with methods that exist solely to reach across the system, like
`def project_contract_client_state_tax_rate`, and doing the same to all the objects
<?xml version="1.0" encoding="UTF-8"?>
<group>
<action>create</action>
<controller>session</controller>
<created-at type="datetime">2008-07-09T20:06:44-07:00</created-at>
<error-class>NoMethodError</error-class>
<error-message>NoMethodError: undefined method `password' for nil:NilClass</error-message>
<file>[RAILS_ROOT]/app/models/user.rb</file>
<id type="integer">5529</id>