Questions tagged [fail-fast-fail-early]
8 questions
46
votes
5 answers
What does the expression "Fail Early" mean, and when would you want to do so?
What does the expression "Fail Early" mean, and under what circumstances is this approach most useful, and when would you avoid the approach?

Andrew Grimm
- 78,473
- 57
- 200
- 338
14
votes
1 answer
How to safely exit early from a bash script?
I know there are several SO questions on exit vs. return in bash scripts (e.g. here).
On this topic, but different from existing questions, I believe, I'd like to know if there is a "best practice" for how to safely implement "early return" from a…

StoneThrow
- 5,314
- 4
- 44
- 86
4
votes
2 answers
Data validation: fail fast, fail early vs. complete validation
Regarding data validation, I've heard that the options are to "fail fast, fail early" or "complete validation". The first approach fails on the very first validation error, whereas the second one builds up a list of failures and presents it.
I'm…

Vivin Paliath
- 94,126
- 40
- 223
- 295
2
votes
1 answer
Is there a consistent way to force errors on incorrect list or vector indexing
My expectation from other programming languages is that (1:4)[3:5] and list(asdf = 4, qwerty = 5)$asdg should both raise exceptions. Instead, the first silently returns c(3, 4, NA), and the second silently returns NULL (as does or list(asdf = 4,…

Chris Henry
- 55
- 5
2
votes
2 answers
C: how can I fail to compile when -Wswitch is off?
If I want my switch(an_enum) statement to be reported when it misses an enum case, I can turn on the -Wswitch compiler flag (on gcc).
enum E { e1, e2, e3 };
...
switch(e) {
case e1: ...
case e2: ...
// NO default: checked by -Wswitch and…

xtofl
- 40,723
- 12
- 105
- 192
0
votes
0 answers
Check pointer passed to function for validity, also non NULL case
Is there a way to check a pointer's validity besides the common assert(NULL != ptr)?
I tried the following to intentionally provoke an "access error" so i will be alerted early, not lately when the pointer is accessed in some nested code:
#if…

Wör Du Schnaffzig
- 988
- 5
- 23
0
votes
1 answer
Early return from a function which has a return type of [String] in Swift 3
I have a function which returns an Array of String if some conditions are met. But I want to have the early return functionality in my function. Something like this:
func fetchPerson() -> [String] {
guard let appDelegate =…

nayem
- 7,285
- 1
- 33
- 51
0
votes
1 answer
Fail early vs. robust methods
I'm constantly (since years) wondering the most senseful way to implement the following (it's kind of paradoxic for me):
Imagine a function:
DoSomethingWith(value)
{
if (value == null) { // Robust: Check parameter(s) first
throw new…

user5358508
- 13
- 2