4 ms·
Which is why "defer" and the "go" should operate on blocks or statements, not expressions. For instance: defer { result++; } Instead of: defer func(
by 0xABADC0DA 14y ago
Which is why "defer" and the "go" should operate on blocks or statements, not expressions. For instance:
defer { result++; }
Instead of:
defer func() {
result++;
}();
Also that you need such an ugly syntax just to not silently ignore return values from "defer" and "go" speaks volumes. For instance the "defer f.Close()" in the original post ignores errors from close, and with no exceptions these are just lost. It should be something more like:
defer func() {
err := f.Close();
// handle error
}();
You are basically always going to use this form anyway if you care about error handling. But lack of error handling in Google Go is another issue entirely.