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

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

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

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


当前回答

当涉及到软件设计和开发时,设计模式是一种浪费时间的行为。

不要误解我的意思,设计模式是有用的,但主要是作为一种交流载体。它们可以非常简洁地表达复杂的思想:工厂、单例、迭代器……

但它们不应该作为一种开发方法。开发人员经常使用一系列基于设计模式的类来构建他们的代码,而在可读性和性能方面,更简洁的设计会更好。所有这些都带有一种幻想,即单个类可以在它们的域之外被重用。如果一个类不是为重用而设计的,或者不是接口的一部分,那么它就是一个实现细节。

设计模式应该被用来为组织特性命名,而不是用来规定必须编写代码的方式。

(这本来是有争议的,记得吗?)

其他回答

Requirements analysis, specification, design, and documentation will almost never fit into a "template." You are 100% of the time better off by starting with a blank document and beginning to type with a view of "I will explain this in such a way that if I were dead and someone else read this document, they would know everything that I know and see and understand now" and then organizing from there, letting section headings and such develop naturally and fit the task you are specifying, rather than being constrained to some business or school's idea of what your document should look like. If you have to do a diagram, rather than using somebody's formal and incomprehensible system, you're often better off just drawing a diagram that makes sense, with a clear legend, which actually specifies the system you are trying to specify and communicates the information that the developer on the other end (often you, after a few years) needs to receive.

[如果有必要,一旦您编写了真正的文档,您通常可以把它塞进组织强加给您的任何模板中。不过,你可能会发现自己不得不添加章节标题和重复的材料。

The only time templates for these kinds of documents make sense is when you have a large number of tasks which are very similar in nature, differing only in details. "Write a program to allow single-use remote login access through this modem bank, driving the terminal connection nexus with C-Kermit," "Produce a historical trend and forecast report for capacity usage," "Use this library to give all reports the ability to be faxed," "Fix this code for the year 2000 problem," and "Add database triggers to this table to populate a software product provided for us by a third-party vendor" can not all be described by the same template, no matter what people may think. And for the record, the requirements and design diagramming techniques that my college classes attempted to teach me and my classmates could not be used to specify a simple calculator program (and everyone knew it).

软件开发是计算机科学的一个非常小的子集。

人们有时似乎认为这两者是同义词,但实际上,计算机科学的许多方面是普通开发人员很少(如果有的话)接触到的。根据一个人的职业目标,我认为有很多计算机专业的毕业生如果接受某种软件工程教育可能会更好。

我非常重视教育,拥有计算机科学学士学位,并在业余时间攻读计算机科学硕士学位,但我认为许多获得这些学位的人将学位视为达到目的的手段,受益甚微。我认识很多人,他们上过和我一样的系统软件课程,写过和我一样的汇编程序,但直到今天他们都没有看到他们所做的任何价值。

程序员把他们自己的(有限的)编程语言视为神圣不可侵犯的宗教。

有趣的是,程序员几乎像宗教信徒一样对待这些讨论:不允许批评,(通常)不允许客观的讨论,(通常)基于非常有限或缺乏的知识和信息进行争论。为了确认,只需阅读之前的答案,尤其是评论。

同样有趣的是,另一个确认:根据“给我一个有争议的意见”这个问题的定义,任何有争议的意见都不应该被投反对票——实际上恰恰相反:越有争议越好。但我们的程序员是如何反应的:就像巴甫洛夫的狗一样,对不喜欢的意见投反对票。

PS:为了公平起见,我给其他一些人点了赞。

偶尔写一些垃圾代码是可以的

有时,一段快速而肮脏的垃圾代码就是完成特定任务所需要的全部。模式、orm、SRP等等……抛出一个控制台或Web应用程序,写一些内联sql(感觉不错),然后抛出需求。

Having a process that involves code being approved before it is merged onto the main line is a terrible idea. It breeds insecurity and laziness in developers, who, if they knew they could be screwing up dozens of people would be very careful about the changes they make, get lulled into a sense of not having to think about all the possible clients of the code they may be affecting. The person going over the code is less likely to have thought about it as much as the person writing it, so it can actually lead to poorer quality code being checked in... though, yes, it will probably follow all the style guidelines and be well commented :)