这绝对是主观的,但我想尽量避免它变成争论。我认为如果人们恰当地对待它,这将是一个有趣的问题。

这个问题的想法来自于我对“你最讨厌的语言的哪五件事?”问题的回答。我认为c#中的类在默认情况下应该是密封的——我不会把我的理由放在这个问题上,但我可能会写一个更完整的解释来回答这个问题。我对评论中的讨论热度感到惊讶(目前有25条评论)。

那么,你有什么有争议的观点?我宁愿避免那些基于相对较少的基础而导致相当宗教的事情(例如,大括号放置),但例如可能包括“单元测试实际上并没有多大帮助”或“公共字段确实是可以的”之类的事情。重要的是(至少对我来说)你的观点背后是有理由的。

请提出你的观点和理由——我鼓励人们投票给那些有充分论证和有趣的观点,不管你是否恰好同意这些观点。


当前回答

你需要提防对象痴迷的程序员。

例如,如果你写了一个类,对内置类型(如int或float)建模,你可能是一个迷恋对象的程序员。

其他回答

永远不要以单例方式实现任何东西。

您可以决定不构造多个实例, 但始终确保您的实现可以处理更多。

我还没有发现任何使用单例的场景 才是正确的选择。

在过去的几年里,我对此进行了一些非常激烈的讨论, 但最后我总是对的。

That (at least during initial design), every Database Table (well, almost every one) should be clearly defined to contain some clearly understanable business entity or system-level domain abstraction, and that whether or not you use it as a a primary key and as Foreign Keys in other dependant tables, some column (attribute) or subset of the table attributes should be clearly defined to represent a unique key for that table (entity/abstraction). This is the only way to ensure that the overall table structure represents a logically consistent representation of the complete system data structure, without overlap or misunbderstood flattening. I am a firm believeer in using non-meaningful surrogate keys for Pks and Fks and join functionality, (for performance, ease of use, and other reasons), but I beleive the tendency in this direction has taken the database community too far away from the original Cobb principles, and we jhave lost much of the benefits (of database consistency) that natural keys provided.

那么为什么不两者都用呢?

代码即设计:Jack W. Reeves的三篇文章

任何软件的源代码都是其最准确的设计文档。其他的一切(规格,文档,有时还有注释)要么是不正确的,过时的,要么是误导性的。

肯定会让你在任何地方被炒。

没有闭包我也能活。

看起来现在每个人和他们的母亲都想在一种语言中出现闭包,因为它是自切片面包以来最伟大的发明。我认为这只是另一种炒作。

绝大多数正在开发的软件在收集需求时不涉及最终用户。

通常只是一些经理提供“需求”。