对C++的一点抱怨

一段时间不写C++代码了,写起来感觉有些陌生了,特别是对于C++的模板实现更是心中没底,各种错误出现、效率底下让我不得不有些后悔当初项目采用了C++并且大量使用了STL。

然而毕竟项目已经成型,完全推倒并用纯C重构在时间上和精力上已经不太可行。选择一种语言,就像是选择一个爱人,即使后来觉得不太称心,还是要坚持到最后。好在语言的选择只是在一个项目上,随着项目的结束而结束;而爱人是一辈子,应该更加慎重抉择:)。

烦恼之余,重读大牛Linus炮轰C++的激扬文字,聊以自慰。

From: Linus Torvalds <torvalds <at> linux-foundation.org>
Subject: Re: [RFC] Convert builin-mailinfo.c to use The Better String Library.
Newsgroups: gmane.comp.version-control.git
Date: 2007-09-06 17:50:28 GMT (2 years, 14 weeks, 16 hours and 36 minutes ago)

On Wed, 5 Sep 2007, Dmitry Kakurin wrote:
>
> When I first looked at Git source code two things struck me as odd:
> 1. Pure C as opposed to C++. No idea why. Please don‘t talk about portability,
> it‘s BS.

*YOU* are full of bullshit.

C++ is a horrible language. It‘s made more horrible by the fact that a lot
of substandard programmers use it, to the point where it‘s much much
easier to generate total and utter crap with it. Quite frankly, even if
the choice of C were to do *nothing* but keep the C++ programmers out,
that in itself would be a huge reason to use C.

In other words: the choice of C is the only sane choice. I know Miles
Bader jokingly said "to piss you off", but it‘s actually true. I‘ve come
to the conclusion that any programmer that would prefer the project to be
in C++ over C is likely a programmer that I really *would* prefer to piss
off, so that he doesn‘t come and screw up any project I‘m involved with.

C++ leads to really really bad design choices. You invariably start using
the "nice" library features of the language like STL and Boost and other
total and utter crap, that may "help" you program, but causes:

 - infinite amounts of pain when they don‘t work (and anybody who tells me
   that STL and especially Boost are stable and portable is just so full
   of BS that it‘s not even funny)

 - inefficient abstracted programming models where two years down the road
   you notice that some abstraction wasn‘t very efficient, but now all
   your code depends on all the nice object models around it, and you
   cannot fix it without rewriting your app.
In other words, the only way to do good, efficient, and system-level and
portable C++ ends up to limit yourself to all the things that are
basically available in C. And limiting your project to C means that people
don‘t screw that up, and also means that you get a lot of programmers that
do actually understand low-level issues and don‘t screw things up with any
idiotic "object model" crap.

So I‘m sorry, but for something like git, where efficiency was a primary
objective, the "advantages" of C++ is just a huge mistake. The fact that
we also piss off people who cannot see that is just a big additional
advantage.

If you want a VCS that is written in C++, go play with Monotone. Really.
They use a "real database". They use "nice object-oriented libraries".
They use "nice C++ abstractions". And quite frankly, as a result of all
these design decisions that sound so appealing to some CS people, the end
result is a horrible and unmaintainable mess.

But I‘m sure you‘d like it more than git.

            Linus

From: Linus Torvalds
Subject: Re: Compiling C++ kernel module + Makefile
Date: Mon, 19 Jan 2004 22:46:23 -0800 (PST)

On Tue, 20 Jan 2004, Robin Rosenberg wrote:
>
> This is the "We‘ve always used COBOL^H^H^H^H" argument. 

In fact, in Linux we did try C++ once already, back in 1992.

It sucks. Trust me - writing kernel code in C++ is a BLOODY STUPID IDEA.

The fact is, C++ compilers are not trustworthy. They were even worse in
1992, but some fundamental facts haven‘t changed:

 - the whole C++ exception handling thing is fundamentally broken. It‘s
   _especially_ broken for kernels.
 - any compiler or language that likes to hide things like memory
   allocations behind your back just isn‘t a good choice for a kernel.
 - you can write object-oriented code (useful for filesystems etc) in C,
   _without_ the crap that is C++.

In general, I‘d say that anybody who designs his kernel modules for C++ is
either
 (a) looking for problems
 (b) a C++ bigot that can‘t see what he is writing is really just C anyway
 (c) was given an assignment in CS class to do so.

Feel free to make up (d).

        Linus

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-06 03:15:09

对C++的一点抱怨的相关文章

男生失恋了怎么办才能最快走出来

两人之间永远那么和谐.婚姻就应该向热恋那样经营, 少一点抱怨,多一份谅解:少一点争吵,对一点甜蜜:少一些斤斤计较,多一些宽容理解. 第一.展现自我魅力,让对方开心. 热恋时,我们总会千方百计地讨好恋人,希望能让对方喜欢我们, 所以就无所不用其极地去展现自己的优点及魅力. 我们便松懈了这种积极 的原动力.例如,都要打扮一番,而婚后就开始不修边幅; 婚前每天接送女友上下班,而婚后就只想在家睡大觉-- 请试着用恋爱时的积极心态展现自己当时的优点,你就会发现,经营幸福其实并不难. 第二.精心安排相处时光

