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

It's also not even true, given that `if foo, err := bar(); err != nil {` is considered idiomatic over writing that over two lines.



Both are idiomatic. I use the two line version.

I don't like this form both for legibility, and the fact that it closes over the return value.


They are not the same though. I got bitten by this recently (Go beginner).

In the single line form, both foo and err are scope restricted to the if block. Found that out the hard way.




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

Search: