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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:35:10+00:00 2026-06-10T16:35:10+00:00

Suppose I’m writing a library that stores a sequence of doubles to a file

  • 0

Suppose I’m writing a library that stores a sequence of doubles to a file in a certain format. The format requires that the doubles are monotonically increasing.

Now, some users won’t read the manual carefully or write buggy frontends that do something like

store(3.0)
store(3.1)
store(0.3)
store(7.8)

What the library could do is

  1. Error out when store(0.3) is called.
  2. Try to correct the error by making a good guess, e.g., actually store(3.3).
  3. Correct the error and write a message to stderr.
  4. […]

The advantage of (1) would be that the user cannot miss it. If the code ran for a long time (which is the regular case in my context), though, the user wouldn’t be too happy with the program aborting.
(2) would do away with this, but possibly encourage misusing the library.

Are there policies in any language that advocate one approach over the other?

  • 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-10T16:35:12+00:00Added an answer on June 10, 2026 at 4:35 pm

    Irrespective of the language used, my general advice is to always fail quickly. This localises errors to the actual source of the problem – i.e., throw an error or exception and bail out (perhaps permitting the programmer to catch the exception, depending on the language). Similarly, some languages with checked exceptions might force the programmer to add a check for malformed input.

    The reason for this is simple – the further away from the actual source of the problem that the errors manifest, the harder the program is to debug. Let’s say the programmer didn’t mean 3.3 (as opposed to 0.3) and you corrected it for him – well, the program will keep running, but at some point the value 3.3 will manifest and potentially cause other problems. It might also be that the source of these values was some kind of sorting algorithm with bugs – the fact that your library doesn’t fail in this case will simply make it harder to debug the sorting algorithm and identify the real cause of the failure.

    It also plays hell with any attempts to unit test the code – code that should fail doesn’t necessarily fail in the right place. This just makes the code magical and much more difficult to manage as part of a development process.

    There is an alternative to simply failing and forcing the user or client program to start the interaction all over again – you could do things in a transactional manner such that the library is left in a consistent state after the failure, permitting the user to proceed from the last valid input (for example). This should be implemented with proper rollback semantics though, to ensure data consistency.

    So in summary: fail fast, and fail early.

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

Sidebar

Related Questions

Suppose i have an XML file, that i use as local database, like this):
Suppose I have a pure virtual method in the base interface that returns to
Suppose I have a static method of my class that returns an object of
Suppose I have a class Baz that inherits from classes Foo and Bar ,
Suppose I have a process that is updating a record and encounters a record
Suppose I have a data frame, df, that looks like: f t1 t2 t3
Suppose there is a MySQL user alice that is currently connected to the database.
Suppose I have a class MyClass to which I want to add certain 'observer'
Suppose you have an array value => timestamp. The values are increasing with the
Suppose that I have a registration screen, and when the user clicks the Register

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.