Code reuse is one of the key steps to maintainability. There are many ways a developer might make their code reusable. For example, Steve’s co-worker wrote this block, which generates 1000 log entries:
int next = 0;
List<FeedSearchTransactionLogResult> allDataSimulated = new List<FeedSearchTransactionLogResult>();
allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));
allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));
allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));
//SNIP skip 995 lines…
allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));
allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));
allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));
At least, it might be 1000 log entries. It’s hard to tell. The original developer reused the hell out of that one line of code. This block is easy to modify- if the number of iterations ever changes, a developer simply needs to add or remove the correct number of lines.
Now that’s reusable code.
[Advertisement]
BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!