知识卡片
错误返回应表达真实失败可能
错误结果用于表达函数职责内可能发生的失败,不必为已由静态类型保证的条件重复添加运行时检查。Add(int,int)内部反射检查参数是否为int不能接住Add(“foo”,2),因为调用本身不能通过编译。外部输入应在解析和业务验证边界报告问题,而非给每个小函数机械添加一个永远为空的error。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 九、Go 中的日志记录和并发测试 · 查看原书依据
re (very poorly) reinventing the wheel. Go's internal compiler kills this long before we ever see it. So, we should focus on things that the comp
参考来源
- 位置:《精通 Go 并发(机翻)》spine12《九、Go 中的日志记录和并发测试》(book-sources;extracted/精通 Go 并发(机翻)/_epub-src/OEBPS/Text/11.html)。
- 结论依据:原文Add(int,int)尝试用反射检查静态参数,再用字符串调用;编译阶段已经拒绝该调用,支持只为真实失败边界设计error。
- 原始内容:re (very poorly) reinventing the wheel. Go's internal compiler kills this long before we ever see it. So, we should focus on things that the comp