Is it clearer to sleep near a function call in a loop or in the function call itself? Personally I lean toward sleeping near the call rather than in the call, because there is nothing about "getApple()" that implies that it should sleep for some amount of time before returning the apple. I think it would be clearer to have:
for ( int i = 0; i < 10; ++i ) { getApple(); sleep() }
than...
for ( int i = 0; i < 10; ++i ) { getApple(); } Apple getApple() { sleep(1); return new Apple(); }
Of course, this would be different if the method were getAppleSlowly() or something.
Please let me know what you think.
Some additional information (also in comments below, see comments):
The wait is not required to get an apple. The wait is to avoid a rate limit on queries per minute to an API, but it is not necessary to sleep if you're only getting one apple. The sleep-in-get way makes it impossible to get an apple without sleeping, even if it is unnecessary. However, it has the benefit of making sure that no matter what, methods can call it without worrying about going over the rate limit. But that seems like an argument for renaming to getAppleSlowly().