Design is Refactoring


If Writing is Rewriting, Then Designing is Refactoring

Rust by Trial and Error

At this year’s Rocky Mountain Ruby, I mentioned to Steve Klabnik that I was trying (slowly) to learn Rust. He encouraged me to blog about anything I managed to hack together, as the Rust community deserves the kind of enthusiastic blogging that so greatly helped the Ruby community. At the same conference a couple of people mentioned that they really liked my deep dives into http://exercism.io problems.

So, let’s give the people what they want by blogging about doing Exercism in Rust!

Read More

In which a method tries to be too accepting

I frequently write methods like this:

def watch_magicians(magicians)
  magicians.collect { |magician| magician.magical_phrase }
end

a_bunch_of_magicians = [copperfield, blane, maskelyne]
watch_magicians(a_bunch_of_magicians)

Invariably I then need to watch a single magician, which I can only do like so

watch_magicians([ricky_jay])

Which seems unnecessary in a language like Ruby. If I were using type-checked language then I would write watch_magicians to require an Array. But no such requirement exists in Ruby, so why shouldn’t watch_magicians be able to work like this?

# with a collection
watch_magicians([henning, houdini])

# with just one magician
watch_magicians(jillete)

# with no magicians
watch_magicians(nil)
Read More

Building on the bones of your drafts

In my last post I talked about how our rough drafts have the power to reveal our humanity and our learning processes. But I never talked about how we actually improve our code, how we can build on our flawed early implementations and make them better.

Just as a writer doesn’t randomly change words and call the result a Second Draft, we can’t improve our code by just randomly tweaking things and pushing it to GitHub. Your commit log can be endlessly long and the code might still be a First Draft. So, how do we actually move from First Draft to Second? How do we build upon the bones of our drafts, each new layer better than the ones beneath?

Read More

The Power of Drafts

How do you write code? I’m not asking about text editor, language or keyboard layout. I’m talking more about your process. Do you write a bunch of perfect code all at once? Or do you write some terrible code, which you rewrite into less-terrible code?

Read More

Encapsulate Enumerable to Avoid Embarrassment

Vacations and work pulled me away from this blog for a bit, though I did manage to get a few newsletters out. But vacation time is over (for now) and it’s time to hop back into the Organizing Data section of Refactoring.

This week it’s Encapsulate Collection, which is full of great ideas. But its implementation is very Java-focused, heavy with reference to the Java Collections Framework. So, unlike past posts, I’m not going to focus as much on Fowler’s text, but rather the spirit of it when applied to Ruby and its Enumerables.

Read More