HeadlinesBriefing favicon HeadlinesBriefing.com

The Law of Loudness: Fixing Silent Code Failures

DEV Community •
×

Debugging can be a nightmare, especially when a stack trace points to a null error that's five layers deep. Junior engineers often catch errors and return null or false to keep the app running, but this 'Zombie Mode' creates hidden bugs that crash the app later. This is known as 'Passing the Buck,' where the error is outsourced to the calling function.

The Law of Loudness offers a better approach: if a function can't fulfill its promise, it should throw an error immediately. This practice, 'Fail Fast,' ensures that data integrity is protected. By stopping execution when an error is detected, developers can quickly identify and fix the root cause, preventing 'Zombie' data from causing further issues.

Senior engineers embrace this method because it leads to faster debugging. When an app crashes, the stack trace points directly to the line that failed, saving hours of tracing null values. It also builds trust, as developers can rely on functions to either return valid data or throw an error, eliminating the need for constant null checks.

This approach is detailed in 'The Professional Junior: Writing Code that Matters,' a handbook that provides tactical field guides to unwritten engineering rules. By adopting the Law of Loudness, developers can write code that not only pleases the compiler but also ensures robust and maintainable applications.