by divan · 10mo ago · 0 comments
Literally the simplest way to deal with errors (cognitively and character wise). Since AI autocomplete entered the scene, typing this repetitive (for a reason) pattern became not a problem at all (I'm not even talking about post Claude Code era)
> The only resort the consumer of this library has is to parse the string value of this error for useful information.
Well, no. See for wrap/unwrap functionality https://go.dev/blog/go1.13-errors
> In Go, errors are values. They just aren’t particularly useful values.
In his example author could easily use his `progError` type instead.
Gosh, why it's so tempting to write a post about bad language instead of just reading docs or article about idiomatic usage?
Code is read 10x more than it is written. The noise this pattern introduces inhibits reading and rapid comprehension.
Things are getting marginally better now that go has errors.Is and errors.As, and also now that go is starting to get some functional iterators. But go is one of the least quickly-understandable of the modern languages currently in use.
Here is the thing... it's NOT a 'noise'. Untill you see handling 'error path' as noise, you will be trapped in searching magic bullet language solution to hide it. We've all been there.
When it takes five times as long to figure out how a function actually works (not only due to error handling, to be fair), the language has a problem.
Nonsense. We don't read letters, nor even words, we see patterns. if err != nil {} is easy to skip over visually.
I agree with you. I don't have problems with the `if err!=nil` syntax.
From my post: > It’s become something of a meme to bemoan the supposed difficulty of writing if err != nil. I actually won’t make that point because I think it is a very surface level point that has been talked about to death and *I don’t think the ‘verbosity’ of this code snippet is such an issue.*
I apologize if my language was ambiguous on whether or whether not I had a problem with that syntax.
>In his example author could easily use his `progError` type instead.
I agree, but it was my impression that type erasure was more idiomatic. I should have made it clear that I was criticizing that idiom, not the language.
>Well, no. See for wrap/unwrap functionality https://go.dev/blog/go1.13-errors
You are right. I should have done my research on that before writing that point. I still think that downcasting isn't the most elegant solution because it defeats the point of using the opaque return type but I agree that it is nowhere near as much of a problem as I thought it was.
Writing `pub` is personally more annoying to me than writing `if err != nil`. I understand that most people don't like how capitalization determines visibility, but I think it actually makes sense when you think about it.
that and the fact you can accidently silently ignore it without it being a compiler error