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

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

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

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


当前回答

没有“放之四海而皆准”的发展方法

我很惊讶这是一个有争议的观点,因为在我看来这是常识。然而,在热门博客上有许多文章都在推广“一刀切”的开发方法,所以我认为我可能只是少数。

我所见过的被吹捧为任何项目的正确方法的东西——在了解任何关于它的信息之前——像使用测试驱动开发(TDD)、领域驱动设计(DDD)、对象关系映射(ORM)、敏捷(大A)、面向对象(OO)等等,等等,包括从方法到架构到组件的一切。当然,这些都是很有市场价值的首字母缩写。

人们甚至似乎在他们的博客上贴上徽章,比如“我是测试驱动的”或类似的东西,就好像他们严格坚持单一的方法,不管项目的细节是什么,实际上是一件好事。

它不是。

选择正确的方法、体系结构和组件,等等,是应该在每个项目的基础上完成的事情,不仅取决于您正在从事的项目的类型及其独特的需求,而且还取决于与您一起工作的团队的规模和能力。

其他回答

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

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.

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

编程:这是一份有趣的工作。

我似乎看到了两类开发人员。有些人不喜欢,但他们有能力,薪水也不错。另一组人喜欢它的程度有点令人毛骨悚然。这似乎就是他们的生活。

我只是觉得这份工作薪水高,而且有趣。每一天的每一分钟都有各种各样的学习新东西的空间。我想不出其他我更喜欢的工作了。但这仍然是一份工作。妥协是要做出来的,你生产的东西并不总是那么好。

因为我更愿意在沙滩上喝啤酒或和孩子们一起玩。

大多数开发人员对此一无所知

是的. .好了。我说过了。我从我认识的所有开发者身上发现了这一点。只有少数是真正好的。只有少数人明白代码应该被测试……面向对象的开发方法实际上是在帮助你。让我感到沮丧的是,有些人获得了开发人员的头衔,而实际上他们所能做的只是复制和粘贴一些源代码,然后执行它。

无论如何……我很高兴像stackoverflow这样的项目已经开始了。这对开发人员来说是件好事。有没有更好的办法?我做对了吗?也许我可以用这个技巧来加快速度,等等……

但是不行……大多数开发人员只是学习一种工作需要的语言,并坚持使用它,直到他们自己变成了老而暴躁的开发人员,不知道发生了什么。他们得到的只是一大笔薪水,因为他们只是比你大。

好吧……IT界的生活是不公平的,我将采取措施在未来忽略这些人。万岁!

关系数据库是在浪费时间。改用对象数据库!

关系数据库供应商试图欺骗我们,让我们相信世界上唯一可扩展的、持久的和安全的存储就是关系数据库。我是一个认证的DBA。你是否曾经花了几个小时试图优化一个查询,却不知道哪里出了问题?关系数据库不允许您在需要时创建自己的搜索路径。你把应用速度的控制权拱手让给了素未谋面的人,他们并不像你想象的那么聪明。

当然,有时在维护良好的数据库中,他们会为复杂的查询提供快速答案。但你为此付出的代价太高了!每次要读取数据项时,都必须选择编写原始SQL,这是很危险的。或者使用Object关系映射器,这会增加更多的复杂性和超出你控制的事情。

更重要的是,你被禁止提出智能搜索算法,因为每次该死的往返数据库花费你大约11毫秒。这太过分了。想象一下,您知道这个超级图算法,它将回答一个特定的问题,这个问题甚至可能无法用SQL表达!,在适当的时候。但是,即使您的算法是线性的,而有趣的算法不是线性的,也不要将它与关系数据库结合起来,因为枚举一个大表将花费您数小时!

将其与SandstoneDb或Gemstone for Smalltalk进行比较!如果你喜欢Java,试试db4o吧。

因此,我的建议是:使用对象- db。当然,它们并不完美,有些查询速度会比较慢。但是你会惊讶的发现很多人会更快。因为加载对象不需要在SQL和域数据之间进行所有这些奇怪的转换。如果您确实需要某个查询的速度,对象数据库有您应该信任的查询优化器:您的大脑。

源文件太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出来谷歌说的是"搜索,不排序"吗?那么,为什么同样的哲学不能应用于编程语言呢?