Hacker News new | past | comments | ask | show | jobs | submit login

Open a scope when you check resource acquisition passed, rather than the opposite (jump to the end of the function if it failed).

It can get quite hilly, which doesn't look great. It does have the advantage that each resource is explicitly only valid in a visible scope, and there's a marker at the end to denote the valid region of the resource is ending.

EDIT: you mentioned early return, this style forbids early return (at least, any early return after the first resource acquisition)






Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: