On Sun, Jun 14, 2020 at 8:25 AM Tom Limoncelli <t...@whatexit.org> wrote:
>
> On Thu, Jun 4, 2020 at 3:34 PM Ian Lance Taylor <i...@golang.org> wrote:
> >
> > On Thu, Jun 4, 2020 at 8:43 AM <lgod...@gmail.com> wrote:
> > >
> > > ?? Why not a cleaner syntax e.g.  x = some_func ()  #{ }   .. symbol # 
> > > arbitrarily chosen
> >
> > Besides what other people have said, it may be of interest to glance
> > through 
> > https://github.com/golang/go/issues?q=is%3Aissue+label%3Aerror-handling
>
> 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.



https://golang.org/issue/38151

Ian

-- 
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/CAOyqgcXdXByxK2hmB1EqybyPw6NmbxwN793dipGTGmFxbkThMw%40mail.gmail.com.

Reply via email to