Sometimes I write a method in a way that I know is extremely poor style but it works. For example, I was recently developing in VisualWorks and needed to route mouse wheel events from a subcanvas to the scroll bar to allow the subcanvas to be scrolled with the scroll wheel. Since I knew that the scroll wheel worked when you were on the scroll bar, I located the scroll bar using code that said something like mySubcanvas container container components last component components first component controller mouseWheelEvent: anEvent. I knew that it was the wrong way to write the method because it made too many assumptions but it worked. As soon as I got it working, I analyzed why it worked and how to simplify it. I was then able to get it to work in a much less brittle way. Sometimes, though, it's easier to write messy code that works then immediately simplify it to make it work right.
Download