When I learned the C ++ language, I found that there are so many tricks in C ++. In fact, there are few tricks used in daily programming, unless you are the library designer, otherwise, many tricks do not need to be concerned at all. Maybe C ++ has gradually peaked in the development industry in recent years.
Let's define "academic school" first, OK? First, ask yourself a question. What is your definition of "academic school? The following are some options: 1. tends to be theoretical. 2. Ignore constraints in actual encoding (such as efficiency, readability, and so on ).
3. Advocate the behavior of language lawyers. 4. Drill details. 5 .... I think if I say that C ++ language design emphasizes the beauty of theory, I'm afraid everyone who has learned C ++ will laugh... As Bjarne himself said, one of the Rule of Thumb in the early stage of C ++ design is "do not fall into the stubborn pursuit of perfection"; but it is ironic that, later, you will see that such a philosophy has brought about the misunderstanding of C ++ today.
I guess most people holding such a point of view have vague definitions of academic schools, it is generally between "practices that advocate drilling language details and taking advantage of language details", "Focusing on language features and ignoring actual coding needs", and "endless debate on language details.
Therefore, when someone says "C ++ = academic school", his true meaning is likely to be: "There are too many dark corners in the C ++ language, in addition, the C ++ community also advocates the potential philosophy of grasping the language corner. Even the evolution of C ++ 0x seems to be more concerned with language features, those language features are basically out of touch with our actual developers ..." And so on.
The first thing to admit is that in the last ten years, the C ++ community has indeed established a mentality of over-paying attention to language details to some extent, this kind of mentality is undoubtedly wrong, but it can be solved only by knowing how the mistake came from.
In addition, even if you cannot solve this problem at the moment, you can maintain a rational and tolerant attitude after knowing the cause, rather than making complaints. A rational attitude is more conducive to sound development. For example, if the C ++ community can understand where this kind of latent philosophy came from, it may gradually develop better.
Is C ++ missing? Yes. The for_each algorithm of STL, So you write: struct MyOp {void operator () (int & I ){...}}; Std: for_each (v. begin (), v. end (), MyOp (); this solution is actually very poor. First, you have to write v. begin () and v. end (). Second, You have to define a new class for this purpose.
Third, this new class is not at the point where you use this new class (for_each is called), because partial classes cannot be used as template parameters. What you want is lambda function: for_each (v. begin (), v. end (), <> (int & I ){...}); But C ++ 98 does not. What you need is the built-in foreach: for (int & I: v ){...} But C ++ 98 does not.
Since the loop structure is one of the most common structures in programming. This problem is actually quite annoying. If you think it is not annoying, it may be because you are used to it. This is not necessarily a good thing. For example, writing std: vector: iterator every time is annoying. If I change a container, I need to modify a bunch of std: vector <…>. Why not use typedef? Line.
I still need to write typedef once. I am very lazy and don't want to write any unnecessary code. You need to know that every row of code that is useless (not required to express your thoughts) increases the maintenance burden. This is why language expressiveness is so important. What should we do? If I tell you, you can write foreach (int & I, v) {…} in C ++ 98 ){...} What do you think? Nonsense. Of course, it is impossible. No one wants to use this simple expression.
Another fact I need to tell you is. In order to achieve this feature almost perfectly in C ++ 98, some people have dug the standard corner. No, I am not looking for reasons for drilling language details. I just want to tell you that many people think that the drilling language details are mostly driven by users' actual needs at the beginning.
This foreach facility has been attempted by C ++ programmers to implement N times and N times, which shows a strong demand. Unfortunately, the vast majority of implementations are far from easy to use. Even the authors of this implementation have developed an implementation on CUJ as early as 03 years ago, which is not easy to use.
It was later that the final easy-to-use version was achieved with perseverance. What I want to say is that the beautiful foreach above, of course everyone wants to use it. But the problem is that C ++ 98 can only be implemented by standards. This is the only way.
- Who is more powerful in C ++ and C?
- How to better compile C ++ code
- Introduction to how to implement shared memory in the C ++ standard library
- C ++ code implementation ControlTemplate
- Analysis of Visual C ++ application implementation methods
Otherwise, you have to wait for language evolution and endure for several years. Who would like? Besides, this foreach facility can also be used as a placeholder to fulfill its responsibilities before the arrival of C ++ 09. After adding the built-in foreach support to C ++ 09, we only need to use regular expressions to search for global replacement, it will be OK, without any upgrade troubles.
Another typical example is the traits in STL. In fact, traits should not be a traits. The most natural Implementation Method of traits should be C ++ 09 concept. But STL needs the static dispatch technology. What should I do? Either use traits (Increasing Language complexity) or not (apparently not ). Another typical example is template metaprogramming. What is the use of template metaprogramming? Daily developers will not be able to use it in eight lifetime. But is it true? Yes, it is not directly used by daily developers.
But what about the various boost sub-libraries supported by template meta-programming? What about the sub-databases of TR1 selected in C ++ language (used indirectly )? What about the daily developer's meta-programming without learning templates? You don't have to learn. What is this complicated technology? That is, something skillful. Why do people learn this? Wait. There are also a lot of examples.
In fact, STL's traits technology can already explain the problem. If you take a closer look, you will find that the so-called technology that uses the dark corner of C ++ almost appears in the library development, and the reason why it appears in the library development, this is because the library development needs to be driven-in order to develop a better library. Don't you want to use a better library? Oh, when it comes to "better databases", some people will certainly have their opinions.