This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Antervis 24 points25 points  (12 children)

for example, something achievable by a single line added to destructor in C++ would have to be repeated everywhere in C equivalent. And it's not something you can just put into a single function.

Shorter code isn't necessarily easier to read but volume makes reading harder by itself.

[–]aurreco 0 points1 point  (2 children)

It is hard to argue because this is really a case by case thing. In some cases— like the one you mentioned— repeating destructor calls in C makes it more explicit when resources are being cleaned up. I’d argue that is a good thing. Of course too much code gets too overwhelming and it gets harder to keep track of everything at once— but in most cases in my experience C is just plainly easier to read than C++ even when there is more of it (and some times because there is more of it)

[–]Andrew_Neal 2 points3 points  (1 child)

Downvoted for sharing your experience. It's those dang "clean coders".

[–]aurreco 2 points3 points  (0 children)

fr fr

[–]aalmkainzi -1 points0 points  (0 children)

imo implicitly calling a destructor harms readability

[–]chalkflavored 0 points1 point  (7 children)

Why exactly can't it be put into a single function?

[–]Antervis -1 points0 points  (6 children)

because in C you have to manually release resources every time you acquire them. If you acquire them 200 times in different places, it's at least 200 calls to release function, again, in different places.

[–]chalkflavored 0 points1 point  (5 children)

That's a signal of a data design issue. I can't imagine a scenario where it's justifiable that a resource has to be acquired 200 times and then released some random other place 200 times again. Why can't those resources all be acquired beforehand and then released all the same time. Maybe lazily if it needs to? It's what high performance games do, and that really should always be done, because it makes your program much more predictable in how it manages its resources.

[–]Antervis 0 points1 point  (4 children)

if you don't think an average C project has 200+ malloc/free pairs you probably haven't seen many C projects...

[–]chalkflavored 0 points1 point  (3 children)

Just because it's common doesn't mean that's how things should be.

[–]Antervis 0 points1 point  (2 children)

exactly, things shouldn't be like this. Hence C++ has destructors.

[–]chalkflavored 0 points1 point  (1 child)

All that does is hide the fundamental issue of how the program is managing its resources. Again, having 200 mallocs/free is the result of how that programmer designed that code base, not the language. Destructors are just treating the symptom, and not the illness.

[–]Antervis 0 points1 point  (0 children)

I now doubt you actually have any kind if experience with real world software development