Re:Memory management in C programs (2014)
by reverius42 on Monday July 18, 2016 @11:01PM
(#12119270)
Init methods is the answer to that (but it potentially forces some additional complexity around initialized/not-initialized state into the other methods).
[ Parent
| on HN ]
Re:Memory management in C programs (2014)
by deathanatos on Monday July 18, 2016 @11:54PM
(#12119484)
As I stated in my original post, these have the same classes of problems as null pointers: you have "constructed" an object whose internal state in invalid; a instance of Foo is either a Foo that init'd successfully or not-a-Foo (that failed to init/isn't initialized; a "zombie object") just as a pointer is either a pointer-to-something or a pointer-to-nothing. This is why you say "it potentially forces some additional complexity around initialized/not-initialized state into the other methods.
At least in C++ (and many other OO languages), I find the downsides of having these Jekyll and Hyde classes outweigh any benefits that may come of ignoring exceptions.
In fact, I think managing this extra state, also dealing with complications that could arise from object slicing, were the major reasons given when Martin Sústrik argued he should have originally started out with ZeroMQ in C and not in C++.