6 ms·
> C++ just doesn't attract self-publicists the way Ruby seems to. That's a cheap shot ... Linus Tolvards is definitely not the Ruby-type. And his arguments ar
by bad_user 16y ago
> C++ just doesn't attract self-publicists the way Ruby seems to.
That's a cheap shot ... Linus Tolvards is definitely not the Ruby-type.
And his arguments are sound ... for system programming, C is a much better language because it's simpler, lacks magic, making the pieces of code easier to understand without the bigger context, and it's more portable.
And for application-level programming, why would you chose a language without a garbage-collector?
- tbrownaw 16y ago> And for application-level programming, why would you chose a language without a garbage-collector? Because your code uses some finite resources other than memory, and you don't want the ability to forget to release said resources when you're done with them and they go out of scope.
- eru 16y agoWhy should memory management related to managing other resources. Anyway, you might be interested in The Haskell Disciplined Disciple Compiler (http://www.haskell.org/haskellwiki/DDC http://www.haskell.org/haskellwiki/DDC) which lets you statically encode resource management rules. (And of course spots garbage collection for memory.)
- tbrownaw 16y agoYour objects contain/use various resources, such as memory, file descriptors, mutexes, etc. The way to reclaim any of these is to destroy the object, which lets you reclaim all of them. So memory management is very much tied to other resource management, since they both involve the same thing (deciding when to destroy objects you no longer need). Unfortunately not all resources can be collected equally lazily, so memory-centric GC schemes that ignore the requirements of other resources tend to get in the way (and make you do using(){...} or try/finally to make sure your files are closed, instead of allowing for RAII).
- eru 16y ago> The way to reclaim any of these is to destroy the object, which lets you reclaim all of them. I asked why one should mix management of resources, and you answer that one should mix management of resources. But I still don't know why?
- tbrownaw 16y agoIt's more that how the hell do you unmix them (any why would you bother, anyway)?
- eru 16y agoHow to unmix: Just e.g. close your files explicitly, but let the memory of the data structures that represent your files be garbage collected normally. For patterns of usage similar to RAII, Common Lisp uses unwind-protect. I already mentioned Disciplined Disciple Compiler that extends Haskell to give static guarantees for following certain rules for resource management. Why would you bother: RAII only covers some cases for resource management, and most garbage collectors can take an arbitrary long time to collect an object that's no longer reachable. Which is fine for memory, because memory is fungible, but the attached resources, say mutexen, are not necessarily fungible.
- gaius 16y agoPerhaps you need to run deterministically without a stop-the-world garbage collector? A) the world is bigger than simple web applications and B) some of us have been doing this for a long time.
- bad_user 16y agoI wasn't talking about web applications, and modern garbage collectors are not stop-the-world. Not to mention ... stop-the-world garbage collectors have a good reason for doing what they do. They are defragmenting the memory. You get that for free, when in C++ you would have to deal with hell if your app is doing lots of allocations ... see the shit the Firefox devs had to go through to alleviate the problems of heap fragmentation, and its still a problem.
- heresy 16y agoAh, but what, you're using both managed code (C#) and unmanaged code (C++) in the same address space, doing memory intensive work using third party proprietary C++ code that does lots of small allocations? In 32-bit land, it's welcome to OutOfMemoryException because managed code can't allocate a big enough chunk when returning to C#. No free lunch :) Either recycle processes often or reserve big enough contiguous chunks in managed code before calling out to the bad C++ code, no amount of good citizenship in managed code will stop the poorly written native code from fragmenting the hell out of your address space.
- gaius 16y agoUnfortunately we don't all have the luxury of rewriting all our code in the trendy language du jour.
- wglb 16y agoCan you give an example of stop-the-world garbage collection?
- bhousel 16y agoJavascript... Yes, even V8. Side rant: it's part of the reason that my Palm Pre will sometimes just hang for a second at the worst times, such as when I go to answer the phone. :(
- kvs 16y agoTry allocating a very large chunk of memory using a high-level language with garbage collector. It's not always about collection.
- eru 16y agoWhy would you allocate a large chunk of memory, when you are using a garbage collected language? There may be reasons to want to mix manual and automatic memory management. If you want to do that, there are language that support it. Like D.
- kvs 16y agoNot necessarily allocating very large chunks in bulk but umm... Allocating nodes for a million nodes of a graph and subsequently processing them. Java JVM fragments memory heavily. En