Home > Uncategorized > Split Loop – Refactoring

Split Loop – Refactoring

We had a discussion a couple of days back in the Agile Software Development Training.
We were talking about the Split Loop refactoring.

void printValues() {
	double averageAge = 0;
	double totalSalary = 0;
	for (int i = 0; i < people.length; i++) {
			averageAge += people[i].age;
			totalSalary += people[i].salary;
	}
	averageAge = averageAge / people.length;
	System.out.println(averageAge);
	System.out.println(totalSalary);
}

Not everyone was in agreement. One of my colleague raised the question, what if the number of records are more? If the number of records are more, then move the processing to data could be a better solution?? Does that mean putting business logic in stored procedures / sql?? May be not. Build a query in the business logic using something like NHibernate Query Generator so that the you don’t have to build you business logic in stored procedures. That said I still favor the Split Loop.

The criteria to use
1) Number of records
2) Is it a realtime application (more performance requirements) / embedded system
3) Is this the real performance bottleneck (address Macro optimizations, before running into Nano Optimizations like this)

Advertisements
Categories: Uncategorized
  1. ambati
    July 10, 2007 at 7:49 am

    Hi Sendhil,
     
    Can you provide some more information regarding basics of Split Loop – Refactoring?
     
    Regards,
    Sreedhar Ambati

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: