Last Updated: 2021-05-16
I was caught off guard working with a third-party API that normally returned a
number, but sometimes returned
_, _, score = FuzzyMatch.new(possibilities).find_with_score(name) if score < 0.5 do_something end
nil < 0.5 doesn't work, this blew up and I had to rewrite the code as:
if (! score) || score < 0.5 do_something end
Consult the docs whenever using a library function and enumerate the possible
return types, then ensure your code can handle these. Be especially careful
nil and possible exceptions.
Be especially careful about assuming numerical functions always return numbers.
Just because you might expect
0 in error conditions doesn't mean they will