Skip to main content
Improved sentence structure, flow, clarity, and grammar
Source Link
Mike Partridge
  • 6.7k
  • 1
  • 26
  • 40

Both are 'safe/sane/correct' if the caller checks before use. The issue is what happens if the caller doesn't check. Which is better, some flavour of null error or using an invalid value?

There is no single correct answer. It depends on what you are worried about.

If crashes are really bad but the answer isn't critical or has an exceptedaccepted default value, then perhaps using a boolean as a flag is better. If using the wrong answer is a greaterworse issue than crashing, then using null is better.

For the majority of the 'typical' cases, fast failure and forcing the callers to check is the fastest way to sane code. Hence, and hence I think null should be the default choice but. I wouldn't put too much faith in the "X is the root of all evil" evangelists. They though; they normally haven't anticipated all the use cases.

Both are 'safe/sane/correct' if the caller checks before use. The issue is what happens if the caller doesn't check. Which is better, some flavour of null error or using an invalid value?

There is no single correct answer. It depends on what you are worried about.

If crashes are really bad but the answer isn't critical or has an excepted default value, then perhaps using a boolean as a flag is better. If using the wrong answer is a greater issue than crashing, then using null is better.

For the majority of the 'typical' cases, fast failure and forcing the callers to check is the fastest way to sane code. Hence, I think null should be the default choice but I wouldn't put too much faith in the "X is the root of all evil" evangelists. They normally haven't anticipated all the use cases.

Both are 'safe/sane/correct' if the caller checks before use. The issue is what happens if the caller doesn't check. Which is better, some flavour of null error or using an invalid value?

There is no single correct answer. It depends on what you are worried about.

If crashes are really bad but the answer isn't critical or has an accepted default value, then perhaps using a boolean as a flag is better. If using the wrong answer is a worse issue than crashing, then using null is better.

For the majority of the 'typical' cases, fast failure and forcing the callers to check is the fastest way to sane code, and hence I think null should be the default choice. I wouldn't put too much faith in the "X is the root of all evil" evangelists though; they normally haven't anticipated all the use cases.

Improved sentence structure, flow, clarity, and grammar
Source Link

First, bothBoth are 'safe/sane/correct' if the caller checks before use. ThisThe issue is what happens if they don'tthe caller doesn't check. WhichWhich is better: "some, some flavour of null error"error or "usingusing an invalid value".value?

But there reallyThere is no 1single correct answer that's right here. It really depends on what you are worried about.

If crashes are really bad but the answer isn't critical /or has an excepted default value, then maybeperhaps using a boolean as a flag is better. If using the wrong answer is a real problem butgreater issue than crashing is not so bad, then using null is better.

For the majority of the 'typical' cases, fast failure and forcing the callers to check is the fastest way to sane code and hence. Hence, I think null should be the default choice, but I wouldn't put too much faith in the "X is the root of all evil" evangelists. They normally haven't anticipated all the use cases.

First, both are 'safe/sane/correct' if the caller checks before use. This issue is what happens if they don't. Which is better: "some flavour of null error" or "using an invalid value".

But there really is no 1 answer that's right here. It really depends on what you are worried about.

If crashes are really bad but the answer isn't critical / has an excepted default value, then maybe a boolean as a flag is better. If using the wrong answer is a real problem but crashing is not so bad, then null is better.

For the majority of the 'typical' cases, fast failure and forcing the callers to check is the fastest way to sane code and hence I think null should be the default choice, but I wouldn't put too much faith in the "X is the root of all evil" evangelists. They normally haven't anticipated all the use cases.

Both are 'safe/sane/correct' if the caller checks before use. The issue is what happens if the caller doesn't check. Which is better, some flavour of null error or using an invalid value?

There is no single correct answer. It depends on what you are worried about.

If crashes are really bad but the answer isn't critical or has an excepted default value, then perhaps using a boolean as a flag is better. If using the wrong answer is a greater issue than crashing, then using null is better.

For the majority of the 'typical' cases, fast failure and forcing the callers to check is the fastest way to sane code. Hence, I think null should be the default choice but I wouldn't put too much faith in the "X is the root of all evil" evangelists. They normally haven't anticipated all the use cases.

Source Link
ANone
  • 311
  • 2
  • 5

First, both are 'safe/sane/correct' if the caller checks before use. This issue is what happens if they don't. Which is better: "some flavour of null error" or "using an invalid value".

But there really is no 1 answer that's right here. It really depends on what you are worried about.

If crashes are really bad but the answer isn't critical / has an excepted default value, then maybe a boolean as a flag is better. If using the wrong answer is a real problem but crashing is not so bad, then null is better.

For the majority of the 'typical' cases, fast failure and forcing the callers to check is the fastest way to sane code and hence I think null should be the default choice, but I wouldn't put too much faith in the "X is the root of all evil" evangelists. They normally haven't anticipated all the use cases.