News for hackers. Stuff that matters.
Re:Why I Write Games in C (yes, C) by pier25 on Saturday September 21, 2019 @01:19PM (#21036575)
> I do write games and game engine code and tools in C++ without using any of the OOP features.

Excuse my C/C++ ignorance, but why not simply use C?

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.
Re:Why I Write Games in C (yes, C) by kazinator on Saturday September 21, 2019 @04:00PM (#21037574)
C++ RAII is completely gone without the use of classes; it requires something with a destructor.
Re:Why I Write Games in C (yes, C) by vnorilo on Saturday September 21, 2019 @11:06PM (#21039381)
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".
Re:Why I Write Games in C (yes, C) by vnorilo on Sunday September 22, 2019 @12:44AM (#21039715)
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.
Re:Why I Write Games in C (yes, C) by yvdriess on Saturday September 21, 2019 @02:21PM (#21036984)
That but without using any of the standard libraries. Even RAII can get in the way.
Re:Why I Write Games in C (yes, C) by klipt on Saturday September 21, 2019 @01:35PM (#21036706)
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?

Re:Why I Write Games in C (yes, C) by Thiez on Saturday September 21, 2019 @02:13PM (#21036925)
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...
Re:Why I Write Games in C (yes, C) by klipt on Saturday September 21, 2019 @03:45PM (#21037465)
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

Re:Why I Write Games in C (yes, C) by ncmncm on Sunday September 22, 2019 @04:40AM (#21040322)
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.

Re:Why I Write Games in C (yes, C) by choeger on Saturday September 21, 2019 @01:24PM (#21036624)
There is still the STL, there are still templates and data structures have a very well-defined lifetime.
Re:Why I Write Games in C (yes, C) by skrebbel on Saturday September 21, 2019 @01:34PM (#21036699)
Isn't the STL mostly classes? How is that not OO?
Re:Why I Write Games in C (yes, C) by gpderetta on Sunday September 22, 2019 @03:58PM (#21043558)
STL has nothing to do with OOP . In Alex Stepanov (the ST in STL) words "object orientedness is almost as much of a hoax as Artificial Intelligence"
Re:Why I Write Games in C (yes, C) by choeger on Saturday September 21, 2019 @04:41PM (#21037813)
Well, yes you have some objects in there. But it is rather an implementation detail. You don't use inheritance for instance.
Re:Why I Write Games in C (yes, C) by bullen on Sunday September 22, 2019 @03:18AM (#21040090)
I use string and stream, also most libraries (glew) and compilers (MinGW) that are updated use C++.

To avoid cache misses you can't use OOP, that's probably where this wave of going back to C is coming from:

For example here's how someone that knows how computers work writes Java games: http://www.javaonthebrain.com/java/warp/warp.java

Re:Why I Write Games in C (yes, C) by z3phyr on Saturday September 21, 2019 @01:31PM (#21036680)
If C gets operator overloading and RAII, there will be no good reason to use C++ for me!!
Re:Why I Write Games in C (yes, C) by FrozenVoid on Monday September 23, 2019 @01:27AM (#21046164)
Only operator overloading is really important and would cut down the size of code written substantially. Thats the only real advantage of using C++ vs C. Everything else oop, function overloading,RAII,etc can be replaced with macros and structs.
Re:Why I Write Games in C (yes, C) by pingyong on Monday September 23, 2019 @08:54AM (#21048422)
Pretty sure you can't make destructors with macros?
Re:Why I Write Games in C (yes, C) by FrozenVoid on Wednesday September 25, 2019 @07:44AM (#21069759)
Re:Why I Write Games in C (yes, C) by sramsay on Saturday September 21, 2019 @02:35PM (#21037061)
Is RAII in C a serious suggestion being made anywhere?
Re:Why I Write Games in C (yes, C) by kazinator on Saturday September 21, 2019 @04:02PM (#21037578)
GCC has it as an extension. See the cleanup attribute:

https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attribute...

Re:Why I Write Games in C (yes, C) by ncmncm on Sunday September 22, 2019 @04:41AM (#21040325)
It is meaningless without destructors and exceptions.