5 ms·
Is this meant as a joke or a serious argument? I personally find the original code just as if not more readable than the static lookup table and I don't need t
by blensor 1y ago
Is this meant as a joke or a serious argument?
I personally find the original code just as if not more readable than the static lookup table and I don't need to count out the elements if I want to know how often it will retry.
But more importantly, changing the max retries is trivial in the original code and tedious in the static lookup table, especially for bigger changes.
Also, this is something you most likely want to make configurable to adapt to certain scenarios which is not possible with a static table
There are more reasons against it but those are the the main ones that jump at me right away
- masklinn 1y agoNot only that, but now that Go has iterators if you need this in several locations the logic of the original can easily be encapsulated in an iterator with a few relevant tunable knobs, and then you just write something like: for range ExponentialBackoff(ctx) { err := request(ctx) if err == nil { return nil } } and if one of the callsites needs to configure the backoff then you've got something like: for range ExponentialBackoff(ctx, MaxAttempts(20), BaseDelay(5)) { err := request(ctx) if err == nil { return nil } }
- TurboHaskal 1y agoI am afraid it is a serious argument. If you ever feel the need to write code like that lookup table, you are working on the wrong place and you have a hiring problem.