I have never said it had bad readability. I said your "nice thing" serving no
purpose was an obfuscation pretending to be simple while not being so. It would
be a bad idea (now I am saying "bad") to use it as an example to do anything useful.
Your original "transaction" code was rather readable although had an unnecessary
"else" clause made it more complex than necessary.
While fixing the bug your worsened the readability from ok to rather poor (again
I am not calling it "bad").
A better readable code for "transaction", after the bug fix and preserving your
preferences for indentation and braces but not new lines and using magic numbers
vs symbolic constants could be, for example:
enum TsxStatusCategory: int {
TSX_ABORTED_DONT_RETRY = -1,
TSX_ABORTED_CAN_RETRY = 0,
TSX_COMMITTED = 1
};
template<typename L>
inline
TsxStatusCategory
doTsxTransaction( L &lambda ) // function name should be a verb [clause]
{
unsigned code = _xbegin(); // unsinged is not unsigned BTW
if( code == _XBEGIN_STARTED )
{
lambda();
_xend();
return TSX_COMMITTED;
} // `else' served no purpose here other than obfuscation
if (code & _XABORT_EXPLICIT)
return TSX_ABORTED_DONT_RETRY;
if (code & _XABORT_RETRY)
return TSX_ABORTED_CAN_RETRY;
return TSX_ABORTED_DONT_RETRY;
}
> Yours has a bad readabiliy.
Yes, it does and as said earlier it is its point.