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

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

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

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


当前回答

罗布·派克写道:“数据占主导地位。如果你选择了正确的数据结构,并且组织得很好,算法几乎总是不言而喻的。数据结构,而不是算法,才是编程的核心。”

由于现在任何重要的数据都在数百万条记录中,我认为良好的数据建模是最重要的编程技能(无论是使用rdbms还是sqlite或amazon simpleDB或谷歌appengine数据存储)。

当所有的数据都存储在这样的数据存储系统中时,就不再需要花哨的搜索和排序算法了。

其他回答

在1970年1月1日之前,真和假是相反的……

单身人士并不邪恶

There is a place for singletons in the real world, and methods to get around them (i.e. monostate pattern) are simply singletons in disguise. For instance, a Logger is a perfect candidate for a singleton. Addtionally, so is a message pump. My current app uses distributed computing, and different objects need to be able to send appropriate messages. There should only be one message pump, and everyone should be able to access it. The alternative is passing an object to my message pump everywhere it might be needed and hoping that a new developer doesn't new one up without thinking and wonder why his messages are going nowhere. The uniqueness of the singleton is the most important part, not its availability. The singleton has its place in the world.

微软应该停止支持任何与Visual Basic有关的东西。

我真的不喜欢当人们告诉我使用getter和setter而不是使变量公共时,你应该能够获得和设置类变量。

我完全同意如果是改变对象中的一个变量在你的对象中,你不会得到这样的东西:a.b.c.d.e = something;但我更愿意使用:a.x = something;然后a.setX(东西);我认为a.x =某物;实际上,在同一个例子中,它们都更容易阅读,而且比设置/获取更漂亮。

我不明白为什么要这样做:

void setX(T x) { 这个->x = x; }

T getX () { 返回x; }

这就需要更多的代码,需要更多的时间,你要一遍又一遍地做,这只会让代码更难阅读。

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

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

至少从关于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的目的是“帮助用户评估抽象的替代实现”。它并没有声称可以帮助用户定位需要替代实现的代码,在比函数更精细的级别上。


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