/10@yegor256 1
Need It Robust?
Make It Fragile!
Yegor Bugayenko
/10@yegor256 2
less bugs
/10@yegor256 3
Fail Safe
vs.
Fail Fast
/10@yegor256 4
Fix
Report
Use
Deploy
/10@yegor256 5
int len(File f) {
if (f == null) {
return -1;
}
}
int len(File f) {
if (f == null) {
throw new Exception(
“file can’t be NULL”
);
}
}
/10@yegor256 6
try {
stream.read();
} catch (IOException ex) {
ex.printStackTrace();
}
try {
stream.read();
} catch (IOException ex) {
throw new RuntimeException(
“failed to read stream”,
ex
);
}
exception swallowing
/10@yegor256 7
void push(int x) {
if (pos < array.length) {
array[pos++] = x;
}
}
void push(int x) {
if (pos >= array.length) {
throw new Exception(
“array is full”
);
}
array[pos++] = x;
}
/10@yegor256 8
@Override
void save() {
// not implemented yet
}
@Override
void save() {
throw new Exception(
“not implemented yet”
);
}
/10@yegor256 9
file.delete();
if (!file.delete()) {
throw new Exception(
“failed to delete file”
);
}
/10@yegor256 10
User find(int id) {
if (/* not found */) {
return null;
}
// continue...
}
User find(int id) {
if (/* not found */) {
throw new Exception(
“user not found”
);
}
// continue...
}
/10@yegor256 11
Fix
Report
Use
Deploy
/10@yegor256 12
www.yegor256.com

Need It Robust? Make It Fragile!