A
Alf P. Steinbach /Usenet
Well, I think, it's not just me.
Since it's in the FAQ, and since we have discussed this for years, it must be
nearly all of us: we're idiots.
I'm thinking of the argument for `unsigned` type, that you can do
void foo( unsigned n )
{
assert( n < maxN );
// blah
}
which is reportedly both more concise and more efficient than
void foo( int n )
{
assert( 0 <= n && n < maxN );
// blah
}
But, the second one can always be written as
void foo( int n )
{
assert( unsigned( n ) < maxN );
// blah
}
which is perhaps not quite as concise, but is exactly as efficient (doing
exactly the same), and moreover sort of forces you to think about what the first
function's code really does -- which is the same as this.
In short, the efficiency argument is bogus.
Why did we not recognize that earlier (like, why is the bogus argument still in
the FAQ with no counter-argument), or, perhaps, why have I not recognized this
being mentioned in the postings about signed/unsigned?
Cheers,
- Alf (wondering)
Since it's in the FAQ, and since we have discussed this for years, it must be
nearly all of us: we're idiots.
I'm thinking of the argument for `unsigned` type, that you can do
void foo( unsigned n )
{
assert( n < maxN );
// blah
}
which is reportedly both more concise and more efficient than
void foo( int n )
{
assert( 0 <= n && n < maxN );
// blah
}
But, the second one can always be written as
void foo( int n )
{
assert( unsigned( n ) < maxN );
// blah
}
which is perhaps not quite as concise, but is exactly as efficient (doing
exactly the same), and moreover sort of forces you to think about what the first
function's code really does -- which is the same as this.
In short, the efficiency argument is bogus.
Why did we not recognize that earlier (like, why is the bogus argument still in
the FAQ with no counter-argument), or, perhaps, why have I not recognized this
being mentioned in the postings about signed/unsigned?
Cheers,
- Alf (wondering)