3 ms·
If you are going to argue this, you might just as well start arguing that no programmer is allowed more than a quota of 10 ifs per month. Every conditional bran
by revelation 10y ago
If you are going to argue this, you might just as well start arguing that no programmer is allowed more than a quota of 10 ifs per month. Every conditional branch in your program is "an opportunity for bugs and an opportunity for misconfiguration".
This is the equivalent of hoisting a white flag. Theres tons of code added to Chrome all the time, it doesn't add configuration options but it sure as hell has the very same effect.
- geofft 10y agoAn if is just an inconsistent goto, so, yes. if is often a code smell. For instance, any code like x = some_result() if is_valid(x): do_stuff_with(x) is indisputably an opportunity for bugs. Better would be some construct like "if let" in Swift or Rust, where you can't use x without the condition. For instance, this was the fundamental cause of Apple's "goto fail" vulnerability: the language / API style required that they check each result and run a conditional branch on their own. (The proximate cause was bad language syntax, but the opportunity for bad syntax shouldn't have been there in the first place.)