Re: Boxing and Unboxing ??
- From: "Jesse McGrew" <jmcgrew@xxxxxxxxx>
- Date: 15 Jan 2007 22:07:40 -0800
Peter Olcott wrote:
"Jesse McGrew" <jmcgrew@xxxxxxxxx> wrote in message
news:1168918374.578116.244610@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Why should the programmer have to change his code just to enable an
optimization? Why not just say "your methods will run faster if you
don't modify large value-type parameters"?
This aspect is not a matter of optimization, it is a matter of preventing
programming errors. By using the [const] parameter qualifier it is impossible to
inadvertently change a function parameter that was not intended to be changed.
It's already impossible! Those errors don't exist today: if you pass a
value type into a method, any changes the method makes will only affect
the local copy inside that method; the original value in the caller
won't be changed.
The potential errors are purely a side effect of the *optimization*
you've been proposing, which is to pass "in" value types by reference
even though you don't expect to get a changed value back from the
method (which is the purpose of "ref" and "out" parameters). If you
weren't passing them by reference, there'd be no need for those
parameters to be read-only, because any changes would be local to the
method being called.
Jesse
.
- Follow-Ups:
- Re: Boxing and Unboxing ??
- From: Bruce Wood
- Re: Boxing and Unboxing ??
- References:
- Boxing and Unboxing ??
- From: Peter Olcott
- Re: Boxing and Unboxing ??
- From: Bob Graham
- Re: Boxing and Unboxing ??
- From: Peter Olcott
- Re: Boxing and Unboxing ??
- From: Arne Vajhøj
- Re: Boxing and Unboxing ??
- From: Peter Olcott
- Re: Boxing and Unboxing ??
- From: Barry Kelly
- Re: Boxing and Unboxing ??
- From: Peter Olcott
- Re: Boxing and Unboxing ??
- From: Barry Kelly
- Re: Boxing and Unboxing ??
- From: Peter Olcott
- Re: Boxing and Unboxing ??
- From: Barry Kelly
- Re: Boxing and Unboxing ??
- From: Barry Kelly
- Re: Boxing and Unboxing ??
- From: Peter Olcott
- Re: Boxing and Unboxing ??
- From: Jesse McGrew
- Re: Boxing and Unboxing ??
- From: Peter Olcott
- Re: Boxing and Unboxing ??
- From: Jesse McGrew
- Re: Boxing and Unboxing ??
- From: Peter Olcott
- Re: Boxing and Unboxing ??
- From: Jesse McGrew
- Re: Boxing and Unboxing ??
- From: Peter Olcott
- Re: Boxing and Unboxing ??
- From: Jesse McGrew
- Re: Boxing and Unboxing ??
- From: Peter Olcott
- Boxing and Unboxing ??
- Prev by Date: Re: Boxing and Unboxing ??
- Next by Date: Failed to convert parameter value from a SqlParameter to a DateTime.
- Previous by thread: Re: Boxing and Unboxing ??
- Next by thread: Re: Boxing and Unboxing ??
- Index(es):
Relevant Pages
|