Clean Code in Ruby by Robert Martin (Uncle Bob)

Usually gives this talk to Java developers; converted it to Ruby; talk shrunk in half.

What can we do with bad code?
“Grand Redesign in the Sky” by the “Tiger Team.” Bad idea: takes too long, and the poor fools stuck maintaining the legacy code hates them! Incremental improvement is a better alternative. That means:
- Always check it in a little bit better
- Never let the sun set on bad code
- Test first

The meat of the talk is a refactoring of a command line argument parser. My attention always wanders in these sorts of things. At least Uncle Bob asks us to raise our hands a lot (I don’t know why I am so interested in this exercise). Here are some highlights:
80% of the audiences tests
30% test first
10% measure test coverage
5% use RSpec
60% do metaprogramming
30% former Java programmers
5% former C programmers
5% former .Net programmers

“How many people have trouble maintaining if/else statements?” Maybe 10% of audience. Really? Sign them up to work on Con-way Bill Corrections!

Not too many people have heard of Open/Closed Principle.

No one intends to build a festering pile. But we don’t write the code right the first time.
Here’s a good way to ruin a program: make massive changes. The antidote is to use Test-driven Development (TDD) and keep all tests running 100% with every small change.

Side comment: “You guys still make things private? I don’t know if I still believe in that.”

News flash: RadRails successor (Aptana) can do some simple refactorings in Ruby like extract method.

Bad code: nothing has a more profound and long-term degrading effect
- Bad schedules can be redone
- Bad requirements can be redefined
- Bad team dynamics can be resolved: “Fire the asshole!”
- Bad code rots and ferments
- It becomes an inexorable weight that drags the team down

Professional write tests — first. Professionals clean their code. Professional know that the only way to go fast … is to go well.

You know, I can’t help but think that a lot of this is self-evident to any professional who takes their job seriously. I wonder, too, if it’s wasted on the audience — this is a group of people who choose to attend the Clean Code talk at RailsConf after all. Bob Martin is a good speaker, though. I’d like to send every mid-level developer I might work with some day to this talk.

Leave a Reply

You must be logged in to post a comment.

gears