|
|
|
|
|
by Mouse47
3155 days ago
|
|
>Rusts solution is a more general solution to the "general resource problem" It's true. Ever since I got familiar with the ownership concept, I've taken to writing C# IDisposables with disposable member variables like this: public MyObject(){
this.myResource = new DisposableResource();
this.ownsMyResource = true;
}
public MyObject(DisposableResource resourceToUseThatIDontOwn){
this.myResource = resourceToUseThatIDontOwn;
this.ownsMyResource = false;
}
public void Dispose(){
//not pictured: .NET's boilerplate dispose code
if(ownsMyResource) myResource.Dispose();
}
For the client I'm contracting with right now, mismanagement of disposable resources is the #1 issue in the codebase. 100k lines of code, and it's never clear who should be disposing connections. There are some objects with multiple constructors (like above) that have 'conditional' ownership. In Rust, it's impossible to have this problem, period...although the above C# construct simulates it, lol. |
|