Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Get a Whiff of This

Get a Whiff of This

A talk about code smells

Sandi Metz

May 06, 2016
Tweet

More Decks by Sandi Metz

Other Decks in Programming

Transcript

  1. @sandimetz May 2016 Classic Smells Alternative Classes w/ Different Interfaces

    Comments Data Class Data Clumps Divergent Change Duplicated Code Feature Envy Parallel Inheritance Hierarchies Primitive Obsession Refused Bequest Shotgun Surgery Speculative Generality Switch Statements Temporary Field Inappropriate Intimacy Incomplete Library Client Large Class Long Method Long Parameter List Message Chains Middle Man Lazy Class
  2. @sandimetz May 2016 Alternative Classes w/ Different Interfaces Comments Data

    Class Data Clumps Divergent Change Duplicated Code Feature Envy Parallel Inheritance Hierarchies Primitive Obsession Refused Bequest Shotgun Surgery Speculative Generality Switch Statements Temporary Field Classic Smells Inappropriate Intimacy Incomplete Library Client Large Class Long Method Long Parameter List Message Chains Middle Man Lazy Class
  3. @sandimetz May 2016 Alternative Classes w/ Different Interfaces Comments Data

    Class Data Clumps Divergent Change Duplicated Code Feature Envy Parallel Inheritance Hierarchies Primitive Obsession Refused Bequest Shotgun Surgery Speculative Generality Switch Statements Temporary Field Classic Smells Inappropriate Intimacy Incomplete Library Client Long Method Long Parameter List Message Chains Middle Man Lazy Class Large Class
  4. @sandimetz May 2016 Alternative Classes w/ Different Interfaces Data Class

    Data Clumps Divergent Change Duplicated Code Feature Envy Parallel Inheritance Hierarchies Primitive Obsession Refused Bequest Shotgun Surgery Speculative Generality Switch Statements Temporary Field Classic Smells Inappropriate Intimacy Long Method Long Parameter List Message Chains Middle Man Lazy Class Large Class
  5. @sandimetz May 2016 Divergent Change Parallel Inheritance Hierarchies Shotgun Surgery

    Alternative Classes w/ Different Interfaces Refused Bequest Switch Statements Temporary Field Feature Envy Inappropriate Intimacy Message Chains Middle Man Data Class Duplicated Code Speculative Generality Lazy Class Data Clumps Primitive Obsession Long Method Long Parameter List Large Class
  6. @sandimetz May 2016 Alternative Classes w/ Different Interfaces Refused Bequest

    Switch Statements Temporary Field Divergent Change Parallel Inheritance Hierarchies Shotgun Surgery Feature Envy Inappropriate Intimacy Message Chains Middle Man Data Class Duplicated Code Speculative Generality Lazy Class Data Clumps Primitive Obsession Long Method Long Parameter List Large Class Bloaters
  7. @sandimetz May 2016 Tool Abusers Alternative Classes w/ Different Interfaces

    Refused Bequest Switch Statements Temporary Field
  8. @sandimetz May 2016 Divergent Change Parallel Inheritance Hierarchies Shotgun Surgery

    Alternative Classes w/ Different Interfaces Refused Bequest Switch Statements Temporary Field Feature Envy Inappropriate Intimacy Message Chains Middle Man Data Class Duplicated Code Speculative Generality Lazy Class Data Clumps Primitive Obsession Long Method Long Parameter List Large Class Bloaters Abusers Divergent Change Parallel Inheritance Hierarchies Shotgun Surgery
  9. @sandimetz May 2016 Divergent Change Parallel Inheritance Hierarchies Shotgun Surgery

    Divergent Change Parallel Inheritance Hierarchies Shotgun Surgery
  10. @sandimetz May 2016 Data Class Duplicated Code Speculative Generality Lazy

    Class Feature Envy Inappropriate Intimacy Message Chains Middle Man Divergent Change Parallel Inheritance Hierarchies Shotgun Surgery Alternative Classes w/ Different Interfaces Refused Bequest Switch Statements Temporary Field Data Clumps Primitive Obsession Long Method Long Parameter List Large Class Bloaters Abusers Preventers
  11. @sandimetz May 2016 Feature Envy Inappropriate Intimacy Message Chains Middle

    Man Data Class Duplicated Code Speculative Generality Lazy Class Divergent Change Parallel Inheritance Hierarchies Shotgun Surgery Alternative Classes w/ Different Interfaces Refused Bequest Switch Statements Temporary Field Data Clumps Primitive Obsession Long Method Long Parameter List Large Class Bloaters Abusers Preventers Dispensables
  12. @sandimetz May 2016 Feature Envy Inappropriate Intimacy Message Chains Middle

    Man Data Class Duplicated Code Speculative Generality Lazy Class Divergent Change Parallel Inheritance Hierarchies Shotgun Surgery Alternative Classes w/ Different Interfaces Refused Bequest Switch Statements Temporary Field Data Clumps Primitive Obsession Long Method Long Parameter List Large Class Bloaters Abusers Preventers Dispensables Couplers
  13. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  14. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  15. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  16. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  17. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  18. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  19. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  20. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  21. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  22. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  23. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  24. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  25. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  26. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  27. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  28. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  29. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  30. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  31. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  32. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  33. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  34. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  35. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  36. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  37. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  38. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end Kaboom
  39. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  40. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  41. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  42. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  43. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  44. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  45. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  46. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  47. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  48. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  49. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  50. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Larry def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Curly def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Mo def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  51. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Larry def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Curly def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Mo def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Fee def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Fi def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Foe def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  52. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Larry def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Curly def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Mo def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Fee def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Fi def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Foe def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  53. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  54. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  55. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  56. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  57. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  58. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  59. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  60. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  61. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  62. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  63. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  64. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  65. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  66. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  67. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end
  68. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  69. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  70. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Bar def weekly_sales_total(params) Sale.where(date: (start_date..end_date)).sum("cost") end end
  71. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: (start_date..end_date)).sum("cost") end end
  72. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end
  73. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end
  74. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  75. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  76. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Baz def expense_total(params) Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  77. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  78. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  79. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  80. @sandimetz May 2016 class Foo def sales_total(params) range = DateRange.new(starting:

    params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  81. @sandimetz May 2016 class Foo def sales_total(params) range = DateRange.new(starting:

    params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  82. @sandimetz May 2016 class Foo def sales_total(params) range = DateRange.new(starting:

    params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end Data Clump | Extract Class
  83. @sandimetz May 2016 class Foo def sales_total(params) range = DateRange.new(starting:

    params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  84. @sandimetz May 2016 class Foo def sales_total(params) range = DateRange.new(starting:

    params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  85. @sandimetz May 2016 Foo Sale Persistence where where List a

    list Sale.where(date: range).sum("cost") ??? ??? ???
  86. @sandimetz May 2016 Foo Sale Persistence where where List a

    list a list Sale.where(date: range).sum("cost") ??? ??? ???
  87. @sandimetz May 2016 Foo Sale Persistence where where List sum

    a list a list Sale.where(date: range).sum("cost") ??? ??? ???
  88. @sandimetz May 2016 List #sum Sale #where DateRange Foo I

    know my collaborators collaborators
  89. @sandimetz May 2016 class Foo def sales_total(params) range = DateRange.new(starting:

    params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  90. @sandimetz May 2016 class Foo def sales_total(params) range = DateRange.new(starting:

    params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  91. @sandimetz May 2016 class Foo def sales_total(params) range = DateRange.new(starting:

    params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  92. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  93. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  94. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end
  95. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end
  96. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end
  97. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end
  98. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end
  99. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end
  100. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end
  101. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end
  102. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  103. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  104. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.total(within: range) end end
  105. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.total(within: range) end end
  106. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.total(within: range) end end
  107. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.total(within: range) end end
  108. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.total(within: range) end end Message Chain | Hide Delegate
  109. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end
  110. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end
  111. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end
  112. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end
  113. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  114. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  115. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  116. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end Check the query result
  117. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  118. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  119. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  120. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end Depend on Sale class?
  121. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  122. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  123. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end Depend on Totalizable role!
  124. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  125. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  126. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  127. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  128. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  129. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  130. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  131. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  132. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end Two players of the Totalizable role
  133. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  134. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  135. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  136. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  137. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} assert_equal 28, Foo.new.sales_total(params) end end
  138. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} model = TotalizableDouble assert_equal 28, Foo.new.sales_total(params) end end
  139. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} model = TotalizableDouble assert_equal 28, Foo.new.sales_total(params) end end
  140. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} model = TotalizableDouble assert_equal 28, Foo.new.sales_total(params, model) end end
  141. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} model = TotalizableDouble assert_equal 28, Foo.new.sales_total(params, model) end end
  142. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} model = TotalizableDouble assert_equal 47, Foo.new.sales_total(params, model) end end
  143. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} model = TotalizableDouble assert_equal 47, Foo.new.sales_total(params, model) end end FAST
  144. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} model = TotalizableDouble assert_equal 47, Foo.new.sales_total(params, model) end end
  145. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # FAST Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} model = TotalizableDouble assert_equal 47, Foo.new.sales_total(params, model) end end
  146. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end
  147. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end
  148. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end
  149. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end
  150. @sandimetz May 2016 module Totalable def total(within:, date_field: :date, on:

    "cost") where({date_field => within}).sum(on) end end class Sale < Persistence def self.total(within:) where(date: within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end
  151. @sandimetz May 2016 module Totalable def total(within:, date_field: :date, on:

    "cost") where({date_field => within}).sum(on) end end class Sale < Persistence def self.total(within:) where(date: within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end
  152. @sandimetz May 2016 module Totalable def total(within:, date_field: :date, on:

    "cost") where({date_field => within}).sum(on) end end class Sale < Persistence def self.total(within:) where(date: within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end
  153. @sandimetz May 2016 module Totalable def total(within:, date_field: :date, on:

    "cost") where({date_field => within}).sum(on) end end class Sale < Persistence def self.total(within:) where(date: within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end Speculative Generality
  154. @sandimetz May 2016 module Totalable def total(within:, date_field: :date, on:

    "cost") where({date_field => within}).sum(on) end end class Sale < Persistence def self.total(within:) where(date: within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end Dependency Injection Is Awesome
  155. @sandimetz May 2016 module Totalable def total(within:, date_field: :date, on:

    "cost") where({date_field => within}).sum(on) end end class Sale < Persistence end class Expense < Persistence end
  156. @sandimetz May 2016 module Totalable def total(within:, date_field: :date, on:

    "cost") where({date_field => within}).sum(on) end end class Sale < Persistence extend Totalable end class Expense < Persistence extend Totalable end
  157. @sandimetz May 2016 module Totalable def total(within:, date_field: :date, on:

    "cost") where({date_field => within}).sum(on) end end class Sale < Persistence extend Totalable end class Expense < Persistence extend Totalable end
  158. @sandimetz May 2016 module Totalable def total(within:, date_field: :date, on:

    "cost") where({date_field => within}).sum(on) end end class Sale < Persistence extend Totalable end class Expense < Persistence extend Totalable end Duplicated Code | Pull Up Method
  159. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  160. @sandimetz May 2016 module Totalable def total(within:, date_field: :date, on:

    "cost") where({date_field => within}).sum(on) end end class Sale < Persistence extend Totalable end class Expense < Persistence extend Totalable end
  161. @sandimetz May 2016 class Foo def sales_total(params, model=Sale) range =

    DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end class Bar def weekly_sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting]).week_range model.total(within: range) end end class Baz def expense_total(params, model=Expense) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end
  162. @sandimetz References May 2016 http://martinfowler.com/books/refactoring.html http://www.refactoringinruby.info/ Kevin Rutherford, William Wake

    Mäntylä, M. V. and Lassenius, C. "Subjective Evaluation of Software Evolvability Using Code Smells: An Empirical Study". Journal of Empirical Software Engineering, vol. 11, no. 3, 2006, pp. 395-431. https://github.com/troessner/reek https://blog.codeship.com/how-to-find-ruby-code-smells-with-reek
  163. @sandimetz Credits May 2016 Coffee on a Winter's morning, Stefan

    Lins, https://www.flickr.com/photos/mrlins/8533102693/ Royal Australian Air Force in Australia during World War II, Argus Newspaper Collection of Photographs, State Library of Victoria, https://www.flickr.com/photos/statelibraryofvictoria_collections/16554906225/ Chevy Crusher, Ruby Eng , https://www.flickr.com/photos/mac-ash/4105522760/ Misuse Makes Mishaps, Jeremy Brooks , https://www.flickr.com/photos/jeremybrooks/2205135193, resistance is futile, Lora, https://www.flickr.com/photos/laroyo/6871150550/ Well this is pointless, Janet McKnight, https://www.flickr.com/photos/janetmck/2613441853/ Glue goo 3, Sam-Cat, https://www.flickr.com/photos/samcatchesides/3326878644/ poses of victory, Daniel Novta, https://www.flickr.com/photos/vanf/7304661962/ Odorous smells!, auddess, https://www.flickr.com/photos/auddess/4744679975 EXPLORE] Smell the Flowers, Christine und David Schmitt, https://www.flickr.com/photos/cheesy42/8624536219/ PIZZA, Tobi Gaulke. https://www.flickr.com/photos/gato-gato-gato/15958062095/ Ain't Life Grand, Anne Worner, https://www.flickr.com/photos/wefi_official/9305161946/