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 1038703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:00:31+00:00 2026-05-16T15:00:31+00:00

When working on the early stages of a console-based Python remake of the classic

  • 0

When working on the early stages of a console-based Python remake of the classic game ‘Snake’, someone submitted a patch to spawn food at random locations. The code defined a Food class which worked fine, but the logic behind it seemed a little weird.

I think we should delete the food once it’s been consumed, then create another one. However, this person simply moves the food to a new random location once it’s been consumed. While the latter seems illogical to me, it seems to do the exact same thing, maybe even more efficiently.

My question is: Would it be better to use the former logic, or the later, or am I simply nit-picking over nothing?

This all started at: https://bugs.launchpad.net/snakes-game/+bug/628180

  • 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-16T15:00:31+00:00Added an answer on May 16, 2026 at 3:00 pm

    Either is fine – within certain common-sense boundaries.

    The latter approach will save re-allocating the object, so recycling it in this way will be more efficient – the gain is likely to be irrelevant in your particular example though unless heap fragmentation is a concern (e.g. on an embedded app with very limited RAM).

    The danger with recycling is that the object may retain some vestige of its former state, so may not behave in the same manner as a new object would – in your case the logic is simple, so there is little danger, but with more complex objects this could become significant.

    So in general I’d suggest the “create a new object” approach (it follows the principle of “least surprise”, and will be less likely to confuse other programmers who come to work on the code) unless there are performance implications (e.g. on an embedded application like a phone where you have very limited resources and don’t want a fragmented heap), in which case the “re-use an existing object” may be a smart solution.

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

Sidebar

Related Questions

I'm working on early designs for an application that needs to start out small
I am working though some simple DX tutorials, and have hit an early snag.
Working on a small game using an HTML5 canvas, and javascript. And it's working
I am in the early stages of building an app using Rails 3. User
I am working on a small project which involves a dictionary based text searching
I'm currently busy working on an IP ban tool for the early versions of
I am currently working through the Gregory Brown Ruby Best Practices book. Early on,
In my early days of programming, before I started working professionally, I wrote a
I'm in the early stages (read:just started yesterday) of a project, and I'm setting
I'm a newbie at C, in the early stages of building a small Scheme

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.