Categories
Coding

Rule of passing arguments

Rule is as follows:

If I need a sheep, I should be asking you only for a sheep.

I should not be asking you for an entire barn, and then waste time
searching through the barn to find that one sheep.

Even if I find a sheep, how do I know that that sheep is not sick,
and should not be eaten? And if I find 2 sheep, which one do I use?

So never declare requiring an object if you only need just one element inside that object. Just declare requiring that one element, and let the caller sort it out.

Following this rule does wonderful things for you, when you end up moving layers around, or refactoring things, of finding new ways to use certain module.