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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:36:02+00:00 2026-06-18T08:36:02+00:00

This question came to my mind because I was working on a project, and

  • 0

This question came to my mind because I was working on a project, and I created the following method:

private void GoToFirstPage() {
    CurrentPage = 0;
}

which I use in a few methods related to pagination.

Is it a good idea? Or should I be calling CurrentPage = 0; instead in all the method calls?

  • 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-06-18T08:36:03+00:00Added an answer on June 18, 2026 at 8:36 am

    First, how likely is it that you’d ever change the implementation of GoToFirstPage? For example, if this is, say, a PDF viewer, might the next version have a continuous scrolling mode as well as a page-by-page mode, so you’ll keep a CurrentTopLine instead of a CurrentPage? In that case, if you’ve got CurrentPage = 0; in 15 different places, and you have to change all 15 of them to if (PageMode) CurrentPage = 0; else CurrentTopLine = 0;, that’s a perfect opportunity for stupid bugs to creep into your code because you forgot about 1 of them and only changed 14. If you’ve got it in a method, you only need to change things in one place.

    In some cases, having a name for the method gives you some extra documentation (and unlike a comment, it won’t get stale as things change, because you have to keep it up to date or things won’t compile). In this case, I don’t think that’s relevant, because CurrentPage = 0; is just as readable and meaningful as GoToFirstPage();, but in many cases, it is.

    Occasionally, performance is a concern. Function calls aren’t free, after all. But in this case, it’s hard to imagine it could ever matter. It’s not like you’re going to call GoToFirstPage millions of times in a tight loop, right?

    So, if none of these are relevant, how do you decide? The most important factor is probably what’s more idiomatic for your language, codebase, etc. In a typical Java program, a function like GoToFirstPage(); would fit in perfectly, and it might even be implemented as SetCurrentPage(0); for another layer of encapsulation. In a typical Python program, the current_page property would be part of even the public API of the class. Neither one is necessarily bad or good, and consistency of style is important in keeping your code readable.

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

Sidebar

Related Questions

What is the difference between above two? This question came to my mind because
I was working on shared memory and this question came in my mind so
This question came to mind after reading the answer to this question; which basically
This question came to my mind while working on 2 projects in AI and
This question came to my mind when I learned C++ with a background of
This question came about because the cells gem specifies template directories using File.join('app','cells'). That
This question came to my mind quite a few times. Let my explain my
This question came to my mind while I am reading the post Why doesn't
While writing a simple server-client application, this question came in my mind. When someone
I was reading about bit array and this question came up in my mind.

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.