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

  • Home
  • SEARCH
  • 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 6971067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:47:29+00:00 2026-05-27T16:47:29+00:00

Hopefully this will not come across as a silly or pedantic question, but I’m

  • 0

Hopefully this will not come across as a silly or pedantic question, but I’m curious.

Occasionally I’ll be in a situation where an existing object’s properties may need to be updated with new variables, and I’ll do it like this (in no particular language):

public void Update(date, somevar){
 if(date > this.Date){
  this.Var = somevar;
 }
}

The idea being that if the date passed to the function is more recent than the date in the current object, the variable is updated. Think of it as like a basic way of caching something.

Now, the interesting part is that I know somevar will never be “old” when compared to this.Var, but it may be the same. So as far as I can see, checking the date is pointless, and therefore a pointless operation for the program to perform.

So what this is really about is whether it’s better – in whatever way – to perform a write to this.Var every time Update is called, or getting this.Date, comparing it, then possibly performing the write. And just to throw in something interesting here, what if Update were to be called multiple times?

If the example I’ve given makes no sense or has holes in it, I apologise; I can’t think of another way of giving an example, but hopefully you can see the point I’m trying to make here.

  • 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-27T16:47:30+00:00Added an answer on May 27, 2026 at 4:47 pm

    Unless for some reason assignment is an expensive operation (e.g. it always triggers a database write), this isn’t going to make your programme faster.

    The point of putting checks in your setters is usually to enforce data integrity, i.e. to preserve programme invariants, and thus the correctness of your other code, which is rather more important.

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

Sidebar

Related Questions

I'm not the sure title of this question is the best, but hopefully this
Hopefully this explanation will make sense, but what is the best way (if it
I've tried to simplify for the purposes of asking this question. Hopefully, this will
( Late edit: This question will hopefully be obsolete when Java 7 comes, because
2 small parts to this question which hopefully will clear up some ambiguity for
I have been looking over the web but have not come across an answer
Hopefully this will be an easy question! I have two tables, a 'client(s)' table
Hopefully this will not spark a religious war... We have a web based app
hopefully this will be an easy answer for some of you CSS veterans out
So, hopefully this will be my final request for help on this project, as

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.