3 ms·
An 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_
by geofft 10y ago
An 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.)