Yeah, sure. So it’s funny… When Go 1.0 was announced was actually the first that I had heard of Go, and at the I was working in C# for the most part with some Java and Python, and I was like “Oh, it’s a language from Google. I should go and see what it’s like.” And the very first thing that I’ve noticed was no exceptions. I was like, “Wow, that’s terrible… I’m not gonna use that.” [00:23:58.25] [laughs] Then they announced 1.01 about six months later, and I was like “Let me look at it again”, and the rest is history.

Exceptions are hard… Hard, hard, hard. In my last job was another big code base, I think somewhere around 50,000 lines of C#, and I remember one instance where I was modifying some code and I was like “Oh, this code can fail. I’ll have to throw in an exception.” And during a code review, someone was like “You can’t have that throw an exception, that’s way deep in the stack. We have no idea who will catch that.” That was for the first time I was like “Wow, exceptions aren’t that great. They’re basically a go-to, except that you don’t know where going to.” You can figure it out sometimes, but it’s very hard to know who is going to catch this error, and you have to clean everything up. And if you’re looking at a function, you have no idea what can fail. Any function that you call could fail. What’s worse is that it might not fail now, but in six months someone might modify it to fail, and that’s scary.

I remember one of the first Go programs that I wrote was just downloading a bunch of pictures off some website, and everything that could fail returned an error. It was this epiphany of, “Oh my god, I know what can fail. I can deal with all this, and I’d know exactly what my program’s gonna do.” I think dealing with errors is where Go really got it right, because the multiple returns means it’s very easy to just say, “Okay, this thing returns an error, but also some actual useful data.”

Yes, you have to do “if error =/= nil, blah”, but that’s good, because that means you’re saying, “I know this can fail. I’m gonna do something.”

People always talk about, “Oh, it makes my happy path look all messy”, and I’m like “This is programming. There is no happy path.”

Source link


Please enter your comment!
Please enter your name here