Hacker News new | ask | show | jobs
by wangchow 3470 days ago
Alas, having no garbage collector at all is a blissful state of simplicity when performance matters. It's not very difficult to clean up one's objects manually in a well-thought-out codebase.
3 comments

Experience (i.e. the number of memory-related bugs) suggests otherwise.
What about smart pointers? It gives the flexibility and benefits of garbage-collection without the performance degradation. It's not a silver bullet but it helps.

What I'm getting at is, Rust is the only modern language (in vogue at the moment) that does not use garbage collection. It would be nice if more languages didn't require a garbage collector but gave the option to use one.

If there are some more of such languages please chime in and provide a link to them! :)

> flexibility and benefits of garbage-collection

Not really, as it doesn't allow/collect cycles.

> without the performance degradation

Only for single-threaded code.

I agree with the rest of your comment!

A smart pointer is just a way to add custom behavior when it's created and destroyed. The question is what the smart pointer does. Usually the answer is update a reference count, which happens so frequently that it ends up being a lot more expensive (especially in bus bandwidth) than occasionally tracing live objects between long periods of useful work.
D has optional GC. However in hindsight it is perhaps not so smart. The problem is that it fractures the ecosystem: some libraries require GC and others don't. If you don't want to use it you have to rely only on non-GC libraries.
Smart pointers are as hard to manage as pointers.

There are different kind of smart pointers and you gotta think what you want to do with them. A GC is easier.

GC is certainly easier. However, it is important to understand the life-cycle of objects regardless. To be able to control them (if desired) is good because in many cases one would prefer to have that control instead of being forced to use garbage collector.

In an ideal world, garbage collector makes sense because we don't want to have to worry about life-cycle management when we are solving other problems. Memory management can indeed be an annoying implementation detail, but as it stands there are certainly limiting factors in hardware which are impacted by generic object-management for specific application domains.

GC isn't the the only way to achieve memory safety.
> well-thought-out codebase.

Which in real life means a single developer ownership codebase.

Or a meticulous team of very high quality engineers with top notch documentation and design practices. Note that I do agree with you, however, because as you said:

> in real life

In real life most companies don't want to pay for "meticulous team of very high quality engineers with top notch documentation and design practices".

They rather pay for outsourced consultants that deliver something that works within a fixed price contract.

Knuth's code has bugs. NASA's code has bugs. There's no reason to believe that high quality software engineers even exist.
High Quality != 0 bugs.

(Small) teams of high quality engineers do exist, but are very expensive.

And most humans are lazy f%$#s who throw things away rather than recycling them.
> It's not very difficult to clean up one's objects manually in a well-thought-out codebase.

Given the rarity of a well thought out codebase, I'd say it is. As soon as multiple people work on something confusion always ensues.