Hacker News new | ask | show | jobs
by zeugma 5528 days ago
Maybe that what's the author wanted to pointed out: if you have garbage collection (at least the way it's implemented in C#/Java) you have to give away scope lifetime of object. This is annoying because you want determinism for some kind of resources (file, lock, ...) and then you have to manually clean them, which is what you wanted to avoid in the first place with garbage collection.

In C++, if you declare the object on the stack, the destructor will be called when the scope is closed. Which is very handy for e.g. lock.

The thing is, garbage collection could be use together with scope lifetime (aka RAII) just let the programmer choose which is best/more convenient for him given his resources.

1 comments

I agree. I think the author does understand the difference between scope, object lifetime and manual/GC object management.

The article is clearly written for pogrammers coming from C++ to C#, which there are a lot of, including myself. I like both C++ and C# a lot but have to admit that managing object lifetime in C# is one of the things I really dislike. There's the suggestion that RAII is reasonable in C# but for me always ends up being a headache.

As others have noted, this could have been written against many VM/GC based languages and not just C#. That said, it's the FUNDAMENTAL difference between the 2 types of languages and thus the comparison is moot. It's like getting into a limo and saying it doesn't feel like a motorcycle. I'm not convinced the author understands this...