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

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

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

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


当前回答

观点:数据驱动的设计本末倒置。它应该立即从我们的思想中消除。

绝大多数软件不是关于数据的,而是关于我们试图为客户解决的业务问题。它是关于一个问题域的,涉及对象、规则、流程、案例和关系。

当我们从数据开始设计,并根据数据和数据之间的关系(表、外键和x-to-x关系)对系统的其余部分建模时,我们将整个应用程序限制为如何在数据库中存储数据和如何从数据库中检索数据。此外,我们将数据库体系结构公开给软件。

数据库模式是一个实现细节。我们应该可以自由地改变它,而不需要对我们的软件设计进行任何显著的改变。业务层不应该知道表是如何设置的,或者是从视图中提取还是从表中提取,或者是从动态SQL或存储过程中获取表。这种类型的代码永远不应该出现在表示层中。

软件是用来解决业务问题的。我们要处理用户、汽车、帐户、余额、平均值、摘要、转账、动物、消息、包裹、购物车、订单和其他各种真实的有形对象,以及我们可以对它们执行的操作。我们需要根据需要保存、加载、更新、查找和删除这些项。有时候,我们必须以特殊的方式来做这些事情。

But there's no real compelling reason that we should take the work that should be done in the database and move it away from the data and put it in the source code, potentially on a separate machine (introducing network traffic and degrading performance). Doing so means turning our backs on the decades of work that has already been done to improve the performance of stored procedures and functions built into databases. The argument that stored procedures introduce "yet another API" to be manged is specious: of course it does; that API is a facade that shields you from the database schema, including the intricate details of primary and foreign keys, transactions, cursors, and so on, and it prevents you from having to splice SQL together in your source code.

把马放回马车前面。思考问题领域,并围绕它设计解决方案。然后,从问题域导出数据。

其他回答

单元测试不会帮助你写出好的代码

进行单元测试的唯一原因是确保已经工作的代码不会崩溃。首先编写测试,或者为测试编写代码都是荒谬的。如果在编写代码之前编写测试,您甚至不知道边界情况是什么。您的代码可能通过了测试,但在不可预见的情况下仍然会失败。

此外,优秀的开发人员会保持较低的内聚性,这将使新代码的添加不太可能对现有内容造成问题。

事实上,我将进一步推广,

软件工程中的大多数“最佳实践”都是为了防止糟糕的程序员造成太大的破坏。

他们的作用是指导糟糕的开发人员,防止他们犯愚蠢的错误。当然,由于大多数开发人员都很糟糕,这是一件好事,但优秀的开发人员应该得到通过。

当有人认为整个编程语言“笨拙”时,通常是因为他不知道如何使用它。

只有一种设计模式:封装

例如:

工厂方法:您已经封装了对象创建 策略:封装了不同的可变算法 迭代器:您封装了按顺序访问集合中的元素的方法。

编写完代码后再编写规格说明。(如果有的话)

In many projects I have been involved in, a great deal of effort was spent at the outset writing a "spec" in Microsoft Word. This process culminated in a "sign off" meeting when the big shots bought in on the project, and after that meeting nobody ever looked at this document again. These documents are a complete waste of time and don't reflect how software is actually designed. This is not to say there are not other valuable artifacts of application design. They are usually contained on index cards, snapshots of whiteboards, cocktail napkins and other similar media that provide a kind of timeline for the app design. These are usually are the real specs of the app. If you are going to write a Word document, (and I am not particularly saying you should) do it at the end of the project. At least it will accurately represent what has been done in the code and might help someone down the road like the the QA team or the next version developers.

意见:没有函数定义和返回类型会导致代码灵活易读。

这种观点可能更适用于解释型语言,而不是编译型语言。需要一个返回类型和一个函数参数列表,这对于智能感知来自动记录你的代码是很好的,但它们也是限制。

不要误解我的意思,我不是说扔掉返回类型,或者参数列表。他们有自己的位置。在90%的情况下,它们是利大于弊的。

在某些时候和场合,这是有用的。