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

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

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

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


当前回答

单身人士并不邪恶

There is a place for singletons in the real world, and methods to get around them (i.e. monostate pattern) are simply singletons in disguise. For instance, a Logger is a perfect candidate for a singleton. Addtionally, so is a message pump. My current app uses distributed computing, and different objects need to be able to send appropriate messages. There should only be one message pump, and everyone should be able to access it. The alternative is passing an object to my message pump everywhere it might be needed and hoping that a new developer doesn't new one up without thinking and wonder why his messages are going nowhere. The uniqueness of the singleton is the most important part, not its availability. The singleton has its place in the world.

其他回答

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

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

让您的业务逻辑远离DB。或者至少,保持它非常精简。让DB做它应该做的事情。让代码做它应该做的事情。时期。

If you're a one man show (basically, arrogant & egotistical, not listening to the wisdom of others just because you're in control), do as you wish. I don't believe you're that way since you're asking to begin with. But I've met a few when it comes to this subject and felt the need to specify. If you work with DBA's but do your own DB work, keep clearly defined partitions between your business objects, the gateway between them and the DB, and the DB itself. If you work with DBA's and aren't allowed to do your DB work (either by policy or because they're premadonnas), you're very close to being a fool placing your reliance on them to get anything done by putting code-dependant business logic in your DB entities (sprocs, functions, etc.). If you're a DBA, make developers keep their DB entities clean & lean.

不会编码的架构师是无用的。

这听起来有点苛刻,但并非不合理。如果你是一个系统的“架构师”,但对所使用的技术没有一定的实际参与,那么你如何获得开发团队的尊重呢?你如何影响方向?

架构师需要做更多的事情(与利益相关者会面,与其他团队谈判,评估供应商,编写文档,进行演示等等)但是,如果您从未看到架构师签入代码……小心!

设计模式是石器时代编程语言设计的一个症状

他们有自己的目的。很多优秀的软件都是用它们开发出来的。但事实上,我们需要编写这些心理抽象的“配方”,关于你的代码如何工作/应该如何工作,这说明缺乏足够有表现力的编程语言来为我们处理这种抽象。

补救措施,我认为,在于允许你将越来越多的设计嵌入到代码中的语言,通过定义可能不存在或可能没有普遍适用性,但在你的代码不断处理的情况下真的真的有意义的语言结构。Scheme的人已经知道这一点很多年了,Scheme宏可能会让大多数猴子尿裤子。

并不是所有东西都需要封装到自己的方法中。有时候让一个方法做不止一件事是可以的。