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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:11:03+00:00 2026-05-13T15:11:03+00:00

You’re designing a method. It serves a purpose, that’s why you’re designing it in

  • 0

You’re designing a method. It serves a purpose, that’s why you’re designing it in the first place. A caller uses your method and the method fails, but, lo and behold, the ultimate purpose that exuse the existence of the method is nevertheless achieved — thanks to external circumstances that are out of your control or some kind of magic, you choose. Would you report this situation to the caller as a failure or as a success?

Let’s pick a trivial example. You’re writing a DeleteFile function. It takes a file path and deletes the file. Someone calls this function, providing a path. The function looks the file up, but it does not exist. It’s not a permissions issue or something, the file is genuinely missing. Maybe another process deleted it a microsecond ago, and maybe it never existed at all. The function failed to perform its task, so it must report a failure… but the only reason why a user whould call this function is to make sure a file does not exist, and, voila, it does not, so it is a success.

I anticipate answers like “just be more verbose in your return values”, and I’m happy to return a verbose result as a complimentary information, but what (and why) would you return as a primary success flag of the function, success or failure? Would it be FALSE with additional flag of BUT_DOES_NOT_EXIST_ANYWAY, or would it be TRUE with a BUT_THANK_SOMEONE_ELSE flag?

I’m asking about situation in general, including when the method has no parameters or it is not possible to call it in a wrong way for some other reason.

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

    When new programmers are learning how to write functions, the terms preconditions and postconditions are often introduced. Preconditions are assumptions that must be met for your method to work properly. Postconditions are guarantees that your method makes about the state of the system after execution.

    I think that a reasonable precondition to expect when calling a deleteFile method is that the file currently exists. If the preconditions are not met, the method should fail, even if the postconditions have been achieved in an accidental, roundabout way.

    Now, if your method were called deleteFileIfExists, that’s a different story. You haven’t imposed such strict preconditions on the method.

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

Sidebar

Related Questions

No related questions found

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.