你真的了解C++ 吗?(1分)

  • 主题发起人 主题发起人 ggym
  • 开始时间 开始时间
G

ggym

Unregistered / Unconfirmed
GUEST, unregistred user!
在1998年的元旦,Bjarne Stroustrup(C++之父)接受了IEEE《计算机》杂志记者的专
访。编辑很自然的认为他会对于过去七年来使用他创建的语言进行面对对象设计做一个
历史性的回顾。而在这个专访中,记者获得了更有价值的新闻,但是最后编辑决定为了
整个IT产业,这个稿子不能发表,但是就像其它被砍掉的新闻,往往还是弄得路人皆知
的。这一篇适当时专访的完全拷贝,没有被编辑、删改或者做过什么润色处理,也没有
发布
过,可能看起来不像常见的杂志文章,但这是实情。你会发现真正引人入胜的地方...
...记者: 您在几年前你改变了软件设计世界的面貌,现在再回首往事您有什么感想?
Stroustrup: 事实上我在你到来之前的这些天里一直在考虑这件事,你还记得几乎所有
的人都在写C程序那会儿吗?麻烦的是这些人写得太好了,而且那些个大学也都在努力
的传授C编程技术。的确他们是十分的成功——我要特别的指出“成功”这个词——因
为这种显著的C程序员的培养效率,这就是产生问题的原因。记者: 这难道是个问题吗
?Stroustrup: 当然,你记得大家都在用Cobol语言写程序的时候吗?
记者: 哦,当然,当时我也一样。Stroustrup: 在一开始的时候,这些人简直象半个上
帝似的拿着高工资,享受着贵族一样的待遇。
记者: 唉,那些日子多么的让人怀念,是吧?Stroustrup: 当然了。但是接着发生了什
么?IBM觉得这样不舒服,就投资了数百万来
培养程序员,直到程序员多得一毛钱就可以雇一打。记者: 这就是为什么当时我撤出来
了,工资在一年里就降到人们在说做个记者都比程序员强的地步。
Stroustrup: 对啦!那时侯相同的事情发生在了C程序员身上了。记者: 这个我明白
了,可是您要说的是……
Stroustrup: 有一天,我坐在办公室里就在想如何能把这件事挽回一些。我想知道如果
有一种特别复杂而且难以学会的语言,是否就没有人可以又把程序员们搞到市场的泥潭
里去呢?我用了从X10里了解到的东西,,噢,就是X-Windows,真是一个该死的图形系
统,只能运行在那些个SUN 3/60的机器里,哈!它具有所有我想要的特征:可笑而复杂
的语法,含混的功能描述,还有伪装的OO结构,就算是在现在,还是没有人愿意用那些
东西,如果你不想发疯的话,Motif才是唯一解决方案。记者: 你是在开玩笑吗?
Stroustrup: 没有,事实上还有另外的一个问题,UNIX是用C写的,就是说任何一个C程
序员都可以很容易的成为系统程序的开发者。还记得一个大型的主机系统应用的开发者
通常能挣多少钱吗?记者: 你肯定是知道我当时就是干这个的。
Stroustrup: 好吧,因此这个新的语言一定要通过隐藏所有的系统调用来和UNIX分离开
来,这样可以使那些个就只是知道DOS的人也可以活得很体面。
记者: 我不大相信您说的这个……Stroustrup: 而且到现在时间也够长的了,我相信有
很多的人已经指出了C++是对时间
的浪费,我要说的是,这个过程比我想象的要长的多了。记者: 那么您又是如何做到的
呢?
Stroustrup: 那只是一个玩笑,我真的没有想到人们会对那本书那么认真。任何人只要
长了半个大脑也应该明白面对对象编程是荒谬而不合逻辑的,而且效率低下。
记者: 什么?Stroustrup: 再说代码重用,你什么时候听说过有公司重用他的代码?记
者: 事实上从来没有,但是……
Stroustrup: 那么我提醒你一下,在早期有很多的例子。哦,有一家叫Menter Graphi
cs的俄勒冈州公司,我认为他们应该是感冒了,竟然在90年或者是91年把所有的代码用
C++重写了一遍,对不起,我实在是想不起确切的时间了,我看大家应该从这个事件中
吸取教训。记者: 没有人真正的吸取了教训吗?Stroustrup:没有,而且还有很多公司
犯同样的错误,还向他们的股东解释说那3亿美圆的损失是正
常的,他们就是做了这样的事情。记者: 真的?可是这也只能证明OO方法是能够工作
的,不是吗?
Stroustrup: 也许吧,执行文件是那么大,在一台有128M内存的HP工作站上只是装载到
内存中就要用5分钟时间,然后将象毛毛虫爬树一样的运行。事实上我在第一个礼拜就
发现了这个缺点,奇怪的是好象没人在乎这个,Sun和HP好象只在乎买出那些功能强大
的各种玩意儿,而不在乎在上面跑什么程序。在AT&.T的时候我编了一个“Hello
World”程序,简直是难以置信,执行文件有2.1M。
记者: 那么大?是啊,就是从那时候开始的编译程序产生大个的文件的。Stroustrup:
就是这个样子,如果你不信的话,可以用最新版的g++试一下,你得到的
东西不会小于0.5M,而且就在最近也有一些在各个国家的例子,比如在British Telec
om公司发生的灾难,但是幸运的是他们把原来的计划废弃了,又重新开始,他们就比A
ustralian Telecom公司幸运,现在我又听说Siemens公司又在造“恐龙”了,他们目前
是越来越担心要用来加速执行软件所要使用的昂贵的高速硬件,难道你真的认为那些个
多态继承是一种乐趣吗?记者: 噢,但是C++的确是一种可靠的语言啊!
Stroustrup: 你是真的相信的,对吧?你有没有真的坐下来用C++开发过项目?我来告
诉你会发生什么:首先,我会加入足够的缺陷来让那些微不足道的模块先执行,让工作
超载,在工程扫尾的阶段,你回发现几乎所有的模块都会有这种缺陷,这是因为人们以
为就是应该这样做,因为在C++的教程中就是这样写的。在相同的模块中执行不同对象
的相似操作意味着:有一些东西在各个模块中是完全不相同的。当你有了互不相同的上
百个这样的模块,就可以把他们集成在一起了。其次,我再说说所谓的数据隐藏,上帝
啊,当我听说了有的小组实现了什么对象协同通信,我真的是憋不住想笑!我看,OO方
法中的“协同”这个词可以把项目经理的肋条累断。记者: 我不得不说着太可怕了!你
还说这是用来提高程序员的工资,这太龌龊了!
Stroustrup: 龌龊?不是这样的,任何人都有选择的权利。我是并不想让事情发展成这
个样儿的。不管怎么说,我基本上还是成功的。C++现在已经不行了不是?而且程序员
现在还是能挣到高工资的——特别是那些还要维护这些该死的“++”东西的那些程序员
。你应该明白如果你去维护一个不是由你开发的C++模块是不可能的。记者: 怎么会这
样的?Stroustrup: 你糊涂了?还记得typedef吗?
记者: 噢,当然。Stroustrup: 知道要在头文件里发现象'RoofRaised'这样的变量是一
个双精度数要用多
长的时间吗?想象一下要在一个工程里所有的类定义里寻找那些typedefs... ......
...记者: 那么你为什么认定你已经成功了呢?
Stroustrup: 还记得一般一个C程序项目要多长时间吗?一般是6个月。这对于一个要养
活妻子孩子的程序员是不够的。如果是一样的项目,但是用C++来开发,会怎么样呢?
我告诉你:要一两年才能做完!这不好吗?就是一个小小的编程语言选择的决定,语言
程序员就不会轻易的下岗了不是?而且那些个大学已经很久没有传授C了,现在是对C程
序员的短缺。特别是对UNIX编程熟悉的程序员。在使用了这么多年的“new”以后,而
且一直以来一直都不用担心返回值的问题。还有多少程序员知道使用“malloc”?事实
上,大多数的C++程序员舍弃了返回值,无论什么样的结果,甚至于返回了“-1”,其
实用不着什么'throw'、'catch'、'try'之类的东西,至少你应该知道产生了错误。记
者: 但是继承的确不是可以节省很多时间的吗?
Stroustrup: 是吗?你注意过C项目计划和C++的项目计划之间的不同吗?在进行了三次
系统功能分解后,要确定所有的东西都可被继承到,如果没有那么说明还是有错,但是
有谁在C编程里听说过存储渗漏这个说法?现在你可以在业界的大厂商的产品中发现了
!有很多的公司不得不放弃了,并且把工程转包出去,他们知道最后可能象筛沙子似的
把内存站用完,他们才不想遭那份罪呢!记者: 也有一些工具来……
Stroustrup: 大多数的防渗漏的工具不还是用C++写的。记者: 果把这些东西发表了,
我们可能在这个行业里无法立足了,你知道吗?
Stroustrup: 我不相信,就象我所说的,现在C++已经是在垂死挣扎了。任何公司只要
清醒,就会认识到用C++来做项目简直是一场灾难。如果还没认识到这些,那就是活该
!有一段时间我使劲的劝Dennis Ritchie用C++重写UNIX。
记者: 啊?天哪!他是怎么说的?Stroustrup: 我不得不承认他的洞察力,我想他和
Brian在很早的时候就清楚的明白了
我的意图,但是从来没有说出来,他说如果我愿意的话,他可以帮我用C++写个DOS。记
者: 那么你写了吗?
Stroustrup: 事实上,我写了,我完成后可以给你一个DEMO,我在机房里的一台4个CP
U的Sparc 20上做的,运行得特别的快,而且只占了70M的硬盘空间。记者: 有For PC的
版本吗?
Stroustrup: 现在你在开玩笑了,难道你没见过Windows 95吗?我认为它是我成功标志
之一,
记者: 我也总是在想关于Unix++,还是有人在试着搞这么个东西的。Stroustrup: 那是

