How do you name a function that returns a generator (that is, uses yield foo instead of return foo)?
- It’s definitely not
getFoo()because it does not return a value of Foo. - It’s probably not
foos()because I’d rather have an easy-to-distinguish prefix. - It’s probably not exactly
listFoo()because it does not return alist. - It’s probably not
iterateFoo()because this prefix is too long.
What’s your preferred solution?
Update:
While foos() may be a perfectly good solution in some cases, note how method names tend to begin with a verb. The verb conveys the idea that this is a method, not a data field, and thus helps readability. If possible, I’d prefer a solution that makes it easy to tell a method from a data field.
Some terse suggestions:
Since you don’t normally need a generator to just get all your foos, it’s pretty common for the specific function of the generator to suggest a more interesting name: