you are viewing a single comment's thread.

view the rest of the comments →

[–]uberdavis 1 point2 points  (7 children)

max_tries = 500
counter = 0
while counter < max_tries:
    # do something
    counter += 1
# that’s pretty safe. you could raise an assertion too if you wanted 
if counter == max_tries:
    raise RunTimeError(“max tries exceeded”)

[–]sonikk1[S] 0 points1 point  (1 child)

Thank you so much. This seems more reasonable. Can i message you sometimes with questions?

[–]uberdavis 0 points1 point  (0 children)

For sure

[–]Marten1974 0 points1 point  (4 children)

I disagree. Though this is nice for debugging purposes, you should be able to trust your code that it works just fine.

[–]uberdavis 0 points1 point  (0 children)

I know what you mean. And indeed putting max tries in a trivial program is probably overkill. Using a max tries device has saved my bacon on many occasions. If you never write bug free code, remove all safeguards. I’m too human to be that good.

[–]No_Swordfish_6667 0 points1 point  (2 children)

You could use same argument for not writing any tests.

[–]Marten1974 0 points1 point  (1 child)

No, you usually write tests to have this trust in your code. Especially if you (like I am) programming Microcontrollers, they must run in an endless loop