4 ms·
> ...the default for a file or connection is that you close it... Something like a file or connection is already not just 'plain old data' though. In my mind,
by flohofwoe 4y ago
> ...the default for a file or connection is that you close it...
Something like a file or connection is already not just 'plain old data' though.
In my mind, 'data' are the pixels in a texture (while the texture itself is an 'object'), or the vertices and indices in a 3D mesh (while the 'mesh' is an object), or the data that's read from or written to files (but not the 'file object' itself).
C is all about data manipulation (the 'pixels', 'vertices' and 'indices'), less about managing 'objects'.
For objects, constructors and destructors may be useful, but there are plenty cases in C++ where they are not (textures and meshes in a 3D API are actually a good example for where destructors are quite useless, because when the 'owner' of the CPU side texture object is done with the object doesn't mean that the GPU is done with the data that's 'owned' by the CPU side object - traditional destructors can be used of course by delaying the destruction on the CPU side texture object until the GPU is done with the data, but why keep the texture object around when only the pixel data is needed by the GPU, not the actual texture object?
A 'defer mechanism' is just the right sweet spot for a C like language IMHO.
- masklinn 4y ago> Something like a file or connection is already not just 'plain old data' though. OK? But now you need to… have two different mechanisms, when one can do both? > In my mind, 'data' are the pixels in a texture (while the texture itself is an 'object'), or the vertices and indices in a 3D mesh (while the 'mesh' is an object), or the data that's read from or written to files (but not the 'file object' itself). This “data” does not have a destructor, and thus is not a concern. > C is all about data manipulation (the 'pixels', 'vertices' and 'indices'), less about managing 'objects'. I think that would be news to every C program I’ve written. > there are plenty cases in C++ where they are not In which case you can just not have them, and not care. > A 'defer mechanism' is just the right sweet spot for a C like language IMHO. If by “a C like language” you mean “a language refuses to take any complexity off of the user’s back” then sure.