Junior
Why are null-related errors called 'million-dollar errors'?
sobes.tech AI
Answer from AI
Errors related to null are called "billion-dollar mistakes" (not million), because they have caused huge financial losses and problems in software for decades. The concept of null (originally NIL) in the ALGOL language was created by Tony Hoare, who later admitted that it was his "billion-dollar mistake" because he could not foresee the security issues they would cause in the future.
Problems arise due to:
- Uncertainty:
nullcan mean different things in different contexts (absence of value, error, unhandled case), which makes the code harder to understand. - Security issues: Attempting to perform an operation on a
nullvalue (such as calling a method or accessing a property) results in an exception (usuallyNullPointerException), which can cause application failures. - Need for checks: Developers constantly need to add checks for
nullbefore using variables, increasing code volume and complexity.
In Flutter and Dart, with the introduction of null safety, this problem has become significantly less relevant, as types by default cannot be null without explicit indication (String?, int?, etc.), allowing the compiler to detect potential errors before runtime.
// Before null safety
String name = null; // This was possible
// With null safety
// String name = null; // Compilation error
String? nullableName = null; // Allowed, but explicitly indicated