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

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

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

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


当前回答

世界需要更多的goto

人们虔诚地避免goto,除了“我的教授告诉我goto不好”之外,没有其他理由。它们有一个目的,可以在很多地方极大地简化生产代码。

也就是说,在你所编写的99%的代码中,它们都是不必要的。

其他回答

你不需要编写所有的程序

我厌倦了所有的事情,但所有的事情都需要塞进一个程序,这样总是更快。一切都需要基于网络,一切都需要通过计算机完成。请用你的笔和纸。它更快,更少维护。

源文件太20世纪了。

在函数/方法的主体中,将过程逻辑表示为线性文本是有意义的。即使逻辑不是严格的线性,我们也有良好的编程结构(循环、if语句等),允许我们使用线性文本清晰地表示非线性操作。

But there is no reason that I should be required to divide my classes among distinct files or sort my functions/methods/fields/properties/etc in a particular order within those files. Why can't we just throw all those things within a big database file and let the IDE take care of sorting everything dynamically? If I want to sort my members by name then I'll click the member header on the members table. If I want to sort them by accessibility then I'll click the accessibility header. If I want to view my classes as an inheritence tree, then I'll click the button to do that.

Perhaps classes and members could be viewed spatially, as if they were some sort of entities within a virtual world. If the programmer desired, the IDE could automatically position classes & members that use each other near each other so that they're easy to find. Imaging being able to zoom in and out of this virtual world. Zoom all the way out and you can namespace galaxies with little class planets in them. Zoom in to a namespace and you can see class planets with method continents and islands and inner classes as orbitting moons. Zoom in to a method, and you see... the source code for that method.

基本上,我的观点是,在现代语言中,不管你把你的类放在什么文件中,或者你定义一个类的成员的顺序是什么,那么为什么我们仍然被迫使用这些古老的实践呢?还记得Gmail出来谷歌说的是"搜索,不排序"吗?那么,为什么同样的哲学不能应用于编程语言呢?

编写大量的规格说明是徒劳的。 编写正确的程序是相当困难的,但是编译器、调试器、单元测试器、测试器等使检测和消除大多数错误成为可能。另一方面,当你像一个程序(例如,伪代码,UML)那样编写具有相当详细级别的规范时,你主要是靠自己。如果您有一个工具可以帮助您正确地处理语法,那么您应该感到幸运。

广泛的规范很可能充满bug。 编写人员在第一次尝试中得到正确答案的可能性,与一个类似的大型程序在没有经过测试的情况下没有错误的可能性是相同的。同行评审可以消除一些错误,就像代码评审一样。

复制/粘贴是万恶之源。

世界需要更多的goto

人们虔诚地避免goto,除了“我的教授告诉我goto不好”之外,没有其他理由。它们有一个目的,可以在很多地方极大地简化生产代码。

也就是说,在你所编写的99%的代码中,它们都是不必要的。