News for hackers. Stuff that matters.
Re:Avoid Else, Return Early (2013) by monocasa on Monday March 26, 2018 @01:09PM (#16680502)
RAII works just as well for heap allocated objects as it does for stack allocated ones.
Re:Avoid Else, Return Early (2013) by jstimpfle on Monday March 26, 2018 @03:36PM (#16681758)
Sure, but allocating resources on the stack is not good for maintainability. Software is easier to understand if its state is not hidden in semi-permanent call stack frames.
Re:Avoid Else, Return Early (2013) by monocasa on Monday March 26, 2018 @04:28PM (#16682252)
In general I agree with you, but that seems orthogonal to the subject at hand.
Re:Avoid Else, Return Early (2013) by jstimpfle on Monday March 26, 2018 @05:38PM (#16682864)
Parent's statement was that early returns are hard because you need to cleanup allocated resources. I don't think so, because there shouldn't (usually) be resources "on the stack".
Re:Avoid Else, Return Early (2013) by monocasa on Monday March 26, 2018 @05:53PM (#16682985)
But RAII is orthogonal to auto, static, or dynamic allocation.