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

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

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

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


当前回答

如果你只能想到一种方法,那就别去做。

无论是一个界面布局,一个任务流,还是一段代码,都可以停止。做一些事情来收集更多的想法,比如询问其他人他们会怎么做,在你至少有三个完全不同的想法和至少一次信心危机之前,不要回去实施。

一般来说,当我认为某件事只能以一种方式完成,或者认为只有一种方法有任何优点时,那是因为我没有充分考虑应该彻底影响设计的因素。如果我这样做了,其中一些显然会发生冲突,导致混乱,从而做出实际的决定,而不是死记硬背的违约。

成为一个优秀的程序员并不意味着你就是一个优秀的界面设计师

遵循世界上所有的界面指南只会开始有所帮助。如果这是人类可能做到的…人们似乎有一种特殊的嗜好,就是把东西变得“可爱”和“聪明”。

其他回答

一个优秀的开发人员需要知道的不仅仅是如何编码

继承是邪恶的,应该被摈弃。

事实是,在任何情况下,聚合都更好。静态类型的OOP语言不能避免继承,它是描述方法想从类型中得到什么的唯一方法。但是动态语言和鸭子类型可以没有它。Ruby mixins比继承强大得多,也更可控。

两行代码太多了。

如果一个方法有第二行代码,它就是代码气味。重构。

扩展方法是魔鬼的工作

Everyone seems to think that extension methods in .Net are the best thing since sliced bread. The number of developers singing their praises seems to rise by the minute but I'm afraid I can't help but despise them and unless someone can come up with a brilliant justification or example that I haven't already heard then I will never write one. I recently came across this thread and I must say reading the examples of the highest voted extensions made me feel a little like vomiting (metaphorically of course).

主要原因是增加了可读性、改进了oo性以及更好地连接方法调用的能力。

I'm afraid I have to differ, I find in fact that they, unequivocally, reduce readability and OO-ness by virtue of the fact that they are at their core a lie. If you need a utility method that acts upon an object then write a utility method that acts on that object don't lie to me. When I see aString.SortMeBackwardsUsingKlingonSortOrder then string should have that method because that is telling me something about the string object not something about the AnnoyingNerdReferences.StringUtilities class.

LINQ是这样设计的,链式方法调用是必要的,以避免奇怪和不舒服的表达式,来自LINQ的扩展方法是可以理解的,但一般来说,链式方法调用降低了可读性,并导致我们在混乱的Perl竞赛中看到的那种代码。

因此,简而言之,扩展方法是邪恶的。摆脱撒旦的枷锁,致力于自由扩展代码。

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 :)