I admit that this question is subjective but I am interested in the view of the community. I have a cache class that takes a cache loader function of type Func<TResult>, which it uses to retrieve a value from the database and store it in cache.
public static class Cache
{
public TResult Get<TResult>(string cacheKey, Func<TResult> cacheLoader)
{
// Implementation
}
}
My question is: How should I name the function parameter?
- Should I name it like an object, e.g.
cacheLoader? - Should I name it like a method, e.g.
loadResult? - Should I explicitly refer to it as a function, e.g.
cacheLoadFunction? (I don’t like this.)
I’m less interested in what I should name this particular function parameter and more interested in how you name function parameters in general. What say ye, Stack Overflow community?
There are precedents for using a noun in the Framework, e.g.
The noun is often an appropriate verb with an agentive suffix.
In your example I would use something like
loaderor possiblyvalueFactory. I personally don’t likecacheLoaderbecause presumably it’s the caller rather than the delegate that does the work of inserting in the cache.