Reputation
8,301
Top tag
Next privilege 10,000 Rep.
Access moderator tools
Badges
12 67 129
Impact
~507k people reached

May
20
reviewed Leave Open Can we guarantee a program will never go wrong?
May
20
reviewed Leave Closed Card deck and sparse matrix interview questions
May
20
reviewed Reopen Is lack of whitespace a sign of a cargo cult programmer?
May
20
reviewed Reopen How to adhere to the open-closed principle in practice
May
20
reviewed Reopen How can I group commits in a version control system such as git
May
20
awarded  Custodian
May
20
reviewed No Action Needed Why don't we completely de-couple frontend JS frameworks and backend APIs?
May
20
reviewed Approve Constant Interface antipattern - PHP
May
12
revised What are your thoughts about the Actor Model?
added 286 characters in body
Jan
26
reviewed Approve Mapping values over a curve
Jan
24
awarded  Good Question
Dec
11
awarded  Favorite Question
Nov
23
awarded  Informed
Nov
21
awarded  Nice Question
Oct
30
comment Why can't Java/C# implement RAII?
I totally understand now.
Oct
30
comment Why can't Java/C# implement RAII?
Yes, exactly what I said. I understand you now. There are problems for other situations, sure. Probably the compiler would need to forbid some constructs. Compilers do this every time. If this is good or bad is matter of discussion which doesn't fit here. I'm not sure if this new example is unsolvable (I have no enough information to discuss this). So you could say write using is easier and I can agree, but the point of this question it is if is is feasible. If you ask me if I want get rid of using on C#, I say a big NO. I'm talking by language design pov.
Oct
30
comment Why can't Java/C# implement RAII?
@RobertHarvey IMHO your answer is not wrong either, just it was not fit in this question. For me it's about language design. I agree with you that C# or even Java team shouldn't waste resources in that feature. I see the usefulness of this feature and I see the cost for the language and for the implementation.
Oct
30
comment Why can't Java/C# implement RAII?
My understanding, changing you example to just a return, is that the compiler would insert a try just before the resource acquisition (line 3 at your example) and the finally-dispose block just before the end of scope (line 6). No problem here, agree? Back to your example. The compiler see a transfer, it couldn't insert try-finally here but the caller will receive a (pointer to) File object and assuming the caller is not transferring this object again, compiler will insert try-finally pattern there. In other words every IDisposable object not transferred need to apply try-finally pattern.
Oct
30
comment Why can't Java/C# implement RAII?
I fail to see what you said now (i'm not saying you are wrong). The object has a resource, not the reference.
Oct
30
comment Why can't Java/C# implement RAII?
@mike20 but if you need to be aware that a type is a resource and you are forced to write something to tell to compiler to do a proper work you're explicit. I disagree with Robert in almost everything he says in this question but he is right saying this answer just get rid of braces and a nested scope and when he's saying the using is not a sugar.