因为他们还没有看到这个采访手迹。
记者: 对不起,不过依我看,我们恐怕不会刊发这些东西的。Stroustrup: 但是这是个
世纪故事,我只是想让我的程序员伙伴们记住我为他们做了什
么,你知道这些个日子里C++程序员可以挣多少钱吗?记者: 我所听说的是一个顶尖的
C++程序员一小时可以挣到70~80美圆。
Stroustrup: 知道了吧!而且我打赌他肯定可以挣那么多!!单步跟踪我放在C++里面
的那些gotcha,并不是容易的事了。在在项目中使用C++的所有特性即使是有经验的程
序员也会感到困惑. 事实上有时侯我也是觉得挺难受的,虽然这个特性是为我的初衷而
做的,我几乎喜欢上了这个语言。记者: 你的意思是说你以前是不喜欢的?
Stroustrup: 我是狠它的!难道你不同意它是挺笨重的吗?但是当那本书的版税源源不
断的……我想你能够明白这些。
记者: 等一下,关于参数的定义,请您一定要回答,您是否真的改良了C的指针。
Stroustrup: 呵,我也是总是想知道这个。一开始我认为我做了,但是有一天我和一个
刚开始学习C++的程序员讨论了这个问题。他说:“他从来就不知道他的变量是否被引
用了,所以我还是在使用指针,那个星号总是在提醒我。”
记者: OK,一般在这个时候我一般是说:“Thank you very much.”,但是现在用在这
里好象还是不够。Stroustrup: 答应我一定要发表。
记者: 好的,我会通知您的,但是我已经知道了我的编辑会说什么了。Stroustrup: 谁
会相信呢?你能把这盘录音带给我拷一个吗?记者: 可以。正文完
 
