Posted over 7 years ago. Visible to the public.

Software design basics [2d]


Read the following chapters from The Pragmatic Programmer (in our library):

  • Software Entropy
  • The Evils of Duplication
  • Orthogonality
  • Decoupling and the Law of Demeter
  • Evil Wizards

Read the following chapters from Clean Code (in our library):

  • Chapter 1: Clean Code
  • Chapter 2: Meaningful Names
  • Chapter 3: Functions
  • Chapter 4: Comments
  • Chapter 5: Formatting
  • Chapter 8: Boundaries
  • Chapter 10: Classes
  • Chapter 12: Emergence
  • Chapter 17: Smells and Heuristics

Also read:

Read the following chapters from our book Growing Rails Application in Practice:

  • Dealing with fat models
  • Extracting service objects

Discuss with your mentor what you took away from each topic.


We're building an e-commerce app where users can create and view invoices.

This is our current model:

class Invoice < ApplicationRecord
  has_many :items
  validates_presence_of :recipient_address, :number

class Invoice::Item < ApplicationRecord
  belongs_to :invoice
  belongs_to :product
  validates_numericality_of :units

class Product < ApplicationRecord
  validates_presence_of :description
  validates_numericality_of :unit_price

This is a view that shows an invoice:

  = @invoice.number

%h3 Recipient
= @invoice.recipient_address

%h3 Items

    %th Description
    %th Quantity
    %th Item total

  - @invoice.items.each do |item|
    %td= item.product.description
    %td= item.units
    %td= item.units * item.product.unit_price
      Invoice total
      = @invoice.items.sum { |item| item.units * item.product.unit_price } * 1.19

How would you judge the quality of this code?
Can you apply what you learned and improve the model and the view?

Henning Koch
Last edit
9 months ago
Henning Koch
About this deck
We are makandra and do test-driven, agile Ruby on Rails software development.
Posted by Henning Koch to makandra Curriculum (2015-07-07 17:22)