Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you remove the err assignment the compiler will also complain about a value assignment mismatch:

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

> tmp/sandbox307381845/main.go:8: multiple-value "html/template".New("foo").Parse() in single-value context

You would have to explicitly assign the err return value to underscore in order to ignore it.



hueving is correct, I meant something like this[1]. Of course, something like this[2] also works.

[1] https://play.golang.org/p/igdUx6qckf

[2] https://play.golang.org/p/_JW5QE_zOJ


That function does not have side effects, so it would be pointless to remove the assignment altogether.

Assigning errors to underscore is effectively the same as try { myFunc(); } except { pass; }, making them equivalent.


No, remove the entire assignment.




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

Search: