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

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

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

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


当前回答

生成文档良好的代码比生成文档不良的代码花费的时间更少

When I say well-documented I mean with comments that communicate your intention clearly at every step. Yes, typing comments takes some time. And yes, your coworkers should all be smart enough to figure out what you intended just by reading your descriptive function and variable names and spelunking their way through all your executable statements. But it takes more of their time to do it than if you had just explained your intentions, and clear documentation is especially helpful when the logic of the code turns out to be wrong. Not that your code would ever be wrong...

I firmly believe that if you time it from when you start a project to when you ship a defect-free product, writing well-documented code takes less time. For one thing, having to explain clearly what you're doing forces you to think it through clearly, and if you can't write a clear, concise explanation of what your code is accomplishing then it's probably not designed well. And for another purely selfish reason, well-documented and well-structured code is far easier to dump onto someone else to maintain - thus freeing the original author to go create the next big thing. I rarely if ever have to stop what I'm doing to explain how my code was meant to work because it's blatantly obvious to anyone who can read English (even if they can't read C/C++/C# etc.). And one more reason is, frankly, my memory just isn't that good! I can't recall what I had for breakfast yesterday, much less what I was thinking when I wrote code a month or a year ago. Perhaps your memory is far better than mine, but because I document my intentions I can quickly pick up wherever I left off and make changes without having to first figure out what I was thinking when I wrote it.

这就是为什么我能很好地编写文档——不是因为我觉得编写适合展示的漂亮代码是一种崇高的使命,也不是因为我是一个纯粹主义者,而只是因为端到端让我在更短的时间内发布高质量的软件。

其他回答

XML和HTML是web的“汇编语言”。为什么还要黑它?

很明显,现在很少有开发人员学习汇编语言/编写代码,因为它很原始,并且使您远离必须在高层解决的问题。所以我们发明了高级语言来封装这些级别的实体,通过我们可以在更高级别上联系到的语言元素来提高我们的工作效率。就像我们可以用计算机做更多的事情,而不仅仅是它的组成部分主板或CPU。

对于Web,在我看来,开发人员仍然在阅读/编写和破解HTML、CSS、XMl、模式等。

我认为这些语言相当于Web或其基础的“汇编语言”。 我们该结束了吗?当然,当出现问题时,我们有时需要破解它。 但可以肯定的是,这是个例外。 我断言,我们正在用等价的web级汇编语言取代机器级的低级汇编语言。

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

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

当我们从数据开始设计,并根据数据和数据之间的关系(表、外键和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.

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

两个人的想法比一个人的好

我坚信结对编程是提高代码质量和编程效率的首要因素。不幸的是,对于那些认为“更多人手=>更多代码=> $$$!”

没有“放之四海而皆准”的发展方法

我很惊讶这是一个有争议的观点,因为在我看来这是常识。然而,在热门博客上有许多文章都在推广“一刀切”的开发方法,所以我认为我可能只是少数。

我所见过的被吹捧为任何项目的正确方法的东西——在了解任何关于它的信息之前——像使用测试驱动开发(TDD)、领域驱动设计(DDD)、对象关系映射(ORM)、敏捷(大A)、面向对象(OO)等等,等等,包括从方法到架构到组件的一切。当然,这些都是很有市场价值的首字母缩写。

人们甚至似乎在他们的博客上贴上徽章,比如“我是测试驱动的”或类似的东西,就好像他们严格坚持单一的方法,不管项目的细节是什么,实际上是一件好事。

它不是。

选择正确的方法、体系结构和组件,等等,是应该在每个项目的基础上完成的事情,不仅取决于您正在从事的项目的类型及其独特的需求,而且还取决于与您一起工作的团队的规模和能力。

根据我得到的大量反馈,我最具争议的观点显然是,程序员并不总是读他们声称读过的书。这紧跟着我的观点,一个受过正规教育的程序员比一个自学成才的程序员更好(但不一定比另一个自学成才的程序员更好)。