Re: attack of silly coding standard?
Keith H Duggar <duggar@alum.mit.edu> wrote in news:e7c2f043-d750-49b2-
9f4e-f3815f6b14fc@p8g2000vbs.googlegroups.com:
Let's bring some concreteness to the debate. Give me an example
from your /real world/ code of a function having at least several
interesting lines and multiple returns that you think is "better"
for having multiple returns.
My 2 cents (will be converted to 0.1278 cents soon):
Exception RecoverExceptionInCatch() throw() {
try {
throw;
} catch(const Exception& e) {
return e;
} catch(const std::exception& e) {
return Exception("EX12", e.what());
} catch(const char* what) {
return Exception("EX14", what);
} catch( ... ) {
return Exception("EX16", "Unknown error");
}
}
-- and --
bool IpAddress::IsIpv4MappedIpv6() const {
const unsigned char ipv4_prefix[12] =
{0,0,0,0,0,0,0,0,0,0,255,255};
return af_==AF_INET6 && memcmp(ip_, ipv4_prefix, 12)==0;
}
bool IpAddress::operator==(const IpAddress& b) const {
if (af_==b.af_) {
return memcmp(ip_, b.ip_, 16)==0;
} else if (af_==AF_INET) {
DEBUG_ASSERT(b.af_==AF_INET6);
return b.IsIpv4MappedIpv6() && memcmp(ip_, b.ip_+12, 4)==0;
} else {
DEBUG_ASSERT(b.af_==AF_INET);
DEBUG_ASSERT(af_==AF_INET6);
return IsIpv4MappedIpv6() && memcmp(b.ip_, ip_+12, 4)==0;
}
}