On Mon, Jun 24, 2013 at 8:49 AM, Larry Evans wrote:
Could you explain exactly how Expected is better?
either get_ipaddr(); // X
either get_ipaddr(); // Y
expected get_ipaddr(); // Z
'either' _means_ the two result are equally valid. Or maybe doesn't imply
any relationship. 'expected' _means_ one value is expected (success) the
other is failure.
So the _meaning_ - the semantics - are different. 'expected' has a more
specific meaning, and should be chosen when that specific meaning is what
you are trying to convey. So Z is better than Y above - the intent is more
clear, more specific.
So *one* of the uses of 'either' is better handled with 'expected'.
That leaves the other use. how is 'either' better than 'variant':
variant get_ipaddr();
either get_ipaddr();
I suspect 'either' has benefits here, but is it enough?
And of course, what happens when someone adds another option:
variant get_ipaddr();
(of course what will really happen is:
variant get_ipaddr();
instead of
expected, error> get_ipaddr();
and we've lost some meaning. Doesn't mean we shouldn't try!)
Also, why is 'either' only 2 types? In English, it isn't: "I am either
going on Monday, Tuesday, or Wednesday".
How common is 2 choices over 3 choices (outside of value + error)?
Tony