On Using 'using'
I read Richard Hale Shaw's recent post and while I don't agree with the article he refers to I don't agree with his suggestion to avoid using using.
As Richard states when the using includes the declaration it is a useful construct and significantly you DO get the compiler generating an error if the object is used outside the scope.
In the case where the object is declared before the using I don't think that it is any easier to remember to not use an object after calling Dispose than it is to remember to not to call it outside the scope of the using. Also support from the compiler is equally lacking in both cases.
It seems to me that just because it can be used to write invalid code is insufficient reason to ban a statement that make code clearer and with clearer scoping of IDisposable objects.
As Richard states when the using includes the declaration it is a useful construct and significantly you DO get the compiler generating an error if the object is used outside the scope.
In the case where the object is declared before the using I don't think that it is any easier to remember to not use an object after calling Dispose than it is to remember to not to call it outside the scope of the using. Also support from the compiler is equally lacking in both cases.
It seems to me that just because it can be used to write invalid code is insufficient reason to ban a statement that make code clearer and with clearer scoping of IDisposable objects.
0 Comments:
Post a Comment
<< Home