Refactoring to generalize

Today at work I was refactoring some of my initial code and it was a great feeling.
First I was doing something like

myUpdate(long id, byte bytAnswer1, byte bytAnswer2, byte bytAnswer3, byte bytAnswer4, ....)

to fill a stored procedure with

MyCallableStatement.setByte (4, bytAnswer2);

Then I realized how stupid it is to make the method signature dependable on the amount of AnswerBytes. So I changed it to

myUpdate(long id, byte[] Answers)

which is much shorter and better from the maintenance point of view.
This also gave me the opportunity to change 10 calls of the above setByte statement to a generic

final int anzAnswers = 10;
for (int i=0;i MyCallableStatement.setByte (i+1, Answers[i]);

I know that it is nothing special, but was a great feeling for me to see how the code evolved and to see the step by step improvement.

Posted by Karsten at 16.06.04 14:45 | TrackBack
Post a comment

Remember personal info?