Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7004437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:11:56+00:00 2026-05-27T21:11:56+00:00

Is it clearer to sleep near a function call in a loop or in

  • 0

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().

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:11:57+00:00Added an answer on May 27, 2026 at 9:11 pm

    I would not put the sleep into the function itself as long as the function name does not suggest that there will be a delay.

    There might be other callers to the function in the future who do not expect it to sleep.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem (simplified to make things clearer): 1. there is one statically-linked static.lib that has
I'm just reposting to make this clearer & because I've uploaded a sample of
Writing an operator< () for a struct appears to be clearer than writing the
what does this mean? (function($){ })(jQuery); to make the question clearer, what does wrapping
Can you suggest simpler and clearer way to write this function? let cartesian_product sequences
(Sorry this is rather a vague question. My attempts to be clearer [and indeed
Update2 I've rewritten the entire question, because some things became a lot clearer, the
The question is in the title but to make it clearer when you use
Technologies involved : ASP.NET Web-forms Javascript (jQuery for instance) Case To make it clearer
Is there a cleaner way for me to write debug level log statements? In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.