Timeline for Migration from a complex C++ application to C# a -- good idea?
Current License: CC BY-SA 3.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 26, 2013 at 15:17 | audit | First posts | |||
| Jul 26, 2013 at 15:22 | |||||
| Jul 16, 2013 at 17:57 | comment | added | mike30 | @ikh. using-blocks use scoping like RAII but there is more to RAII than scoping. Real RAII is implicit. Using-blocks are explicit. In c# you must explicitly write a block, which is a syntax alternative of explicitly writing try/finally-dipose(). Real RAII would not require to you write anything, it just happens. You could say C# has an explicit version of RAII, but it is not possible for C# (and many other languages) to support implicit RAII. | |
| Jul 15, 2013 at 16:29 | comment | added | djechlin | @everyone removed that line, that clearly wasn't the point. | |
| Jul 15, 2013 at 16:28 | history | edited | djechlin | CC BY-SA 3.0 | deleted 78 characters in body |
| Jul 15, 2013 at 16:25 | comment | added | ikh | @gbjbaanb using was exactly what I meant. It works, and it's perfectly correct to view it as RAII implementation, even if it's a bit more verbose than C++. In any case, the point is that it's a mistake to say that RAII is unique to C++, esp when comparing it to C#. | |
| Jul 15, 2013 at 14:24 | comment | added | gbjbaanb | @ikh you don't understand what RAII is. Its not the ability to create a 'cleanup' method (any old fool can do that). The power in RAII is that the cleanup is called automatically for you. The closest thing to RAII in C# is the using statement, but then as you have to litter your code with that, and its not always exception safe, its not really much of a substitute. | |
| Jul 15, 2013 at 12:32 | comment | added | JNL | Really appreciate your comments, it definitely gives me a very good idea of the same. | |
| Jul 15, 2013 at 6:30 | comment | added | Donal Fellows | @Robert Yes, but the cases where RAII is really valuable are those which the syntactic pattern associated with IDisposable addresses. The rest is about the difference between different styles of memory management (direct vs. GC). | |
| Jul 15, 2013 at 4:21 | comment | added | Robert Harvey | @ikh: IDisposable is mostly for unmanaged resources; for managed objects, it does not guarantee that those objects get garbage collected immediately, only that they are marked for garbage collection when the class instance is disposed, which happens anyway when the object goes out of scope. The only way to simulate RIAA with a managed object is to force a garbage collection to occur, which is not really the same thing. | |
| Jul 15, 2013 at 3:00 | comment | added | ikh | RAII is quite doable in C# as well -- see IDisposable. | |
| Jul 15, 2013 at 2:50 | history | answered | djechlin | CC BY-SA 3.0 |