christopher's notes

programming tips: max_attempts, not max_retries

foo(max_retries=3)

How many times would we expect foo to run, at max? Naively, you might say 3. But if you take the argument name literally, it would run 4 times. (Once initially, then 3 retries.)

Alleviate this confusion by naming the argument max_attempts. It's easy to see that foo(max_attempts=3) will never run more than exactly 3 times.

Thinking of a number of "attempts", rather than a number of "retries", is preferred in every case where these concepts applies.


If you post a reply on another blog or social media, or just want to chat, email me! christopher@cg505.com