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

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

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

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


当前回答

XHTML是邪恶的。编写HTML

无论如何,您都必须将MIME类型设置为text/html,所以为什么要欺骗自己相信您实际上是在编写XML呢?无论谁要下载你的页面,他都会相信这是HTML,所以把它做成HTML。

有了这些,不要关闭你的<li>,这是没有必要的。不要关闭html标签,文件已经结束了。它是有效的HTML,可以被完美地解析。

它将创建更可读、更少的样板代码,并且不会丢失任何东西。HTML解析器工作得很好!

当你完成后,再转向HTML5。这样更好。

其他回答

要成为一名程序员,你必须会打字。

这在那些不知道如何打字,但坚持认为他们可以像任何打字员一样用两根手指搜索和啄的人之间存在争议,或者他们真的不需要花那么多时间打字,或者智能感知减轻了打字的需要……

我从来没有遇到过会打字的人,但坚持认为打字没什么区别。

参见:编程中最肮脏的小秘密

您不应该停留在您发现的编写“有效”代码的第一种方法上。

I really don't think this should be controversial, but it is. People see an example from elsewhere in the code, from online, or from some old "Teach yourself Advanced Power SQLJava#BeansServer in 3.14159 minutes" book dated 1999, and they think they know something and they copy it into their code. They don't walk through the example to find out what each line does. They don't think about the design of their program and see if there might be a more organized or more natural way to do the same thing. They don't make any attempt at keeping their skill sets up to date to learn that they are using ideas and methods deprecated in the last year of the previous millenium. They don't seem to have the experience to learn that what they're copying has created specific horrific maintenance burdens for programmers for years and that they can be avoided with a little more thought.

事实上,他们似乎甚至没有意识到做一件事可能有不止一种方法。

I come from the Perl world, where one of the slogans is "There's More Than One Way To Do It." (TMTOWTDI) People who've taken a cursory look at Perl have written it off as "write-only" or "unreadable," largely because they've looked at crappy code written by people with the mindset I described above. Those people have given zero thought to design, maintainability, organization, reduction of duplication in code, coupling, cohesion, encapsulation, etc. They write crap. Those people exist programming in every language, and easy to learn languages with many ways to do things give them plenty of rope and guns to shoot and hang themselves with. Simultaneously.

But if you hang around the Perl world for longer than a cursory look, and watch what the long-timers in the community are doing, you see a remarkable thing: the good Perl programmers spend some time seeking to find the best way to do something. When they're naming a new module, they ask around for suggestions and bounce their ideas off of people. They hand their code out to get looked at, critiqued, and modified. If they have to do something nasty, they encapsulate it in the smallest way possible in a module for use in a more organized way. Several implementations of the same idea might hang around for awhile, but they compete for mindshare and marketshare, and they compete by trying to do the best job, and a big part of that is by making themselves easily maintainable. Really good Perl programmers seem to think hard about what they are doing and looking for the best way to do things, rather than just grabbing the first idea that flits through their brain.

如今,我主要在Java世界中编程。我见过一些非常好的Java代码,但我也见过很多垃圾代码,而且我还看到了更多我在开头描述的心态:人们选择了第一个看起来可以工作的丑陋代码块,而不理解它,也不考虑是否有更好的方法。

You will see both mindsets in every language. I'm not trying to impugn Java specifically. (Actually I really like it in some ways ... maybe that should be my real controversial opinion!) But I'm coming to believe that every programmer needs to spend a good couple of years with a TMTOWTDI-style language, because even though conventional wisdom has it that this leads to chaos and crappy code, it actually seems to produce people who understand that you need to think about the repercussions of what you are doing instead of trusting your language to have been designed to make you do the right thing with no effort.

我确实认为你可能会在另一个方向上走得太远:例如,完美主义完全忽略了你的真正需求和目标(通常是你的业务的真正需求和目标,通常是盈利能力)。但我不认为任何人都能成为一个真正伟大的程序员,除非学会投入一些高于平均水平的努力来思考寻找最好的(或至少是最好的一种)方法来编码他们正在做的事情。

观点:大多数代码都很糟糕,因为这是程序员想要的。

间接地,我们一直在培育一种极具创造力的文化。这并不是说我不认为解决问题具有创造性元素——它确实存在——只是它与绘画之类的事情根本不一样(参见保罗·格雷厄姆的著名文章《黑客和画家》)。

If we bend our industry towards that approach, ultimately it means letting every programmer go forth and whack out whatever highly creative, crazy stuff they want. Of course, for any sizable project, trying to put together dozens of unrelated, unstructured, unplanned bits into one final coherent bit won't work by definition. That's not a guess, or an estimate, it's the state of the industry that we face today. How many times have you seen sub-bits of functionality in a major program that were completely inconsistent with the rest of the code? It's so common now, it's a wonder anyone cause use any of these messes.

复杂,复杂,丑陋的东西只会变得更糟,更不稳定。如果我们正在建造一些实体的东西,地球上的每个人都会说我们的东西是多么丑陋和糟糕,但由于它或多或少被虚拟隐藏起来,我们能够逃脱一些我们物种所见过的最糟糕的制造过程。(你能想象一辆车有四个不同的人用四种不同的方式设计了四个不同的轮子吗?)

但可悲的是,这一切中有争议的部分是,绝对没有理由这样做,除了历史上的文化倾向于更多的自由和更少的组织,所以我们保持了这种方式(可能变得更糟)。软件开发是一个笑话,但它是一个笑话,因为这是程序员想要的(但永远不会承认这是真的,“管理层的阴谋”对大多数人来说是一个更好的理由)。

我们还会搬起石头砸自己的脚多久,才会幡然醒悟,意识到我们才是握着枪、指着枪、扣动扳机的人?

保罗。

并不是所有的程序员都生而平等

管理人员经常认为DeveloperA == DeveloperB仅仅是因为它们具有相同的经验水平等等。事实上,一个开发人员的性能可能是另一个开发人员的10倍甚至100倍。

谈论它在政治上是有风险的,但有时我想指出,即使几个团队成员可能看起来具有相同的技能,但情况并不总是如此。我甚至见过这样的情况:首席开发人员“毫无希望”,而初级开发人员承担了所有实际工作——尽管如此,我还是确保他们得到了荣誉。:)

复制/粘贴不是反模式,事实上它有助于避免产生更多的错误

我的经验法则——只输入不能复制/粘贴的东西。如果创建类似的方法,类或文件-复制现有的并更改所需的内容。(我不是在谈论复制应该放在单个方法中的代码)。

我通常从不输入变量名——要么复制粘贴,要么使用IDE自动补全。如果需要一些DAO方法-复制类似的方法并更改所需的内容(即使将更改90%)。对某些人来说,这可能看起来是极度的懒惰或缺乏知识,但我几乎从来没有处理过由拼写错误引起的问题,而且它们通常很难捕捉(如果没有在编译级别检测到)。

每当我偏离我的复制粘贴规则,开始输入东西时,我总是拼写错误(这只是一个统计数据,没有人能立即写出完美的文本),然后花更多的时间试图找出哪里。