Hopefully this quiz caused some of us to read Martin F.'s
know it did exactly that for me, though it has been on my want-to-read
some time now. I’m half-way through it now and I can only recommend
reading this pick up a copy immediately.
Each of this week’s solutions came with its own write-up so there isn’t
left for me to dissect. Instead, I’ll take this chance to talk a little
the most interesting part of this exercise to me.
It’s my opinion that a large majority of the refactoring patterns were
with the static languages in mind. I’m very intrigued by how a language
Ruby changes the game. Let’s me see if I can give some examples.
First, I mentioned in my write-up that part of my refactoring called for
a method abstract. After some thought, I decided that meant deleting
in Ruby. (See my solution for the reasoning.)
Here’s another thought: many of the refactorings tell you to declare a
as final, to ensure that it isn’t changing. What’s the Ruby equivalent
I don’t think we have one. We can #freeze the object, but that won’t
help us if
the variable is reassigned. I don’t see a good answer there.
But there are two sides to every coin and we have some nice advantages.
example, Extract Method talks a lot about how the local variables can
extraction, especially if many of them are changed by the extracted
is much less of an issue in Ruby though, since we can have the extracted
take a block and use the variables in there however we need. In fact,
means we can use Extract Method quite a bit more often, since the code
just needs to be close to similar and we can handle the differences in
Dave B. was also thinking along these lines and went all the way to
some Ruby centric refactorings. Here’s an example:
Refactoring 2: Remove Unused Scope /You have a begin...end block that introduces a scope that is unused./ *Remove the unused scope.* Thus: def foo begin bar rescue baz end end Becomes: def foo bar rescue baz end
I would love to see many more of these. Perhaps we could come up with a
Similar Methods with Metaprogrammed Definitions and a Convert a Family
Methods to a Single method_missing() Call recipes. Food for thought.
A big thank you to all who supported this deviation from our usual fun
games. I think Pat hit on a super important topic here and we would all
to learn more about it.
Tomorrow, Matthew M. is back with a quiz about txet smnraiclbg…