Bjarne Stroustrup on the Evolution of Languages

Interview++
Bjarne Stroustrup on the Evolution of Languages
Howard Dierking

Every once in a while, an evolutionary leap rapidly advances and reshapes the entire field of engineering. Such a leap occurred in software development with the introduction of the C++ programming language. This leap was not inherent in the language itself: object-oriented languages such as Simula67 and Smalltalk existed prior to C++. But because C++ was built on top of the C programming language (and could compile existing C programs), it was able to bring the abstractions of object-oriented thinking into the mainstream.
C++ has inspired a great deal of thought surrounding software design and development, from design patterns to meta-programming. And because of its portability among hardware platforms and its lower-level expressiveness, C++ will assuredly be essential in a world of faster, smaller hardware.
I recently had the pleasure of talking to Bjarne Stroustrup, the creator of C++, about a host of topics, from his thoughts on languages to general industry trends to his own personal reading list. Many of the questions asked were suggested by readers via my blog, so thanks to everyone who contributed questions. And of course, thanks to Bjarne.

Thoughts on Language
Howard Dierking Why do programming languages connect with people on such a deep level—such that communities of language zealots form?
Bjarne Stroustrup You should ask a psychologist, a sociologist, or maybe even an economist, rather than a computer scientist! My guess is that the languages we use to express our ideas become a part of ourselves so that if you know only one language, proponents of other languages could appear personally threatening. In that case, the solution seems to be to know more languages well. I don't think you can be a professional in the software field knowing only one programming language. There may also be an economic reason: while fundamental understanding transcends programming language boundaries, many practical skills don't. So if I know only language X and its tool sets, and you argue for language Y and its toolsets, you are threatening my livelihood. Again, the solution seems to be to know several languages and toolsets (and to be solid on fundamentals). Unfortunately, my suggested solutions do not take into account that most people have very little time left after doing all that they feel necessary just to manage. That's no excuse for zealotry, though.
HD What should be the role of the IDE in software development? How should the IDE support a language?
BS I'm not a heavy IDE user. I appreciate a responsive IDE editor with understanding of my language, but I also want to be able to work without an IDE. I might have a different opinion if a good IDE was universally available—in reality a part of the language or vice versa (see Figure 1). My desire for portability of code plays a role here. With C++, I want to be able to understand my system from just the source code in the source files. I actively dislike IDE mechanisms that involve transformations or generation that cannot be represented as code fit for human consumption.
Figure 1  The IDE Designer as a Language (Click the image for a larger view)
HD Do you see noise or readability as a problem in today's general purpose languages? If so, what is the solution?
BS A simpler syntax would be nice, but I suspect that what most people grumble about when they talk about readability is not so much the actual text as the complexity of what is being expressed. Too many people expect to walk up to any program written in any language and—with only a bit of help from an online support facility—understand all the constructs used to express the program and all the logic of the program itself. Compare that to the way we look at natural languages and use them. Would you expect to understand a Shakespearean sonnet without background information? How about Beowulf in the original Old English? Maybe we expect too much from our programming languages. Any language that can express all that is needed for a wide range of application areas could be considered unnecessarily complex for any given application, but it must cope with an essentially unbounded set of applications. Domain-specific languages can help in specific cases, but now we have to deal with the complexities of many languages and their interactions.
HD How should a general-purpose language support application design ideas such as component programming and service programming?
BS A general-purpose language should support the writing of libraries that express general and application-specific notions, support tool building, and provide the glue needed to connect different parts of an application. For that, the language needs flexibility, an expressive type system, good basic performance, and long-term stability.
HD Is multiple dispatch a good thing?
BS Yes. A conventional single-dispatch object-oriented programming language (such as Simula, C++, Smalltalk, Java, and C#) cannot elegantly express simple operations, such as multiplying numbers or finding the intersection of two shapes, where the exact types are not known until run time. The resulting code (relying on double dispatch, the visitor pattern, and so on) is slow and not as maintainable as we'd like. Languages that support multiple dispatch at run time (like Dylan and CLOS) do better and languages (such as C++) that support it at compile time can sometimes help a bit. Last year, together with some of my students, I published a research paper on how to cleanly add multiple dispatch to C++. The resulting code for multiple dispatch use-cases is shorter, simpler, uses less memory, and runs faster than all workarounds we have seen (see Figure 2). That work came too late for C++0x, though. You can find a paper about that at research.att.com/~bs/multimethods.pdf.
Figure 2  Multiple Dispatch via Multiple Inheritance (Click the image for a larger view)
HD What are your thoughts on covariance/contravariance in C++ today? Do you expect the current behavior to change in future language versions?
BS Not really. In that area, I think C++ does what it should. Are you thinking about examples such as converting a vector<Apple> to a vector<Fruit>? That's terribly unsafe unless the vector<Fruit> is immutable (or you could add an Orange to it). I don't think implicit run-time type checking is a good approach to such problems.
HD What are your thoughts on making message passing a key language feature, as opposed to method calling?
BS I like explicit message passing, but I have only used it a long time ago and in the context of distributed systems. Realistically, for that to work on a large scale, we'd have to do some serious work on language and tool support for message passing. I don't think that has been done, but I could be wrong. Lots of problems associated with sharing and locking go away if you rely on messages and message queues. I'd love to see a standard C++ library for that, and I just might get it (in a couple of years).
HD Is there an inherent conflict for general-purpose languages in simultaneously supporting a broad, diverse audience and encouraging improvements in code expressiveness and design elegance? What is the role of the language in supporting the latter?
BS I guess there is in the sense that you can approach elegance through specialization. Also, if you have a small audience (user community), you can cater to its tastes (only) and it is possible to depart from conventional notations and concepts if you somehow control your user community (saying something like "you need to read up on type theory to use this"). A general-purpose language is constrained not only by the need to support a wide variety of uses, but also by the need to be teachable to large groups of people with a variety of assumptions and educational backgrounds (the basics have to be usable by a high-school student with a poor teacher).
So I think a general-purpose language can encourage elegance as long as elegant code can be expressed in it. In the case of C++, very elegant code can be written. By being part of a general-purpose language and widely available, such examples can get into the hands of millions and into articles and textbooks that can be read by millions. No specialized language—however elegant—has those options.
HD Have we placed too much emphasis on architecture?
BS No, at least not the way I would define architecture. On the contrary, there is too little emphasis on architecture and too much poor coding with little understanding of structural principles. I suspect a major problem with architecture is that many programmers have only a vague idea of what makes good code good. Being able to recognize it when you see it is not enough. Having rules for what not to do is not enough. We need articulated prescriptive rules.
HD Has the open source community helped, hurt, or made no difference in software quality, design, and professionalism?
BS That's a really hard question. I have seen cases where it helped (increased the quality of code and the degree of professionalism of people involved), cases where it hurt (taught really bad habits and attitudes), and many cases where I couldn't tell.
I have no way of guessing what the effects on the community at large have been or what would have happened had the degree of open source work been greater or lesser. The community is simply too large for me to guess.

Language Trends
HD Do you see a serious shift towards dynamic languages in the near future?
BS Not really. I think people are comparing apples and oranges too often. I don't think we have a choice between static and dynamic languages in general and furthermore I don't think languages cleanly fit into those two categories: most if not all dynamic languages have aspects that are statically determined, and all the major static languages can do things that require run-time determination of the meaning of values. There are fashions, of course, and I can't guess about those, but I think that many real-world language choices are rationally made based on the requirements of an application, an application area, and/or the skills of the available developers. For example, I'd not try to implement a Java runtime in (say) Ruby or express a heavily interactive simulation language as C++ (as opposed to its implementation).
HD Would you see it as a good thing to ultimately remove all existence of void*/variant/object/etc? ( Figure 3 shows a good example.)
Copy Code
STDMETHODIMP 
CoCalc::QueryInterface(REFIID riid, void** ppv)
{
   if (riid == IID_IFirst || riid == IID_IUnknown)
    *ppv = static_cast<IFirst*>(this);
  else if (riid == IID_ISecond)
    *ppv = static_cast<ISecond>(this);
  else
  {
    *ppv = 0;
    return E_NOINTERFACE;
  }
  AddRef();
  return S_OK;
}
BS I guess that in principle it would be a good idea to get rid of all the catchall options, but in reality we could achieve that only by having a full classification of everything we wanted to express so that we could always be more specific. For example, I have never seen a real function that could do something to every object; if you do something, you always make some assumption about what you are manipulating (a pure forwarding function is the closest I can think of as a counter example). The current work on concepts in the C++ world (constraints/requirements on generic algorithms) will be a help here, but I don't see us being able to do without some truly general mechanism for expressing "something, but I really don't know what" for dealing with unanticipated needs.
HD With the trend shifting back to loosely typed languages, should we start considering Hungarian notation again?
BS I'm not sure that there is such a trend, though there probably is an increase in the fraction of the total work that is suitable for loosely typed languages. In other words, the use of statically typed languages could still be growing (I think so) while the use of loosely typed languages is growing faster. And no, don't use Hungarian. Hungarian is an awful idea. The source code should reflect the meaning of a program, not simulate a type system. If you really, really feel the need for Hungarian, you are probably using a language that is unsuitable for your application.
HD In 2000 you gave a presentation called "C++: A New Language for a New Millennium" and introduced the concept of a Wrap<T>. This is basically aspect-oriented programming (AOP). What do you think of AOP (generally) and its formalization of the Wrap<T> pattern (pointcuts, advice, and so on)?
BS I haven't spent enough time on AOP to give a solid answer. I like composition (especially non-intrusive) to be supported in a language (as opposed to both "not supported" and "supported by a tool"). I worry about extra-linguistic tools and about non-standard tool chains. C++ templates have been amazingly successful at non-intrusive composition—just look at the Standard Template Library (STL) and some of the uses in embedded systems programming. It is a real strength to be able to combine ideas without forcing them into a rigid or predesigned hierarchy. However, it has also been hard to manage for some developers and some maintainers. It is also notationally heavy. C++0x contains attempts to address that without flexibility or performance hits.
HD Certain characteristics of the C++ language have the potential to create some nasty unintended consequences (such as macros). What are some other unintended consequences that you would like to see disambiguated in C++ or modern languages in general?
BS Actually, I knew macros were nasty when I started using C; but like most people, I underestimated their nastiness and pervasive negative influences. The pervasive use of macros in C is probably the major reason we didn't have excellent C++ development environments a decade ago. There are also too many, too confusing ways of initializing objects in C++; I hope to address that with a uniform mechanism in C++0x. I mentioned templates in my answer to the previous question. They are the major success in later C++ (post 1985), but their success has strained the language—again, parts of C++0x are intended to deal with that.
Many minor and not-so-minor problems we have discovered over the years cannot be addressed in C++ for compatibility reasons. For example, the declarator syntax is an unnecessary complication—just about any linear notation would be better. Similarly, many defaults are wrong: constructors should not be conversions by default, names should not by default be accessible from other source files, and so on. Not controlling the linker has been a constant source of problems; in particular, implementers seem to delight in providing similar features in incompatible forms.
There have also been positive surprises. The most spectacular has been the pervasive use of destructors in techniques relating to resource management and error handling (using exceptions). I knew destructors were a good idea—after all, you have to reverse the effect of a constructor—but I didn't realize quite how central they would be to good use of C++.
HD You commented on your Web site, "I think we should look for elegance in the applications built, rather than in the languages themselves." Is the move toward domain specific languages (DSLs) a convergence of these?
BS Yes, almost certainly. It is often an attempt in that direction. Sometimes, it even works.
HD What are your thoughts on DSLs in general? What do you envision as the relationship between DSLs and general-purpose languages?
BS I worry about the number of languages being designed, implemented, introduced with great fanfare, and then fading away without significant impact. During this—typically many-years long phase of development—a new language consumes significant resources with essentially no returns. I wrote a paper on this phenomenon called "A Rationale for Semantically Enhanced Library Languages" ( research.att.com/~bs/SELLrationale.pdf). I argue for using libraries, possibly supported by tools, and a general-purpose language.
I think that a DSL should be a last resort, not a first. If at all possible, the DSL should be firmly rooted in a general-purpose language and standard tool chains. A DSL needs a general-purpose language (or at least a systems programming language) for its implementation and the implementation of its run-time primitives. I think it would be best if a DSL is consciously and firmly paired with at least one general-purpose language so that it is easy to add new facilities through the use of libraries written in that general-purpose language. Obviously, a professional should master several languages, but I do wonder if the sum of complexity of a variety of DSLs couldn't become so high that it became a problem. Also, many (if not most) DSLs seem to "want to" become general-purpose languages.
HD You mentioned that many constructs in the C++ were intentionally left ambiguous due to varied definitions on different hardware. Do you see advancements in interoperability that could disambiguate some of these constructs?
BS "Ambiguous" is the wrong word. Far too many things have been left undefined or implementation-defined. I suspect that if I could redefine C++ from scratch it would have no undefined behaviors and far fewer implementation-defined ones. However, I don't have a time machine and we just cannot break hundreds of millions of lines of code by picking a set of resolutions today.

Methodology and Best Practices
HD What process methodology do you tend to use and teach?
BS Identify key application concepts, identify useful libraries, build new libraries in support of the application concept, try out ideas early, integrate early, test early and often, use documentation and tutorial material as design tools, and grow larger programs from smaller ones (iterating along the way). It should be obvious that I'm focusing on relatively small projects just now.
HD Do you see an intersection or affinity between a language and a development methodology?
BS I think so, as far as library design is seen as a design/development technique. Focusing on increasingly higher-level (closer to the application) facilities through library building places requirements on the language. I wouldn't overstate this point, but I don't think you could have a single development methodology for (say) COBOL, C, Java, C++, and Python and expect to gain more than the minimal support from each language.
HD What are some of your personal rules of thumb when creating software?
BS Focus on key concepts; focus on their interfaces; focus on the management of resources (memory, files, locks, and so on); focus on error handling. The design of good invariants for classes and Resource Acquisition Is Initialization (RAII) are key techniques.
HD There's a lot of buzz around being agile. What does "agile" mean to you? Does C++ support agile?
BS I don't use the word; it's much too vague. Of course C++ supports agile—whatever that means.

Looking toward the Future
HD How can a language evolve to support advanced features such as templates, dynamic events, and self-writing code, and at the same time remain accessible to new entrants?
BS I don't know. I don't think there is a general answer. New features can be important as far as they support more effective techniques in the context of a language. However, stability is essential: one of the reasons for the continuing strength of C and C++ is the care taken by the standards committees for old (often decades old) code to remain valid and for the integration of new features to be smooth. This is not easy, to say the least, and the introduction of new features doesn't always succeed. Too often, the concerns of novices are ignored by the standards committee members. Some of the key features planned for C++0x, such as uniform initialization, the auto keyword (for deducing a variable type from its initializer), and concepts such as checking of template argument requirements should serve to make the language easier to use by nonexperts.
HD Do you see language metadata as a key foundation for future programming languages?
BS No. I personally feel most uncomfortable with nontrivial uses of metadata.
HD Do you see a fundamental shift in the future for concurrency if CPUs begin ramping up the number of cores? How might the concurrency challenge be addressed in C++0x?
BS C++0x provides the basics: a machine model suitable for multithreading, a set of low-level primitives for library building, and a threads and locks library API. I would love to see more (and probably will over the next few years), especially a simpler, higher-level concurrency model based on thread pools, futures, and message queues. We need to find automatic or near-automatic ways of spreading a computation over many processors and localizing activities on those processors. There is lots of work in this area—much in C++—but not yet a dominant model. Examples include STAPL from Texas A&M University and TBB from Intel.
HD What are your thoughts on general-purpose computing on graphics processing units (GPGPU)?
BS Tantalizing, but I don't have the practical experience to comment beyond the obvious that it takes a lot of skill to utilize a special-purpose processor.
HD Do you foresee High-Performance Computing (HPC) ultimately becoming transparent to programmers? Moreover, would this goal be one for a language or for a library or framework?
BS Somewhat transparent, only; I don't think concurrency could or should be completely transparent. For starters, error handling can be very different depending on the availability of processors, shared (or not) memory, distribution (or not), and latency. Approximating transparency where that is appropriate is and will remain a goal for new languages, new language features, and (my favorite) new libraries. The latter is only feasible if the underlying language provides the basic guarantees needed as a machine model and a set of very low-level primitives. C++0x will do that.
HD How is the design of C++0x coming along?
BS We are near the end—finally! At least I hope so—nothing is certain until the votes are in and towards the end things can get quite tense and emotional. The current plan has us voting out the complete new standard for public comment in June, giving us a new formal standard 12 to 18 months later. Obviously, I could write a book on this one topic: how do you make a standard, what's supposed to be the guiding principles, and exactly what's in it? I almost have; see my HOPL paper "Evolving a language in and for the real world: C++ 1991-2006" (available at research.att.com/~bs/hopl-almost-final.pdf) and anything with C++0x in the title on my home pages. If you are a glutton for punishment, you can look for "WG21" on the Web and find all the ISO C++ standards committee's papers (including all the proposals). If nothing else, it will convince you that it is a lot of work. Improving a widely used programming language is hard, especially one that is at the implementation layer of many, many tools, languages, and applications. You can also find a few videos by me and others online and on my C++ page.

Books and Phones
HD What are you currently reading?
BS On technical material, I'm back to Hennessy and Patterson for a refresher on machine architecture, and I'm trying to collect papers and articles that help people write good code (for a course I'm teaching). Finding such articles is much harder than I expected; academic papers tend to be very specialized and nonacademic papers are often high on promises but short on evidence (suggestions welcome). Then, of course, there is a steady stream of documents relating to the C++ standardization. I was about to refresh my Knuth, but someone has absconded with my volume III, so that'll have to wait. For pleasure, I'm rereading a bit of O'Brian's Aubrey and Maturin series. I'm trying to refresh my understanding of science, so currently just coming off a Richard Dawkins binge. I also recently finished Rodger's Command of the Ocean: A Naval History of Britain, 1649-1815 (hence the visit to O'Brian).
HD You said "I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone." Do you have a smartphone, and has this gotten any easier?
BS I'm not a great fan of phones. I prefer face-to-face communication and the written word if I cannot get that. Even the fanciest phone is not quite up to well-phrased e-mail. I use a slim phone that fits comfortably in my pocket and I don't use anywhere near all of its features. I'd give up just about any feature for sound quality and reliability. To be fair, user interfaces tend to be much better today than when I made that remark.

Howard Dierking is the Editor-in-Chief of MSDN Magazine.

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
应用背景为变电站电力巡检,基于YOLO v4算法模型对常见电力巡检目标进行检测,并充分利用Ascend310提供的DVPP等硬件支持能力来完成流媒体的传输、处理等任务,并对系统性能做出一定的优化。.zip深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成器生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值