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

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

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

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


当前回答

“谷歌一下”是可以的!

是的,我知道这冒犯了一些人,他们多年的密集记忆和/或辉煌的编程书籍开始在一种任何人都可以在几秒钟内访问的资源中倒下,但你不应该反对使用它的人。

我经常听到有人用谷歌搜索问题的答案,但这确实毫无意义。首先,必须承认每个人都需要参考资料。你不是什么都知道,你需要去查资料。我承认,你从哪里得到的信息真的重要吗?你是在书上查到的,还是在谷歌上查到的,还是从你幻觉中的会说话的青蛙那里听到的,这有关系吗?不。正确的答案就是正确的答案。

重要的是你理解这些材料,将其作为成功编程解决方案的手段,并且客户/雇主对结果感到满意。

(虽然如果你是从幻觉中会说话的青蛙那里得到答案,你可能还是应该得到一些帮助)

其他回答

Variable_Names_With_Bloody_Underscores

或者更糟

CAPITALIZED_VARIABLE_NAMES_WITH_BLOODY_UNDERSCORES

应该在全球范围内清除……与偏见!CamelCapsAreJustFine。 (全局常数不承受)

GOTO语句仅供11岁以下的开发人员使用

任何不支持指针的语言都名不副实

.Net = .Bloat 微软网站开发的最佳范例(无表情web 2) 是缓慢膨胀的最好的例子cr@pw@re曾经写过。 (可以试试Web Studio)

回应: 好的,让我来谈谈下划线的问题。从你提供的C链接:

-全局常量应该全部大写,用“_”分隔符。 我实际上同意这一点,因为这太明显了

-以NetworkABCKey为例。注意ABC中的C和调音中的K是如何混淆的。有些人不介意这一点,有些人只是讨厌它,所以你会在不同的代码中发现不同的策略,所以你永远不知道该如何调用某个东西。

我属于前者。我选择名字非常谨慎,如果你不能一眼看出K属于Key,那么英语可能不是你的第一语言。

C函数名 在c++项目中应该有很少的C函数。 对于C函数,使用GNU约定的所有小写字母,以'_'作为单词分隔符。

的理由

* It makes C functions very different from any C++ related names. 

例子

int some_bloody_function () { }

这些“标准”和惯例只不过是随时间而传下来的任意决定。我认为,虽然它们有一定的逻辑意义,但它们使代码变得混乱,使一些本应简短而易于阅读的东西变得笨拙、冗长和混乱。

C被采纳为事实上的标准,不是因为它友好,而是因为它无处不在。我可以用一种语法友好的高级语言用20行代码编写100行C代码。

这使得程序流易于阅读,并且我们都知道,在一年或更长时间后重新访问代码意味着要到处跟踪面包屑。

我确实使用下划线,但只对全局变量,因为它们很少,而且它们很明显。除此之外,一个经过深思熟虑的CamelCaps()函数/变量名还没有让我失望!

懒惰的程序员是最好的程序员

懒惰的程序员通常会找到方法来减少花在写代码上的时间(尤其是大量相似或重复的代码)。这通常转化为公司/团队中的其他开发人员可以从中受益的工具和工作流。

当开发人员遇到类似的项目时,他可能会创建工具来引导开发过程(例如,创建一个与公司的数据库设计范例一起工作的DRM层)。

此外,诸如此类的开发人员经常使用某种形式的代码生成。这意味着同一类型的所有错误(例如,代码生成器没有检查所有方法上的空参数)通常可以通过修复生成器来修复,而不是修复该错误的50多个实例。

一个懒惰的程序员可能会多花几个小时来完成第一个产品,但会为你节省几个月的时间。

“邪恶”这个词在Stackoverflow和类似论坛上是一个被滥用和过度使用的词。

使用它的人想象力太少。

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

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.

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

库克的格言随意收集……

The hardest language to learn is your second. The hardest OS to learn is your second one - especially if your first was an IBM mainframe. Once you've learned several seemingly different languages, you finally realize that all programming languages are the same - just minor differences in syntax. Although one can be quite productive and marketable without having learned any assembly, no one will ever have a visceral understanding of computing without it. Debuggers are the final refuge for programmers who don't really know what they're doing in the first place. No OS will ever be stable if it doesn't make use of hardware memory management. Low level systems programming is much, much easier than applications programming. The programmer who has a favorite language is just playing. Write the User's Guide FIRST! Policy and procedure are intended for those who lack the initiative to perform otherwise. (The Contractor's Creed): Tell'em what they need. Give'em what they want. Make sure the check clears. If you don't find programming fun, get out of it or accept that although you may make a living at it, you'll never be more than average. Just as the old farts have to learn the .NET method names, you'll have to learn the library calls. But there's nothing new there. The life of a programmer is one of constantly adapting to different environments, and the more tools you have hung on your belt, the more versatile and marketable you'll be. You may piddle around a bit with little code chunks near the beginning to try out some ideas, but, in general, one doesn't start coding in earnest until you KNOW how the whole program or app is going to be layed out, and you KNOW that the whole thing is going to work EXACTLY as advertised. For most projects with at least some degree of complexity, I generally end up spending 60 to 70 percent of the time up front just percolating ideas. Understand that programming has little to do with language and everything to do with algorithm. All of those nifty geegaws with memorable acronyms that folks have come up with over the years are just different ways of skinning the implementation cat. When you strip away all the OOPiness, RADology, Development Methodology 37, and Best Practice 42, you still have to deal with the basic building blocks of: assignments conditionals iterations control flow I/O

一旦你能真正地把自己包围起来,你最终会到达你想要的那个点 看(从编程的角度来看)编写库存应用程序之间的差别很小 一个汽车零部件公司,一个图形实时TCP性能分析仪,一个数学模型 一个恒星核心,或者一个约会日历。

初级程序员处理小块代码。随着经验的积累, 他们处理越来越大的代码块。 随着经验的增加,他们开始处理小块代码。