Monday, July 04, 2005
Instant Refactoring
I normally spend all day working in Eclipse writing Java source.
I quite like Eclipse's "Refactoring Browser" and use it a lot, one of my colleagues was surprised to discover what it does when I was demonstrating the "extract method" action.
Tonight I was working on some Blogger API related code in solely as mental exercise (there are several APIs already floating about), and I was satisfied when wrapping up the code at the length of the methods that I had been writing.
One of the tenets of Smalltalk, is developing small methods that can be combined into larger functional bodies, with a good refactoring browser, you can work the opposite way, develop logical code, and then refactor quickly into easy to maintain code...
paramNode: aValue typeString: aType
"Generate a <param> node for the XML-RPC Call, requires a value and
a type for that value. e.g.
paramNode: 'kevin' typeString: 'string' should return
<param><value><string>kevin</string></value><param>"
| paramNode |
paramNode := XML.Element tag: 'param'.
paramNode addNode: ((XML.Element tag: 'value')
addNode: ((XML.Element tag: aType)
addNode: (XML.Text text: aValue))).
^paramNode
This makes the following call easy...
paramNodes
"Generate the XML-RPC <params><param/></params> block"
| paramNodes |
paramNodes := XML.Element tag: 'params'.
paramNodes addNode: (self paramNode: (self appKey) typeString: 'string').
paramNodes addNode: (self paramNode: (self username) typeString: 'string').
paramNodes addNode: (self paramNode: (self password) typeString: 'string').
^paramNodes
