Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you're validating parameters that originate from your program (messages, user input, events, etc), ASSERT and ASSERT often. If you're handling parameters that originate from somewhere else (response from server, request from client, loading a file, etc) - you model every possible version of the data and handle all valid and invalid states.

Why? When you or your coworkers are adding code, the stricter you make your code, the fewer permutations you have to test, the fewer bugs you will have. But, you can't enforce an invariant on a data source that you don't control.



Yes of course the key here is to understand the difference between BUGS and logical (error) conditions.

If I write an image processing application failing to process an image .png when:

  - user doesn't permission to the file
  - file is actually not a file
  - file is actually not an image
  - file contains a corrupt image
  etc.
are all logical conditions that the application needs to be able to handle.

The difference is that from the software correctness perspective none of these are errors. In the software they're just logical conditions and they are only errors to the USER.

BUGS are errors in the software.

(People often get confused because the term "error" without more context doesn't adequately distinguish between an error condition experienced by the user when using the software and errors in the program itself.)


> But, you can't enforce an invariant on a data source that you don't control.

This is obvious.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: