Hacker News new | ask | show | jobs
by leni536 1387 days ago
Except go's defer is scoped to the function, instead of the innermost enclosing scope.
2 comments

That's a good point and also one of the things I kinda like about Alumina. You can do thing like this and the file will only be closed at the end of the function rather than the end of the if block.

    let stream: &dyn Writable<Self> = if output_filename.is_some() {
        let file = File::create(output_filename.unwrap())?
        defer file.close();

        file
    } else {
        &StdioStream::stdout()
    };
So less granular and can be assymetric. Don’t think that’s a good thing
Me neither, I think it is insane.