Always make error conditions explicit and visible rather than hiding them through silent failures, default return values, or unchecked operations. This includes validating results before use, using assertions for invalid states, and logging unexpected conditions.
Always make error conditions explicit and visible rather than hiding them through silent failures, default return values, or unchecked operations. This includes validating results before use, using assertions for invalid states, and logging unexpected conditions.
Key practices:
find()
before dereferencing to prevent crashesassert(scrollOffset.isFinite && itemExtent.isFinite)
rather than return 0
FML_LOG(ERROR) << "Unexpected condition"
Example of making errors explicit:
// Bad: Hides error by returning default value
if (itemExtent > 0.0) {
final double actual = scrollOffset / itemExtent;
if (!actual.isFinite) {
return 0; // Silently hides the error
}
}
// Good: Makes error explicit with assertion
assert(scrollOffset.isFinite && itemExtent.isFinite,
'scrollOffset and itemExtent must be finite');
if (itemExtent > 0.0) {
final double actual = scrollOffset / itemExtent;
}
This approach helps developers identify issues during development and provides better debugging information when problems occur.
Enter the URL of a public GitHub repository