Passing by reference
- From: "David Veeneman" <dcv@xxxxxxxxxx>
- Date: Tue, 31 Oct 2006 07:24:59 -0600
Is passing a method argument by reference inherently dangerous?
I develop in the .NET environment. For a long time, I have avoided what I
consider to be the dangers of passing method arguments by reference, where
the method changes the object argument. The biggest danger, IMHO, is that
you can't tell by looking at the calling object whether the argument was
changed by the method:
MyClass.MyMethod(myObject);
So, at the first step in a method, I have deep-copied any arguments passed
in that the method will modify, then passed the modified object back as a
return value:
myObject = MyClass.MyMethod(myObject);
One of the advantages of this approach is that it forces methods to limit
themselves to doing just one thing.
But now I'm rethinking the approach. Is it too conservative? Is it
necessary? Is it even good practice. Any and all opinions welcome. Thanks
David Veeneman
Foresight Systems
.
- Follow-Ups:
- Re: Passing by reference
- From: AndyW
- Re: Passing by reference
- From: Dmitry A. Kazakov
- Re: Passing by reference
- From: Bruno Desthuilliers
- Re: Passing by reference
- From: Daniel T.
- Re: Passing by reference
- From: H. S. Lahman
- Re: Passing by reference
- Next by Date: Re: "Polytypic" expressions?
- Next by thread: Re: Passing by reference
- Index(es):
Relevant Pages
|