C# 闭包

1. 首先要说明的是, delegate 被编译器 编译成一个class, 所以才能传来传去(具体参考 <CLR via C#>第四版), 所以 Action.Func也是如此 2. 在C#中,原来闭包只是编译器玩的花招而已,它仍然没有脱离.NET对象生命周期的规则,它将需要修改作用域的变量直接封装到返回的类中变成类的一个属性,从而保证了变量的生命周期不会随函数调用结束而结束,因为变量n在这里已经成了返回的类的一个属性. 这个观点引用自 C#与闭包, 写的很好, 将原文也贴出来吧 首先想说明一

用Maven管理搭服务器管理系统(二)

用Maven创建web项目这里我就不多说了,不会的网上查找. 从今天开始搭建一套网上开源的服务器管理系统-蓝缘2.0,项目功能很简单,主要是权限管理这块,框架技术springMVC+springSecurity3.x+Mybaits3.x,项目在官网上也有展示,提供商业版,这种就属于自己卖自己的产品,不过现在网上很多好的开源项目都缺少相应的文档,说是开源,但是不分享项目业务以及项目逻辑.搭建过程以及技术框架,很多人拿到源码也是不知道怎么去用,经常会遇到部署出现问题,我并不是喷那些分享代码的人,只

因为虚度年华而悔恨,因为碌碌无为而感到羞愧

人生如流水,往事已如烟.那些淹埋在历史中的辉煌,已成了无法等待的过去:那些匆匆追赶的岁月,已让人来不及停留.人生,有很多难言的酸楚,也有很多甜蜜的欢笑.得与失都会成为过去,我们要的是对活着的拥有. 拼搏的路上,有些机会如同竹篮里的水,抓不住就会漏掉,它来不及为你的错过而等待,就如天空的流星只为那一刻而闪耀,当你的视线来不及停留,绚丽就会消逝.人生中的许多良辰美景,只为那一段而夺目:生命中的许多舞台,只为那一出戏而布景.因此,人生的一切美好,需要用心去珍惜,用行动去争取,用毅力去坚持.最后,无论是

windows底下怎么让cmder通过输入subl去打开sublime text

在window自身的cmd或者你安装的cmder中输入 doskey subl="D:\Program Files\sublime3\Sublime Text 3\sublime_text.exe" $* 说明书名:subl="这里输入安装目录". 如果你安装cygwin,则输入下面一条 $ echo 'alias subl="/cygdrive/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe"

喜剧之王

喜剧之王 二十个春秋也不过是一场云烟,二十年的独白未必没有经典,一些东西未必会被这个时代所遗忘,而时隔十九年的喜剧之王,今天我才看了一遍,曾经早已耳闻这部作品的经典,可一直没有去看过,今天观后,我想来说一说:"说一说这血与泪的经典传奇". 纵观整部电影,我看见的是一个小人物追求自己梦想的辛酸历程.尹天仇,一个非常平凡的普通人,每天坚持给自己定位,每次肯定自己的位置,反复强调:"其实呢,我是一个演员",即使他只不过是个跑龙套的,面对别人的嘲笑.训斥依然坚持打入演艺圈.

ASP.NET Core Windows服务开发技术实战演练

一.课程介绍 人生苦短,我用.NET Core!大家都知道如果想要程序一直运行在Windows服务器上,最好是把程序写成Windows服务程序:这样程序会随着系统的自动启动而启动,自动关闭而关闭,不需要用户直接登录,直接开机就可以启动.今天阿笨将给大家带来实如何利用.NET Core跨平台开发技术在Windows操作系统平台上开发我们的Windows服务应用程序以及在Linux操作系统上部署我们的守护进程(daemon)服务,真真的体现.NET Core的跨平台强大之处: 实现一次编译,多平台部

ASP.NET Core WebApi基于Redis实现Token接口安全认证

一.课程介绍 明人不说暗话,跟着阿笨一起玩WebApi!开发提供数据的WebApi服务,最重要的是数据的安全性.那么对于我们来说,如何确保数据的安全将会是需要思考的问题.在ASP.NET WebService服务中可以通过SoapHead验证机制来实现,那么在ASP.NET Core WebApi中我们应该如何保证我们的接口安全呢?  近年来RESTful API开始风靡,使用HTTP header来传递认证令牌似乎变得理所应当,而单页应用(SPA).前后端分离架构似乎正在促成越来越多的WEB应

人不仅需要勤奋努力 人生还需要一点智慧

人不仅需要勤奋努力 人生还需要一点智慧 人生是需要一点智慧,否则,你很可能就会感到迷茫和纠结的.人生是需要一点智慧的,否则,乐观者在磨难中看到机会,悲观者在机会中看到磨难.相同的视角,不同的角度,便会体会到天壤之别的差异. 我们每个人的心灵都是一扇窗,而心灵之外的所有事物,就构成了生活中花花绿绿.分外妖娆的世界.在这个多姿多彩的世界上,我们经历着人生的无常,多少次我们的心灵在黑暗.抑郁中徘徊,或因为失败而受挫折,或因为烦闷而感失落.多少次我们的灵魂饱经生活的磨难,几欲跌进绝望的深渊.而在生活中我