I was assigned a code review to one of my colleagues. I posed the following, which I wanted to share here in order to hear whether I am right or wrong.
Consider the following code snippet:
public void DoSomethingWithList()
{
var list = AnotherClass.GetList();
var itemsToRemove = list.Where(...);
list.Remove(itemsToRemove);
.
.
.
}
I argue that the method above should have list
declared as a dependency (in other words, declared as a parameter in the method's signature). Why ? To follow the Single Responsibility principle, and/or for testing purposes. (I think this is the case for an external class call, but even if GetList
was a private method inside the same class, I would still claim the same - even if the sole motif would be code clarity (call it "purpose clarity").
My colleague says this is not so. Having to call this function every time always passing the same parameter is cumbersome.
I obviously understand that as a developer, but I insisted that the "software engineering principles aimed at code maintainability" should prevail over "developer laziness" (myself included !)
I do understand there are no bulletproof rules, but nevertheless that they should only be broken for a very good reason.
I wonder whether I am wrong. And if am I not, which other aspects I did not mention should have been.
AnotherClass.GetList()
a static method?