有英文原版的吗?
谁有,请给我发一份,谢谢!!!
liuyan_huahai@hotmail.com
 
我有。我转发了[:D]
发信人: baif (baif), 信区: programming
标 题: C++设计者:Stroustrup答记者问(转,E文)
发信站: 泰达学院 (Wed Apr 3 17:10:43 2002), 转信
BBS水木清华站∶精华区
发信人: scallion ( 清 华 一 颗 葱 ), 信区: Programming
标 题: C++ 设计者 Stroustrup 答记者问
发信站: BBS 水木清华站 (Fri Apr 3 16:49:10 1998)
从 news.lang.c++ 上摘来的一篇文章, 写得比较有趣, 就当笑话看吧
如果能耐心读完, 应该得到些启发
____________________________________________________________
On the 1st of January, 1998, Bjarne Stroustrup gave an interview
to the IEEE's 'Computer' magazine.
Naturally, the editors thought he would be giving a retrospective
view of seven years of object-oriented design, using the language
he created.


By the end of the interview, the interviewer got more than he had
bargained for and, subsequently, the editor decided to suppress its
contents, 'for the good of the industry' but, as with many of these
things, there was a leak.



Here is a complete transcript of what was was said, unedited, and
unrehearsed, so it isn't as neat as planned interviews.
You will find it interesting...
__________________________________________________________________
Interviewer: Well, it's been a few years since you changed the
world of software design, how do
es it feel, looking back?
Stroustrup: Actually, I was thinking about those days, just before
you arrived. do
you remember? Everyone was writing 'C'
and, the trouble was, they were pretty damn good at it.
Universities got pretty good at teaching it, too. They were
turning out competent - I stress the word 'competent' -
graduates at a phenomenal rate. That's what caused the
problem.
Interviewer: Problem?

