您的位置:首页 > 其它

"The Trouble with Checked Exceptions A Conversation with Anders Hejlsberg, Part II" 阅读笔记

2010-12-22 15:34 507 查看
(Anders artima 访谈系列的第二部分
)

"Do the simplest thing
possible, but no simpler."

最近在规划一些小东西, 发现自己常常无意识的犯下过度设计的错误, 幸好看到这句话, 让我幡然醒悟.

"I'm a strong believer in being minimalistic."

这个系列, 七七八八看差不多了, 从中可以看出, Anders 对于 .Net 的设计, 确实是在遵循这个思路. 而 .Net 本身, 也称得上杰出了.

"Unless you actually are going to
solve the general problem, don't try and put in place a framework for solving a
specific one, because you don't know what that framework should look like."

作为一个设计过很多复杂框架, 系统的人都这样讲, 我们还有什么好说的呢.

关于异常处理, 有一整段非常精彩的评论, 摘抄如下

"Bill Venners
: What's in the finally?

Anders Hejlsberg
: In the finally, you protect yourself against the
exceptions, but you don't actually handle them. Error handling you put
somewhere else. Surely in any kind of event-driven application like any kind of
modern UI, you typically put an exception handler around your main message
pump, and you just handle exceptions as they fall out that way. But you make sure
you protect yourself all the way out by deallocating any resources you've
grabbed, and so forth. You clean up after yourself, so you're always in a
consistent state. You don't want a program where in 100 different places you
handle exceptions and pop up error dialogs. What if you want to change the
way you put up that dialog box? That's just terrible. The exception handling should be centralized,
and you should just protect yourself as the exceptions propagate out to the handler."

关于异常处理, 也曾困惑过, 看过网上的很多讨论, 大多限于谈玄论道, 给不出切实可行的建议. 当然, 异常处理本身很复杂, 需要见招拆招, 不能谈得很具体, 这也可以理解. 不过, 牛人之所以牛, 就在于能人所不能. Anders 这段话中提出的方式, 结合我自己的经验来看, 对于大多数的异常处理来说, 都简单, 且有效.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