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

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

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

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


当前回答

我最具争议的编程观点是 发现性能问题与测量无关,而是与捕获有关。

如果你在一个房间里寻找大象(而不是老鼠),你需要知道它们有多大吗?不!你要做的就是看。 它们的巨大使得它们很容易被发现! 没有必要先测量它们。

至少从关于gprof的论文开始,度量的思想就已经成为常识 (Susan L. Graham, et al 1982)*,而一直以来,就在我们的眼皮底下,有一种非常简单直接的方法来寻找值得优化的代码。

作为一个小例子,下面是它的工作原理。假设您从调用堆栈中抽取5个随机时间样本,并且恰好在5个样本中的3个样本中看到特定的指令。这说明了什么?

.............   .............   .............   .............   .............
.............   .............   .............   .............   .............
Foo: call Bar   .............   .............   Foo: call Bar   .............
.............   Foo: call Bar   .............   .............   .............
.............   .............   .............   Foo: call Bar   .............
.............   .............   .............   .............   .............
                .............                                   .............

它告诉你程序花费60%的时间做指令请求的工作。去掉它就去掉了60%:

...\...../...   ...\...../...   .............   ...\...../...   .............
....\.../....   ....\.../....   .............   ....\.../....   .............
Foo: \a/l Bar   .....\./.....   .............   Foo: \a/l Bar   .............
......X......   Foo: cXll Bar   .............   ......X......   .............
...../.\.....   ...../.\.....   .............   Foo: /a\l Bar   .............
..../...\....   ..../...\....   .............   ..../...\....   .............
   /     \      .../.....\...                      /     \      .............

约。

如果您可以删除指令(或更少地调用它),大约是2.5倍的加速。(注意-递归是无关紧要的-如果大象怀孕了,它不会更小。) 然后你可以重复这个过程,直到你真正接近最优。

这并不需要精确的测量、函数计时、调用计数、图表、数百个样本,以及任何典型的分析内容。

有些人在遇到性能问题时就使用这种方法,但他们不明白这有什么大不了的。

Most people have never heard of it, and when they do hear of it, think it is just an inferior mode of sampling. But it is very different, because it pinpoints problems by giving cost of call sites (as well as terminal instructions), as a percent of wall-clock time. Most profilers (not all), whether they use sampling or instrumentation, do not do that. Instead they give a variety of summary measurements that are, at best, clues to the possible location of problems. Here is a more extensive summary of the differences.

*事实上,这篇论文声称gprof的目的是“帮助用户评估抽象的替代实现”。它并没有声称可以帮助用户定位需要替代实现的代码,在比函数更精细的级别上。


我第二个最具争议的观点是这个,如果它不是那么难以理解的话。

其他回答

I work in ASP.NET / VB.NET a lot and find ViewState an absolute nightmare. It's enabled by default on the majority of fields and causes a large quantity of encoded data at the start of every web page. The bigger a page gets in terms of controls on a page, the larger the ViewState data will become. Most people don't turn an eye to it, but it creates a large set of data which is usually irrelevant to the tasks being carried on the page. You must manually disable this option on all ASP controls if they're not being used. It's either that or have custom controls for everything.

在我使用的一些页面上,页面的一半是由ViewState组成的,这真的很遗憾,因为可能有更好的方法来做到这一点。

这只是我在语言/技术观点方面能想到的一个小例子。这可能会引起争议。

顺便说一下,你可能想在这个帖子上编辑投票,它可能会被一些人热得很;)

web的MVC应该比传统的MVC简单得多。

Traditional MVC involves code that "listens" for "events" so that the view can continually be updated to reflect the current state of the model. In the web paradigm however, the web server already does the listening, and the request is the event. Therefore MVC for the web need only be a specific instance of the mediator pattern: controllers mediating between views and the model. If a web framework is crafted properly, a re-usable core should probably not be more than 100 lines. That core need only implement the "page controller" paradigm but should be extensible so as to be able to support the "front controller" paradigm.

下面是我自己的框架的核心方法,它成功地应用于一家财富100强的网络硬件制造商为一家财富50强的媒体公司生产的嵌入式消费设备。我的方法被一位前Smalltalk程序员和Oreilly一本关于有史以来最杰出的Java web框架的书的作者比作Smalltalk;此外,我已经将相同的框架移植到mod_python/psp。

static function sendResponse(IBareBonesController $controller) {
  $controller->setMto($controller->applyInputToModel());
  $controller->mto->applyModelToView();
}

编程还处于初级阶段。

尽管编程语言和方法已经发展了很多年,但我们还有很长的路要走。迹象很明显:

语言文档在互联网上随意传播(stackoverflow在这里有所帮助)。 语言在语法上的进化必然会破坏之前的版本。 调试仍然经常使用printf完成。 语言库或其他形式的大规模代码重用仍然相当罕见。

显然,所有这些都在改善,但如果我们都能同意这是开始而不是结束就好了=)。

我最具争议的编程观点是 发现性能问题与测量无关,而是与捕获有关。

如果你在一个房间里寻找大象(而不是老鼠),你需要知道它们有多大吗?不!你要做的就是看。 它们的巨大使得它们很容易被发现! 没有必要先测量它们。

至少从关于gprof的论文开始,度量的思想就已经成为常识 (Susan L. Graham, et al 1982)*,而一直以来,就在我们的眼皮底下,有一种非常简单直接的方法来寻找值得优化的代码。

作为一个小例子,下面是它的工作原理。假设您从调用堆栈中抽取5个随机时间样本,并且恰好在5个样本中的3个样本中看到特定的指令。这说明了什么?

.............   .............   .............   .............   .............
.............   .............   .............   .............   .............
Foo: call Bar   .............   .............   Foo: call Bar   .............
.............   Foo: call Bar   .............   .............   .............
.............   .............   .............   Foo: call Bar   .............
.............   .............   .............   .............   .............
                .............                                   .............

它告诉你程序花费60%的时间做指令请求的工作。去掉它就去掉了60%:

...\...../...   ...\...../...   .............   ...\...../...   .............
....\.../....   ....\.../....   .............   ....\.../....   .............
Foo: \a/l Bar   .....\./.....   .............   Foo: \a/l Bar   .............
......X......   Foo: cXll Bar   .............   ......X......   .............
...../.\.....   ...../.\.....   .............   Foo: /a\l Bar   .............
..../...\....   ..../...\....   .............   ..../...\....   .............
   /     \      .../.....\...                      /     \      .............

约。

如果您可以删除指令(或更少地调用它),大约是2.5倍的加速。(注意-递归是无关紧要的-如果大象怀孕了,它不会更小。) 然后你可以重复这个过程,直到你真正接近最优。

这并不需要精确的测量、函数计时、调用计数、图表、数百个样本,以及任何典型的分析内容。

有些人在遇到性能问题时就使用这种方法,但他们不明白这有什么大不了的。

Most people have never heard of it, and when they do hear of it, think it is just an inferior mode of sampling. But it is very different, because it pinpoints problems by giving cost of call sites (as well as terminal instructions), as a percent of wall-clock time. Most profilers (not all), whether they use sampling or instrumentation, do not do that. Instead they give a variety of summary measurements that are, at best, clues to the possible location of problems. Here is a more extensive summary of the differences.

*事实上,这篇论文声称gprof的目的是“帮助用户评估抽象的替代实现”。它并没有声称可以帮助用户定位需要替代实现的代码,在比函数更精细的级别上。


我第二个最具争议的观点是这个,如果它不是那么难以理解的话。

宏,预处理器指令和注释是邪恶的。

每个文件只使用一种语法和语言!

//不适用于Make文件或插入真实代码的编辑器宏。