Frustration Driven Development

Evan Light

Freelance Code Janitor

@elight

evan.light@tripledogdare.net

Real Talk

(or "a recipe to put me out of business")

How I want to feel

How I often feel

How did I get this way?

Your tax dollars at work

Easy come, easy go!

Workin for the man... me!

I've been doing this a while...

... and I've seen a lot of shit

It pisses me off

Let's talk about hate

mangaholix

We love to talk about TDD

Most Rubyists don't write tests!

FFFFUUUUUUU

TATFT

The Long & Poorly-Named Method

(or, in the words of Samuel L. Jackson, "it's Red, Green, Refactor mother%&@#er!")

FFFFUUUUUUU

Most Rubyists don't refactor!

Don't try to read this code

We're going to operate!

Put it on life support

Stub out dependencies in test setup

Test all branches

Test all boundaries

Watch tests pass

Great book on the topic: Working with Legacy Code

Now, operate!

Extract method

Extract method (cont'd)

Rename method

Let's focus here

Extract class

Then we have...

A couple more Extract methods later

Should User know how to rectify his own account

Hint: rectify & account

Think about it (later ;-) )

The typical "User" class

FFFFUUUUUUU

Move code into modules?

See Mixins, a Refactoring Anti-Pattern

Get a lackey!

Let's face it:

Most templates suck

FFFFUUUUUUU

You could use Helpers...

Helpers are poor objects

What if we delegate to real objects?

Replace this...

... with this

We still have to pick a "presenter"

Presenters probably should not be your first choice

How do I choose?

Want to try using presenters?

modest_presenter

Warning: I wrote this ;-)

Simple implementation but flexible

draper

Convention driven usage but complex implementation

Monkey patching

FFFFUUUUUUU

Dependency injection

Fork, patch, and pull request!

There is no monkey patch

Breaking Demeter

FFFFUUUUUUU

"Law of Demeter" redux

You can play with your friends

You can play with your privates

You shouldn't play with your friend's privates

Style

FFFFUUUUUUU

Get some

Not considering your audience

FFFFUUUUUUU

Be a hero in private

Breaking convention

FFFFUUUUUUU

Predictable is good!

Vocabulary

Get one

Better

But enough code

Your career at first

Midichlorians?!?!1!!

What you're left with

Stretch out with your feelings

We believe in what we do...

... but we often lose sight of what matters

Thank you

Citations

Working with Legacy Code

Refactoring

Mixins, a Refactoring Anti-Pattern

modest_presenter

draper

Regrets of the Dying

Damien Katz @ RubyFringe

Huntington's Disease Society of America

#

/