...

>
> I think this is a hint that this is the wrong approach. The edge-cases
> begin showing the cracks in the abstraction and end up making the code more
> complex. Consider your example instead of:
>
> var finalResult Foo
> for loop := retry.Loop(spec); loop.Next(); {
>     result, err := SomeFunc(blah)
>     if err != nil || resultNotGoodEnough(result) {
>         continue
>     }
>
>         finalResult = result
>     break
> }
>
> There are no special errors, no mixing of concerns, just a boring
> imperative loop. It works like any other loop written in Go.
>

The one things I'll specifically note about your "simple" example is that
it doesn't actually handle errors. The fact that the "quick way to write
it" is actually wrong is the specific argument of this thread.
In your loop you have a way to generate a FinalResult, but no handling of
the actual "I couldn't get a result". The way above that you can tell the
loop failed would be to check if FinalResult doesn't have a valid value.

This, at least, is the point I think Tim is bringing up of "hard to get
wrong".

John
=:->
-- 
Juju-dev mailing list
Juju-dev@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/juju-dev

Reply via email to