|Keep It Simple, Stupid|
Why and how to re-use code to make better applications and you a better programmer. (discussion)by deprecated (Priest)
|on Jun 29, 2001 at 18:24 UTC||Need Help??|
My good friend Carl Manaster sent me this a couple days ago, and I was really taken with just cool it was, and how much I wished other programmers were as diligent as he is (and I try to be).
This is his work, I have permission.
I noticed myself doing something last night that I have done hundreds or thousands of times before, following a habit that I've unconsciously adopted. It worked - again - and I decided to formalize it, to make the practice easier to apply deliberately in the future, to better be able to determine appropriate situations for its application, and to share with others.
What I was doing was as follows. I had four little triangles to draw around the outside of circles forming an irregular shape. I wrote a routine to calculate the points of one of the triangles, with values for all of the coordinates that would only work for the first case. I then duplicated this routine, and reworked it for a second triangle. I then generalized the code, writing a routine that could handle any arbitrary triangle-outside-a-circle (within the context of my application), replaced the original two routines with calls to this one, and wrote the routines for the remaining triangles.
Here's the recipe:
and the rationale:
Note that at every step, except (4), you have something new to test. That's good - you don't save up all the bugs for the final step. It is also a fairly even distribution of thoughtload, so you're never bored or overwhelmed.