News for hackers. Stuff that matters.
Re:Twelve Years of Go by pxue on Wednesday November 10, 2021 @03:50PM (#29180566)
Compressing this into 1 line provides absolutely nothing for the reader, in fact, it absolutely takes away reability.
Re:Twelve Years of Go by The_Colonel on Wednesday November 10, 2021 @03:54PM (#29180621)
Readability absolutely suffers when almost everything you see on your screen is boilerplate.
Re:Twelve Years of Go by thatswrong0 on Wednesday November 10, 2021 @04:17PM (#29180951)
Seriously. I see so many functions in my code see that consist of 1 line of thing I actually care about followed by 3 lines of boilerplate if err not nil… over and over again.

IMO if Go didn’t have its tooling, no one would care about it.

Re:Twelve Years of Go by pxue on Wednesday November 10, 2021 @06:17PM (#29182294)
i have the completely opposite take.

every if err != nil; return err let's me mentally draw a line in the sand and not worry about exception handling for code above that line. It lets me start fresh and restart my mental model with the line of codes below the error handling block.

it doesn't take years of writing Go to understand this, all you need is a open mind to how Go does things.

Re:Twelve Years of Go by thatswrong0 on Friday November 12, 2021 @04:36PM (#29204827)
> It lets me start fresh and restart my mental model with the line of codes below the error handling block.

My code is almost exactly:

err := doThing()

if err != nil {

  return err
}

err = doAnotherThing()

if err != nil {

  return err
}

etc.

There's no need for me to "start fresh". Each line of actual stuff doing might return an error which needs to be returned. That's it. It's a complete waste of space and inhibits readability to absolutely no benefit. And this is extremely common across our code base.