Re:Why I Write Games in C (yes, C)
by oldmanhorton on Saturday September 21, 2019 @01:24PM
(#21036625)
Because c++ without OOP still gives you RAII (which is neutered a bit if you don't write your own classes but still), safe pointers, references, lambda, and an immense standard library, to name a few.
[ Parent
| on HN ]
C++ RAII is completely gone without the use of classes; it requires something with a destructor.
I guess the OP means pod types (plain Cish structs) where dtors are implicit.
Re:Why I Write Games in C (yes, C)
by AnimalMuppet on Sunday September 22, 2019 @12:17AM
(#21039644)
But then what's left of RAII? What resource is there to allocate other than the memory itself? RAII means more than just "get memory to put this in".
Presuming GP includes unique_ptr, there's no real loss of RAII. In my opinion you might as well write trivial classes, but hey, to each his own.
That but without using any of the standard libraries. Even RAII can get in the way.
If by safe pointers you mean unique_ptr etc, I'm pretty sure those are classes: https://en.cppreference.com/w/cpp/memory/unique_ptr
So by definition require OOP?
OOP is such a nebulous thing. Just because the word 'class' is used doesn't mean something is OOP. Those smart pointers don't use inheritance, they don't implement any interfaces, no virtual methods...
I would call that using a subset of OOP features[1], not avoiding it entirely.
But I guess there's no point in arguing over semantics.
[1] As Wikipedia defines OOP: "a programming paradigm based on the concept of "objects", which can contain data, in the form of fields (often known as attributes or properties), and code, in the form of procedures (often known as methods)." https://en.wikipedia.org/wiki/Object-oriented_programming
It's not classic OOP without inheritance and virtual functions.
But nobody seriously uses virtual functions anymore, except where they would need to use function pointers, and for precisely those uses virtual functions are way better: cleaner, safer, often faster.