←back to thread

316 points thunderbong | 3 comments | | HN request time: 0.415s | source
Show context
adontz ◴[] No.42202248[source]
This is a good example of "stringly typed" software. Golang designers did not want exceptions (still have them with panic/recover), but untyped errors are evil. On the other hand, how would one process typed errors without pattern matching? Because "catch" in most languages is a [rudimentary] pattern matching.

https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...

replies(1): >>42202266 #
KRAKRISMOTT ◴[] No.42202266[source]
Go has typed errors, it just didn't use it in this case.
replies(7): >>42202277 #>>42202378 #>>42202617 #>>42203319 #>>42205600 #>>42206561 #>>42208318 #
1. Svip ◴[] No.42202277[source]
The consumer didn't, but the error in the example is typed, it's called `MaxBytesError`.
replies(2): >>42202292 #>>42203341 #
2. eptcyka ◴[] No.42202292[source]
Matching the underlying type when using an interface never feels natural and is definitely the more foreign part of Go's syntax to people who are not super proficient with it. Thus, they fall back on what they know - string comparison.
3. simiones ◴[] No.42203341[source]
Only since go 1.19. It was a stringy error since go 1.0 until then.