I assert that 80% of the annoyance that people feel is the number of
lines required to handle errors, not the syntax. Thus, a large
segment of the community would stop caring about this if we modified
gofmt, not the go language. Specifically, gofmt would simply format
short if's on one lie when possible.
OLD:
a, err := ioutil.ReadFile(patha)
if err != nil {
return err
}
b, err := ioutil.ReadFile(pathb)
if err != nil {
return err
}
c, err := ioutil.ReadFile(pathc)
if err != nil {
return fmt.Errorf("wrapped %v: %w", pathc, err)
}
NEW:
a, err := ioutil.ReadFile(patha)
if err != nil { return err }
b, err := ioutil.ReadFile(pathb)
if err != nil { return err }
c, err := ioutil.ReadFile(pathc)
if err != nil { return fmt.Errorf("wrapped %v: %w", pathc, err) }
This is half as many lines, thus makes it easier to fit on one
screenful of an editor, which is often a cognitive limit for a
developer.
I'm not saying that this solves the problem, but I bet it would reduce
the pressure to fix it.
Tom
--
Email:
t...@whatexit.org Work: tlimo...@StackOverflow.com
Blog:
http://EverythingSysadmin.com/