是的,Go 确实有异常

  • Zig official website's Overview page states there is no hidden control flow, memory allocations, preprocessor, or macros. It gives an example code var a = b + c.d; foo(); bar(); showing clear control flow.
  • Examples of hidden control flow in other languages: D has @property functions, C++, D, and Rust have operator overloading, and C++, D, and Go have throw/catch exceptions (Go's panic/recover is also a form of exception handling).
  • At GoLab 2022, a Go core team member was asked about having a "never recover" policy to avoid concurrency-related issues. The answer was to assume that dependent code, including stdlib code, might try to recover.
  • Even if a Go developer never calls recover themselves, code they depend on might do so. This is a problem as shown by new issues on the Zig website repository.
  • The Go marketing & learning industry is criticized for not making Go users aware that the language has exceptions.
  • For those still unconvinced, see a practical example in the follow-up post [https://kristoff.it/blog/go-e...]. (Correction: Defer statements do run during a panic but other stuff could be in a corrupted state as misremembered earlier.)
阅读 23
0 条评论