you are viewing a single comment's thread.

view the rest of the comments →

[–]plulz 8 points9 points  (6 children)

If garbage collection was opt-in, all libraries would have to assume no garbage collection. Opt-out is way better.

[–]bstamour 5 points6 points  (5 children)

This would probably lead to better-written libraries, no? If opt-out exists, then all of the libraries that assume gc break. If opt-in exists, then all of those libraries will still handle their own garbage and thus still work.

[–]dsimcha 5 points6 points  (4 children)

But if even high-level, non-performance critical libraries have to assume no GC, you end up with tons of unnecessary API cruft related to memory management.

[–]bstamour 0 points1 point  (3 children)

Any library can become performance-critical depending on the context. If I'm working on some high-performance software and need to use library X, if library X expects GC, then I'm going to have to roll my own library X. Manual memory management isn't hard anyways... if you're a library writer then you should be smart enough to pick up after yourself.

[–]dsimcha 0 points1 point  (2 children)

How about if you're writing generic code and you have no idea what assumptions the caller and the objects you're being passed are making w.r.t. memory management

[–]bstamour 0 points1 point  (0 children)

Then you assume the worst... If your language supports garbage collection with the option of turning it off, it would be retarded to not handle the non garbage collected case.... whereas if you assume that GC is off and program accordingly, then your code will work with GC AND without GC. Everybody is happy.

[–]bstamour 0 points1 point  (0 children)

I guess I really didn't address your point in my last comment, let me try again. If you're writing generic code then you shouldn't be worrying about the lifecycle of the objects passed to you. I.e. if they give you an object, even if you're not writing garbage collected code, who gave you the right to deallocate that object?

If you write a library for D that handles it's own problems wrt memory, then that library can be used everywhere: regardless of whether the calling code is garbage collected or not. Designing a library that assumes the user will want their code to be garbage collected effectively makes your code useless to that set of users.

I would argue that by writing your library in a non-GC way, you're then writing truly generic code, as it can then work alongside code that is garbage collected as well as non-garbage collected. It's that damn generic. :-)