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

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

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

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


当前回答

c++是一门很好的语言

一两个星期前,我说c++不是一种很好的语言,在另一个问题上我几乎被私刑了。现在我试着反过来说。;)

不,认真地说,我当时想说的是,c++有很多缺陷,现在我还会再试一次。这一点很难否认。它是如此的复杂,以至于学好它实际上是一件你可以奉献一生的事情。它使许多常见的任务变得不必要的困难,允许用户一头扎进未定义的行为和不可移植的代码的海洋,而编译器没有给出警告。

但它并不是许多人试图创造的那种无用、破旧、过时、令人讨厌的语言。它不应该被掩盖和忽视。没有它,世界不会变得更好。它有一些独特的优势,不幸的是,隐藏在古怪的语法,遗留的麻烦,尤其是糟糕的c++老师背后。但是他们就在那里。

c++有许多我在用c#或其他“现代”语言编程时非常怀念的特性。其中有很多c#和其他现代语言可以学习的地方。

它并没有盲目地专注于OOP,而是探索并开创了泛型编程。它允许惊人地表达编译时元编程,生成极其高效、健壮和干净的代码。在c#出现LINQ或lambda表达式之前,它从函数式编程中吸取了近十年的经验教训。

它允许您通过静态断言和其他元编程技巧在编译时捕获数量惊人的错误,这极大地简化了调试,甚至在某些方面胜过单元测试。(我宁愿在编译时捕获错误,而不是在之后运行测试时捕获错误)。

变量的确定性销毁允许RAII,这是一个非常强大的小技巧,使try/finally块和c#使用块变得多余。

虽然有些人指责它是“由委员会设计的”,但我会说,是的,它是,在这种情况下,这实际上并不是一件坏事。看看Java的类库。又有多少类被弃用了?有多少不应该使用?有多少是相互复制的功能?有多少设计糟糕?

C++'s standard library is much smaller, but on the whole, it's remarkably well designed, and except for one or two minor warts (vector<bool>, for example), its design still holds up very well. When a feature is added to C++ or its standard library, it is subjected to heavy scrutiny. Couldn't Java have benefited from the same? .NET too, although it's younger and was somewhat better designed to begin with, is still accumulating a good handful of classes that are out of sync with reality, or were badly designed to begin with.

c++有很多其他语言无法比拟的优点。这是一门很好的语言

其他回答

开发团队应该更多地按照技术/架构层而不是业务功能来划分。

我来自一个开发者拥有“从网页到存储过程的一切”的普遍文化。因此,为了在系统/应用程序中实现一个功能,他们将准备数据库表模式,编写存储procs,匹配数据访问代码,实现业务逻辑和web服务方法,以及web页面接口。

And guess what? Everybody has their own way to doing things! Everyone struggles to learn the ASP.NET AJAX and Telerik or Infragistic suites, Enterprise Library or other productivity and data layer and persistence frameworks, Aspect-oriented frameworks, logging and caching application blocks, DB2 or Oracle percularities. And guess what? Everybody takes heck of a long time to learn how to do things the proper way! Meaning, lots of mistakes in the meantime and plenty of resulting defects and performance bottlenecks! And heck of a longer time to fix them! Across each and every layer! Everybody has a hand in every Visual Studio project. Nobody is specialised to handle and optmise one problem/technology domain. Too many chefs spoil the soup. All the chefs result in some radioactive goo.

Developers may have cross-layer/domain responsibilities, but they should not pretend that they can be masters of all disciplines, and should be limited to only a few. In my experience, when a project is not a small one and utilises lots of technologies, covering more business functions in a single layer is more productive (as well as encouraging more test code test that layer) than covering less business functions spanning the entire architectural stack (which motivates developers to test only via their UI and not test code).

没有面向对象编程这种东西。

我坚信非托管代码不值得这么麻烦。与查找内存泄漏相关的额外维护性开销(即使是最好的程序员偶尔也会引入这种开销)远远超过从c++这样的语言获得的性能。如果Java, c#等不能得到你需要的性能,买更多的机器。

清理和重构在(团队)开发中非常重要

A lot of work in team development has to do with management. If you are using a bug tracker than it is only useful if someone takes the time to close/structure things and lower the amount of tickets. If you are using a source code management somebody needs to cleanup here and restructure the repository quite often. If you are programming than there should be people caring about refactoring of the lazy produced stuff of others. It is part of most of the aspects some will face while doing software development.

大家都同意这种管理的必要性。而且它总是被跳过的第一件事!

这是有可能保护您的应用程序。

每次有人问如何防止用户盗版他们的应用,或者如何保护应用不受黑客攻击,答案都是不可能的。无稽之谈。如果你真的相信这一点,那就不锁门(或者直接把门拿出来!)。也不用去看医生了。你是凡人——试图治愈疾病只是推迟了不可避免的事情。

仅仅因为有人可能会盗版你的应用或入侵你的系统,并不意味着你不应该试图减少这样做的人。你真正要做的是让入侵者/海盗需要比他们愿意做的更多的工作。

就像在你的房子上安装门闩和ADT可以防止窃贼,合理的反盗版和安全措施可以让黑客和海盗远离你的路。当然,他们越想闯入,你就越需要安全保障。