Skip to content

Instantly share code, notes, and snippets.

@pdougall1
Last active November 3, 2015 20:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdougall1/e79fee71e3997fe13f09 to your computer and use it in GitHub Desktop.
Save pdougall1/e79fee71e3997fe13f09 to your computer and use it in GitHub Desktop.
POODR class notes (day 2)

Code smells, get really good at code smell (brown bag)

All you have to know is the codes smells

make a million new things > mutate objects

Forwardable (delegation)

Don't go on a virtical tangent, instead tiptoe away and finish the horizontal refactor

code smell: DATA CLUMP

want it to become an object

I know that to_s is mine,

Replace Conditionals With Polymorphism

Make the change easy (this might be hard), then make the easy change. - Kent Bech

working responsably with legacy code

The process of design is about discovery. The design will emerge.

Avdi Grimm

Start with the highest level test, make that pass in the dumbest way possible

Code climate
  • should be a solid B
  • alwasy asks for Churn vs complexity
  • High in churn, low in complexity; ex: config files
  • Log in churn, high in complexity; ex: sheet music for church quire app
  • High in churn, high in complextiy; ex: user [DANGER]

most code doesn't matter, and you should not care about things that don't matter; churn vs complexity helps us understand about, stuff

Use for for factories, use it consistently communicates intent, that it's always a factory.

Sadly must check type :( to return early if type is a BottleNumber: it's a traditional shim to port to factory.

eventually ^ replace conditional with polymorphism.

"Pass me the object I'm supposed to operate on!"

Ways to get rid of 3 dependancies

  • want less stable things to depend on more stable things
  • String should not depend on me

MONKEY PATCH

  • follows conventions of OO
  • "Those objects are mine!"
  • Not much fear of name colision
  • Is name colision the only concern?
    • Overriding a method that is used somewhere else; BIG ONE
    • really hard to find the methods
    • magic methods
    • not really a natural extension of the object
  • "smalltalk you ceate a DSL for your app", Avdi said and Sandi agrees.
  • "Java people create brand new objects"
  • When it's safe
    • "I scalded my child once and now I'll never wash them"
    • may never
    • must intervene in the smallest possible way
    • code must be needed in more than one place
    • name has to be specific to your domain that the chance of override by ruby is nearly impossible.
    • "restricted" monkey patch; use a refignment
    • must check that it isn't already deifned.

CONVERSION (Avdi) alternative to ^

  • Integer('1')
  • little different from '1'.to_i
  • idempotent == String('string') => 'string'

Relationship to objects

reduce polution in base classes

Figure out what changed

Avdi (make a little vidual graph)

  |INPUT - NAME (smalest level of abstraction)
  |data  - shuffle
  |DATA  - <blank>

There are two distinct ideas, need orders.

Omega messes, Push all messes back into those

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment