Hello Gophers,

since I obviously don't have enough Twitter followers to get more than one answer to my Go question I'm posting it here ;-)

Would you consider this idiomatic Go code?

https://play.golang.org/p/ymPt_9tKQ9p

I'm talking specifically about returning a cleanup function. My reasoning for it goes kinda like this:

- doSomething doesn't care whether the output is a file or a buffer or os.Stdout, so it should just get an io.Writer. - The cleanup work for using os.Stdout (or a buffer in tests) is different than for *os.File. - Who's responsible for doing that work? If I return *os.File directly from getFile(), there's an implicit assumption that the file needs to be closed by the caller. But what if it's os.Stdout? - The alternative of putting all that in run() is kinda ugly because run() potentially has to do a lot more.

A potential problem I see? The error from os.File.Close() is never checked, neither is the error from bufio.Writer.Flush(). In this small example that wouldn't bother me because it means the program ends anyway. But in other cases it might become more of a problem.

What do you think?

Kind regards,
Chris

--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/7baf0ec35696fc5501dfbe6ce8f161f8%40vonkietzell.de.

Reply via email to