Programming

Jason Cheong-Kee-You edited this page Sep 26, 2017 · 1 revision

Steps

  1. Pre-test refactor for legacy code: Sprout Method, Sprout Class, Wrap Method, Wrap Class
  2. Write test: Arrange, Act, Assert
  3. Write code
  4. Refactor code
    Smell Refactoring
    Large class Extract Class
    Apply Single Responsibility
    Long method Extract Method
    Make Composed Method
    Code not self-explanatory Rename
    Make Composed Method
    Apply Ubiquitous Language
    Apply Single Responsibility
    Duplication Extract Method
    Extract Class
  5. Refactor test
    Smell Refactoring
    Test method name says "what", not "why" Rename to communicate "why"
    Multiple asserts in test method 1 assert per test method
    Long data setup Create Test Data Builders
    Complicated setup of collaborators Use mocks
    Fragile shared fixtures No shared fixtures between test classes

References

Model the Domain

Object Categories

  • People: Actor, Role
  • Places: Place, Outer Place
  • Things: Item, Specific Item, Assembly, Part, Container, Content, Group, Member
  • Events: Transaction, Composite Transaction, Line Item, Follow-up Transaction

Object Collaboration Patterns

  • Generic - Specific
    • Actor - Role
    • Item - Specific Item
    • Composite Transaction - Line Item
  • Whole - Part
    • Container - Content
    • Assembly - Part
    • Group - Member
    • Outer Place - Place
  • Transaction - Specific
    • Transaction - Role
    • Transaction - Specific Item
    • Transaction - Place
    • Follow-up Transaction - Transaction
    • Line Item - Specific Item

References

Refactoring Legacy Code

  1. Write regression test
    • Feed in input, have code generate output for assertions
    • Test all conditional branches
    • Test edge cases
    • Minimize number of tests
  2. Refactor code
    • Extract class, makes method extraction easier, because shared state is in member variables
    • Extract methods
    • Remove "chart junk"
    • Seek regularity in code. Make moves to make code more regular.

References

What and How to Test

Message Type
Query Command
Incoming Assert return value Assert public side effects
Sent to Self Don't test Don't test
Outgoing Don't test Use mock

References

5 Rules

  • 100 lines per class
  • 5 lines per method
  • 4 parameters per method (each hash parameter counts as 1)
  • 1 instance variable per rails view
  • 2 class names per rails controller action (business, presenter)

References

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.