Stroustrup: Yes, problem. Remember when everyone wrote Cobol?
Interviewer: Of course, I did too
Stroustrup: Well, in the begin
ning, these guys were like demi-gods.
Their salaries were high, and they were treated like royalty.
Interviewer: Those were the days, eh?
Stroustrup: Right. So what happened? IBM got sick of it, and
invested millions in training programmers, till they were a
dime a do
zen.


Interviewer: That's why I got out. Salaries dropped within a year,
to the point where being a journalist actually paid better.
Stroustrup: Exactly. Well, the same happened with 'C' programmers.
Interviewer: I see, but what's the point?
Stroustrup: Well, one day, when I was sitting in my office, I
thought of this little scheme, which would redress the
balance a little. I thought 'I wonder what would happen, if
there were a language so complicated, so difficult to learn,
that nobody would ever be able to swamp the market with
programmers? Actually, I got some of the ideas from X10,
you know, X windows. That was such a bitch of a graphics
system, that it only just ran on those Sun 3/60 things.

They had all the ingredients for what I wanted. A really
ridiculously complex syntax, obscure functions, and
pseudo-OO structure. Even now, nobody writes raw X-windows
code. Motif is the only way to go if you want to retain
your sanity.
Interviewer: You're kidding...?
Stroustrup: Not a bit of it. In fact, there was another problem.
Unix was written in 'C', which meant that any 'C' programmer
could very easily become a systems programmer. Remember
what a mainframe systems programmer used to earn?


Interviewer: You bet I do
, that's what I used to do
.
Stroustrup: OK, so this new language had to divorce itself from
Unix, by hiding all the system calls that bound the two
together so nicely. This would enable guys who only knew
about do
S to earn a decent living too.
Interviewer: I do
n't believe you said that...
Stroustrup: Well, it's been long enough, now, and I believe most
people have figured out for themselves that C++ is a waste
of time but, I must say, it's taken them a lot longer than I
thought it would.

Interviewer: So how exactly did you do
it?
Stroustrup: It was only supposed to be a joke, I never thought
people would take the book seriously. Anyone with half a
brain can see that object-oriented programming is
counter-intuitive, illogical and inefficient.
Interviewer: What?
Stroustrup: And as for 're-useable code' - when did you ever hear
of a company re-using its code?
Interviewer: Well, never, actually, but...
Stroustrup: There you are then
. Mind you, a few tried, in the
early days. There was this Oregon company - Mentor
Graphics, I think they were called - really caught a cold


trying to rewrite everything in C++ in about '90 or '91. I
felt sorry for them really, but I thought people would learn
from their mistakes.

Interviewer: Obviously, they didn't?
Stroustrup: Not in the slightest. Trouble is, most companies
hush-up all their major blunders, and explaining a $30
million loss to the shareholders would have been difficult.

Give them their due, though, they made it work in the end.
Interviewer: They did? Well, there you are then
, it proves O-O works.

Stroustrup: Well, almost. The executable was so huge, it took
five minutes to load, on an HP workstation, with 128MB of
RAM. then
it ran like treacle. Actually, I thought this
would be a major stumbling-block, and I'd get found out
within a week, but nobody cared. Sun and HP were only too
glad to sell enormously powerful boxes, with huge resources
just to run trivial programs. You know, when we had our
first C++ compiler, at AT&T, I compiled 'Hello World', and
couldn't believe the size of the executable. 2.1MB
Interviewer: What? Well, compilers have come a long way, since then
.
Stroustrup: They have? Try it on the latest version of g++ - you
won't get much change out of half a megabyte. Also, there


are several quite recent examples for you, from all over the
world. British Telecom had a major disaster on their hands
but, luckily, managed to scrap the whole thing and start
again. They were luckier than Australian Telecom. Now I
he do
wn and worked on a C++ project? Here's what happens:

