News for hackers. Stuff that matters.
Re:Show HN: Crown – A flexible game engine written from scra... by mbel on Thursday June 22, 2017 @07:43AM (#14611509)
Probably because exceptions are the biggest source of pain with RAII.
Re:Show HN: Crown – A flexible game engine written from scra... by tjoff on Thursday June 22, 2017 @07:46AM (#14611521)
I'd say that exceptions are the biggest source of pain if you don't have RAII.

Or, rephrased: RAII is incredibly attractive, especially when exceptions are being used.

Re:Show HN: Crown – A flexible game engine written from scra... by dgfgfdagasdfgfa on Thursday June 22, 2017 @03:57PM (#14614855)
RAII is necessary for exceptions. Why the hell would you do that to yourself?
Re:Show HN: Crown – A flexible game engine written from scra... by leni536 on Thursday June 22, 2017 @08:10AM (#14611646)
How do you deal with constructors that might fail?
Re:Show HN: Crown – A flexible game engine written from scra... by adrift on Thursday June 22, 2017 @08:47AM (#14611844)
You don't have constructors that 'fail'.
Re:Show HN: Crown – A flexible game engine written from scra... by ryandrake on Thursday June 22, 2017 @10:14AM (#14612354)
So, allocating memory for objects is not part of construction? Again, why not just stick with C?
Re:Show HN: Crown – A flexible game engine written from scra... by eropple on Thursday June 22, 2017 @11:23AM (#14612857)
Memory for objects is allocated structurally as part of the object, not dynamically, wherever possible. And it's usually very possible. If you can't do that, provide an initialization method. (In almost all cases, I would personally prefer hiding that two-phase initialization within a factory function.)

As for "why not stick with C"--all of the other reasons still hold true, from templates on down. The simple existence of dtors with viable scope guards that are guaranteed to fire when exiting scope is reason enough for me to never write C and to look with a default skepticism on any codebase that thinks its developers are perfect enough not to need them.

Re:Show HN: Crown – A flexible game engine written from scra... by mbel on Thursday June 22, 2017 @11:23AM (#14612855)
> Again, why not just stick with C?

The thing that is hard to replicate in C is destructors. Automatic deinitialization when leaving scope in very convenient. It allows you to have multiple exists from the scope without preceding each of them with prologue of dinit_*() calls or creating single exit point and jumping to it.

Coupling allocation with initialization is trivial to do without C++ constructors (which I find to be very poorly designed).

Re:Show HN: Crown – A flexible game engine written from scra... by to3m on Thursday June 22, 2017 @11:32AM (#14612935)
C doesn't let you have destructors that automatically clean up whatever got initialised in the Init method (if it was called), but C++ does.