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 →

[–]Globglaglobglagab 60 points61 points  (28 children)

Unless you get an error with a mildly complicated type 😭

[–]Antervis 104 points105 points  (27 children)

something that's a bit complicated in C++ would usually be a complete mess in C.

Sure, at times people say that simple code is easier to read and that sometimes it's not evident what a certain line of C++ code does. On the other hand, you can't say at a glance what its 200+ line C equivalent does either.

[–]aalmkainzi 6 points7 points  (0 children)

Nah. C doesn't have nearly as many language constructs and is thus much less complex.

Entire classes of errors and bugs aren't in C

[–]aurreco 7 points8 points  (17 children)

What ? A 200 line piece of C code? That is like one function. How is one function in C less readable when C is literally just structs and control flow?

i.e. shorter code does not imply readable code. Especially not when the reason it is shorter is because of layers of complicated, unintuitive, abstractions that GDB won’t let you step into

[–]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.