First, I've put in enough pitfalls to make sure that only
the most trivial projects will work first time. Take
operator overloading. At the end of the project, almost
every module has it, usually, because guys feel they really
should do
it, as it was in their training course. The same
operator then
means something totally different in every
module. Try pulling that lot together, when you have a
hundred or so modules. And as for data hiding. God, I
sometimes can't help laughing when I hear about the problems
companies have making their modules talk to each other. I
think the word 'synergistic' was specially invented to twist
the knife in a project manager's ribs.
Interviewer: I have to say, I'm begin
ning to be quite appalled at
all this. You say you did it to raise programmers'
salaries? That's obscene.
Stroustrup: Not really. Everyone has a choice. I didn't expect
the thing to get so much out of hand. Anyway, I basically


succeeded. C++ is dying off now, but programmers still get
high salaries - especially those poor devils who have to
maintain all this crap. You do
realise, it's impossible to

maintain a large C++ software module if you didn't actually
write it?
Interviewer: How come?
Stroustrup: You are out of touch, aren't you? Remember the typedef?
Interviewer: Yes, of course.
Stroustrup: Remember how long it took to grope through the header
files only to find that 'RoofRaised' was a do
uble precision
number? Well, imagine how long it takes to find all the
implicit typedefs in all the Classes in a major project.
Interviewer: So how do
you reckon you've succeeded?
Stroustrup: Remember the length of the average-sized 'C' project?
About 6 months. Not nearly long enough for a guy with a
wife and kids to earn enough to have a decent standard of
living. Take the same project, design it in C++ and what do
you get? I'll tell you. One to two years. Isn't that
great? All that job security, just through one mistake of
judgement. And another thing. The universities haven't
been teaching 'C' for such a long time, there's now a
shortage of decent 'C' programmers. Especially those who


know anything about Unix systems programming. How many guys

would know what to do
with 'malloc', when they've used 'new'
all these years - and never bothered to check the return
code. In fact, most C++ programmers throw away their return
codes. Whatever happened to good ol' '-1'? At least you
knew you had an error, without bogging the thing do
wn in all
that 'throw' 'catch' 'try' stuff.
Interviewer: But, surely, inheritance do
es save a lot of time?
Stroustrup: do
es it? Have you ever noticed the differenc computer ro
om. Goes like a rocket on 4 CPU's, and only
takes up 70 megs of disk.
Interviewer: What's it like on a PC?
Stroustrup: Now you're kidding. Haven't you ever seen Windows '95?
I think of that as my biggest success. Nearly blew the game
before I was ready, though.
Interviewer: You know, that idea of a Unix++ has really got me
thinking. Somewhere out there, there's a guy going to try it.
Stroustrup: Not after they read this interview.
Interviewer: I'm sorry, but I do
n't see us being able to publish
any of this.
Stroustrup: But it's the story of the century. I only want to be
remembered by my fellow programmers, for what I've do
ne for



them. You know how much a C++ guy can get these days?
Interviewer: Last I heard, a really top guy is worth $70 - $80 an
hour.
Stroustrup: See? And I bet he earns it. Keeping track of all the
gotchas I put into C++ is no easy job. And, as I said
before, every C++ programmer feels bound by some mystic
promise to use every damn element of the language on every
project. Actually, that really annoys me sometimes, even
though it serves my original purpose. I almost like the
language after all this time.
Interviewer: You mean you didn't before?
Stroustrup: Hated it. It even looks clumsy, do
n't you agree? But

when the book royalties started to come in... well, you get
the picture.
Interviewer: Just a minute. What about references? You must
admit, you improved on 'C' pointers.
Stroustrup: Hmm. I've always wondered about that. Originally, I
thought I had. then
, one day I was discussing this with a
guy who'd written C++ from the begin
ning. He said he could
never remember whether his variables were referenced or

little asterisk always reminded him.


much' but it hardly seems adequate.
Stroustrup: Promise me you'll publish this. My conscience is
getting the better of me these days.
Interviewer: I'll let you know, but I think I know what my editor
will say.
Stroustrup: Who'd believe it anyway? Although, can you send me a
copy of that tape?
Interviewer: I can do
that.
 
在MS的统治下,C/C++以及其它语言已经失去了移植性。
 
不见得吧,M$控制的是VC;找你这么说BCB也没有移植性啊!
M$控制不了 ASNI C ,所以C还是有很强大的生命力!
好文!收藏!
 
你把VC或BCB或Delphi写的程序可以移植到其它操作系统吗?相信这不是件容易的事,
事实上就如C#一样,现在的开发工具越来越针对具体平台了。
 
后退
顶部