Bjarne stroustrup lecture on C ++

Source: Internet
Author: User

If you want to know the details, you can go to the wg21 website to view the paper. Here are scattered notes.

Today, Bjarne stroustrup went to the company to give a lecture on C ++ 0x generic programming. Adhering to the principle of not eating eggs, you can also look at the hen. I took a seat in the front row 20 minutes in advance-although we say that in addition to the compiler department and database department, we use C ++, I still can't underestimate the curiosity of this group of bosses. Despite the psychological preparations, everyone was shocked by their enthusiasm: at the beginning of the lecture, the Hall of more than 300 people was basically full. There is no opening remarks. Bjarne directly cut the topic and sing the praise of the template: The template is flexible, universal, and has good time and space performance. It is widely used in the construction of modern c ++ class libraries and the construction of high-performance C ++ class libraries, metadata programming. Then there is an excessive problem with the class library. The first is the compilation error message of the enemy. The template compilation check is performed after extension, and the error information is always huge and complicated and hard to understand. If you have compiled list <int> list; sort (list. Begin (), list. End () with G ++, you must remember the error information of 2 K bytes. Second, overloading is not easy to use. Third, many abuse all sorts of tricks and write fancy but fragile code. Bjarne said that many bosses would say "Great!" when they saw the template! Improved macros. Then we started to mess up. Fragile code is a response to their attitude. However, users should not be connected. Third, the code is very difficult to understand. Fourth, the code is lengthy in some places. In Bjarne's words, we should not write more code than what we want to express. However, it seems that C ++ has been criticized. Bjarne thinks the crux of the template problem is that we didn't provide enough information to the compiler. The compiler does not know what to check when extending the template code. Naturally, it cannot provide appropriate error messages or support simple overloading. Therefore, one of the goals of C ++ 0x is to support rich types of information in generic programming. So that the compiler can ignore some of the correctness checks to increase the intensity of optimization, further optimize the already awesome template system, and make the program easy to maintain, not only the MIT pH. D ). Then we started to talk about concepts. Concepts is actually like Java interfaces or Haskell's type classes. In the past, we had to use <typename T>, but with the concept, we can limit the T range without a bunch of traits code. For example, the mintemplate <typename T> const T & min (const T & X, const T & Y) {return x <Y? X: Y;} is converted into template <lessthancomparable T> const T & min (const T & X, const T & Y) {return x <Y? X: Y;} and this lessthancomparable is defined as auto concept lessthancomaprable <typename T> {bool operator <(t, t );}; so that C ++ has the duck typing function during compilation: No matter what a class is, as long as the compiler says it implements the walk (), quack (), it's just a duck. Of course, the function of concept is far more than defining the function signature. It can also limit various operations such as constructors, operators, member function template, and deference. In addition, the acceptable types of classes can be defined, and the Axiom keyword can be used to set the invariant. In Bjarne's example, axiom is used to limit an operator of a semi-group to meet the Union law. It's really geeky to the extreme. In addition, different concepts can be combined, and even a concept is mapped to another concept through the so-called concept map, greatly reducing the amount of code. Bjarne specifically emphasizes that concept is not the same as Haskell's type class or Java/C # generics. It lists three differences. The most important thing is that concepts does not have a hierarchical structure as Java or type class does. Second, the Concept implementation does not require indirect function calls. Finally, concepts can perfectly support the original data type without the need for auto boxing. One example is that concepts can be used to easily describe arrays with fixed lengths on the stack, but Java or type class won't. However, I am surprised that Java does not have an array on the stack. Why should I use this example. Unfortunately, I forgot to ask. Finally, Bjarne said that the whole STL would be rewritten with concepts. After concepts, we will discuss some relatively small changes, such as initializer for syntactic consent. Interestingly, the same {} syntax can be used for struct initialization. There is also the type auto keyword for automatic inference. Bjarne said that he had come up with this stuff in 83 years, and now he has finally successfully joined C ++. In addition, <t, my_alloc <t> can be correctly parsed. spaces are not required between the two> so that they can be distinguished by the same displacement symbol. Finally, we talk about the semantics of R-value, move (), and typedecl. However, I was distracted and did not write any notes. The Question Time is interesting. First, someone asked about the details of R-value. Bjarne says he cannot answer without slides because there are too many details. I had a private smile. I knew I 'd show you pongba's masterpiece. A boss asked Bjarne which part of C ++ he most wanted to change if he had the opportunity to come back. Bjarne replied very resolutely: Insane syntax. The following burst into laughter. Then someone threw out the killer question: do you use VI or Emacs? Naturally, the flowers and branches are trembling. As a result, Bjarne said that he had vowed not to use these two editors 20 years ago. He uses an editor named korsan (sound, not clearly understood), including copy, paste, cut, and find. It is more primitive than notepad. Bjarne said that his pursuit of perfection is simple. I don't agree with that. However, Bjarne mainly writes pictures in front of the whiteboard and occasionally uses the editor without such fancy features. In addition, the pursuit of Ultimate simplicity of the boss to develop C ++, is also a strange life. Finally, someone asked him about the preferred language except C ++/C. Bjarne boss said simula67 and algo 68. However, he added that apart from C ++, which is a common language, there are too many other excellent languages. He also liked some functional programming languages. However, without saying anything, he never jumps to Haskell or ocaml. Everyone laughed. Scattered. After people are scattered, a new moon is like water. No, it was afternoon. The day is right. I'm just a pseudo-wenqing.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.