📜 ⬆️ ⬇️

About hatred for C ++

C ++ or not C ++ , C ++ or Java / Python / Ruby? How often do you ask or hear such questions? I would not like to raise another holivar - in my opinion, smart people would have long ago come to the conclusion that when choosing a language there is no silver bullet that would put an end to it, - each language has its pros and cons and most often the problems in laying between the keyboard and the chair.



I myself program in C ++ , because the tasks to be solved require a fairly good data processing speed. On one of the thematic blogs I met an emotional article in defense of C ++ . They even liked the comments more than the article - they collected the whole bunch of arguments against C ++ , which is rarely found in one place. And most importantly, the author is trying to fend off attacks - just a duel of some kind . All that is written there can be used both by C ++ evangelists and his opponents of the language.
')
I took the liberty of translating the article and a couple of comments to it.

But before you read, please look at the beautiful map of C ++ (The C ++ Lands). Special thanks for the card to Alyona Sagalaeva:







I had a chance to read interesting on TechRepublic. well written, but completely inaccurate and provocative article. This writing is one of those that are trying to predict the death of C ++ and the victory of other, less powerful, languages. I, as a C ++ developer who loves this language with all its skeletons in the closet, can say that the appearance of such articles is a bad sign and a sign of the ignorance of technical bloggers.

I will not go into details - if you are interested, the original can be found by reference . I will analyze only the passage to which I can not respond.

We can assume that the days of C ++ are numbered. The alternative that is most suitable for solving similar problems is Objective-C . Another option is Objective Caml, a language that is regularly cited as an example for high-performance tasks and is often ahead of C ++ in some indicators. It can be written briefly and structured, provides developers with more understandable and interesting models, which are sometimes absent in languages ​​of the same level. D can also be called a competitor, although its proprietary roots can prevent its widespread use. Google’s Go language has many controversial compromises, but without a doubt its capabilities offer a great advantage when creating some type of software, including concurrency.

However, based on the lessons of history, C ++ will occupy its niche for a long time. It has been used for years in developing operating systems. Without controversy, C ++ provides some advantages over C for some types of systems where performance is critical and there are already developments. But the strength of such developments is accompanied by their developers, who ignore alternatives, and this is a feature that is not easily possible to circumvent the potential competitors.
potential competitors.



Just as there is yellow journalism, I would call this article a good example of yellow blogism. The material in it is sensational and emotional, but the facts on which they are based are not disclosed. If you read the full article, you will see that it is filled up with anecdotes, on the basis of which they are trying to draw a conclusion about the death of C ++ . But in the end, the author actually gives up and recognizes that C ++ will still be used for some time.

Let's see what he actually says in the article and try to read between the lines.

We can assume that the days of C ++ are numbered. The alternative that is most suitable for solving similar problems is Objective-C .


Unfortunately, the author did not specify which tasks are meant. He gave an example of browsers. So let's take a closer look at this.

It is said that there are many alternatives to C ++ for the development of browsers, high-performance programs, desktop applications and high-loaded server systems. Let's list a few successful products on the market that are written in C ++ and explain why C ++ was chosen.



I give you the opportunity to name at least one other programming language that allows you to write programs like these and provide the same level of functionality, stability, extensibility, portability. Before you call C, I want to remind you that C is a subset of C ++ , and if you mean pure C, then good luck and wish you not to go crazy if you do not use the abstractions that C ++ provides.

Another option is Objective Caml, a language that is regularly cited as an example for high-performance tasks and is often ahead of C ++ in some indicators. It can be written briefly and structured, provides developers with more understandable and interesting models, which are sometimes absent in languages ​​of the same level.


Do you really think that C ++ is only an object-oriented language and nothing more? The power of C ++ is not only in supporting object-oriented programming - the fact is that in C ++ you can use many different paradigms that make the language powerful enough. Now about the tests. Everyone should understand that micro tests are designed to test only one aspect of the system. Real tests are those that test the system in real conditions.

If we talk about high-performance code, then the compiler used plays a big role, not the high-level language used. This is true for all compiled languages. It can easily be said that one language is better than another, if the tools of the first are better than those of the second, but in reality, the product's performance is more dependent on several things - hardware, compilers, and code. One of the main reasons for the poor performance of some programs is bad code. For example, when an algorithm is chosen without considering the real situation, the input data, ... If you compare bubble sorting in C ++ and bitwise sorting in OCaml, then perhaps the OCaml program will be faster.

Speaking of aesthetics, this is a matter of taste. A poem written in French will not be beautiful for me, because I do not read / speak / write in French - and it doesn’t matter how beautiful it is for another person. The same is true for C ++ - I saw (and I hope I wrote) great C ++ code , but a Java or C programmer will probably have a different opinion, since they don’t know the language like me.

Most of the questions about efficiency and professionalism are connected not only with technical features, but also with those knowledge and their exchange between developers. You cannot say that you are a professional in C ++ unless your colleagues confirm it.

Some may think that reading a book on C ++ will give you the right to consider yourself a professional, but also, as is the case with other languages, professionalism and efficiency come only with experience.

Language D can also compete, although its proprietaryity may prevent its widespread use. Google's Go language contains many controversial compromises, but no doubt its designs provide a great advantage when creating some type of software, including concurrency.


Quoting John Dvorak - “It's all nonsense.”

If you believe that proprietaryity can interfere with widespread use, then take a look at Java, which has become the new Cobol in the business world. Think of the x86 assembler - it is also proprietary. There are many closed programming languages ​​that are widely used, proprietaryity is not a hindrance: what really matters is the technical side. Hackers who choose only those tools that will be used. If you want to sell me a mousetrap, then it should be good enough for me to decide to spend money on it.

As for parallelism, the real problem is that most programmers do not know how to write effective parallel programs. Here is the snag. And it does not matter what language is used. The lack of knowledge in the subject, machine architectures, patterns of various data access, combined with resource constraints, is what makes parallel programming “difficult”. Even when Erlang or Go is mentioned, it is still not effective to write applications when you do it incorrectly and do not use idioms and templates for parallel programs.

However, based on the lessons of history, C ++ will occupy its niche for a long time. It has been used for years in the development of operating systems. Without controversy, C ++ provides some advantages over C for some types of systems where performance is critical and there are already developments. But the strength of such developments is accompanied by their developers, who ignore alternatives, and this is a feature that is not easily possible to circumvent the potential competitors.
potential competitors.


B again - all this garbage .

Developers using C ++ every day do not live in a vacuum. We know about Ruby, Python, Haskell, Lisp, JavaScript, Java and even such newfangled languages ​​like Erlang, Go, Lua , etc. The reason why organizations use C ++ to create good C ++ applications is That C ++ works and allows you to do things that other small languages ​​can do. I will be the first to admit that C ++ is not so productive when you need to work with tasks for which Lisp is intended, but so that you know, using modern C ++ features such as metaprogramming on templates, you can solve these problems.

In addition, Lisp is not designed to create high-performance programs, at least until you configure these programs for a load that you might encounter.

Conclusion

I look at the number of words in the article - there are about 2000. This kind of hatred for C ++ kindles me and makes me defend myself, but let me look into the future. The reason why I consider C ++ powerful tools is not only that I spent on studying and using it a lot of time. This is far from true, there is another reason - I have achieved a lot by starting to use C ++ .

I heard a lot of criticism of C ++ from different people. CEO, HR managers, developers, business partners and even C ++ programmers. But the reason why C ++ is standardized by ISO, the reason why the application market in this language thrives is its design limitation - it so happened that the language was designed with the best and accidentally caught bad parts of past languages ​​to represent a multi-faceted tool for creating good applications. There is a lot that can be done with ++ , a lot more that can be done in other languages.

If there is one criticism towards C ++ , then this is his misunderstanding. If everyone spends the same amount of time studying it as Ruby / Python / JavaScript, then I’m sure it will change the way you think about the language. There are many good books about C ++ - one of them is Programming: Principles and Practice using C ++ . Before knocking on C ++ again, read this book and tell about the weaknesses of C ++ - and it will be normal if you thank me later.

About the author Dean Michael Berris:

I am a programmer by profession, specializing in the development of high-performance network applications in C ++ . I read a lot, write and discuss what is close to me. I am especially interested in developments in parallel programming and high-performance systems, especially those built in C ++ .



A couple of critical comments on the article and answers to them.
Programming in C ++ is very easy to fall into the traps. It is difficult to program on it, because many things are simply hidden from the developer by the compiler (for example, the compiler creates a default copy constructor, and if it was not explicitly created, this leads to byte-by-byte copying of pointers and can lead to crashes in the program. Even a program that most of the time it works fine, it can carry an error of improper use of a remote pointer. It is very difficult to program in C ++ when deadlines are tight and, especially, when newcomers are present in the team.

C ++ has far fewer supported libraries than, for example, in Java. This means that every time you have to implement simple things that already exist in other languages.

Very large platform dependency. It takes a lot of effort to port from Unix to Windows and back.

C ++ can be used for academic projects where language flexibility is important and there is enough time to bring the program to an ideal form.



It is like calling a hammer a good but dangerous tool when you do not know how to use it.

But look at C ++ from the side where it works directly with iron. You also talk about “basic things”, but not every language has a clear idea that there is a “basic thing”. In C ++, the base is memory allocation, memory tools (pointers), types (classes, structures, primitive types), objects of these types (objects of the first class), control structures and functions, such syntactic structures as namespaces, modifiers types, and all those tools for creating modules and libraries.

If you do not like working with low-level tools, then teach STL, use Boost, learn Loki or ACE. If you do not understand what pointers are, you cannot even use C in real programs and you will not achieve anything from C ++ .
For C ++, there are many libraries for different things. You can also use already written C libraries.

I'm not sure that you use C ++ in work projects and it is a shame to hear attacks from you by those who use C ++ for a long time. But I suppose that if you think that there are fewer libraries for C ++ than for Java, you are not surprised by what C ++ is “a useful tool for academic development.”

If you are comparing C ++ with a hammer, then there are at least 5 different devices and attachments to it and it is unclear which one to choose. Choosing the wrong, you beat off his hands. Yes, if you choose the right one, you can work faster, but what is the probability of choosing the right hammer?

C ++ has been one of my tools for over 10 years. I participated in large projects and some of them are still in use. However, there were many projects that stopped even before their completion - they went beyond the allotted time and budget. After that, the java team of programmers implemented the same functionality for 2 weeks and without significant bugs. Even the performance of the java version was higher ( since ++ the code was not optimized).

I have seen experienced programmers make stupid mistakes that are so easy to make, but hard to find in C ++ .

Porting code from unix to windows is a complete nightmare. Fancy designs with templates have a great chance not to be compiled on another platform.

Porting from windows to unix is ​​also not sugar.

STL is good and makes programming easier and the library is supported by all compilers. It provides a lot of “basic things”, such as the containers we need to implement business logic. But besides good design and handy stuff, her error messages are terrible. STL can vary slightly across platforms, which can lead to problems when porting.
We use the ACE / TAO framework, but there were also problems with it on the windows platform, although it is claimed that the library is platform-independent.

We are testing how Boost can be used in our projects.

The problem is that we already have 3 different frameworks (2 of them are internal development), which are already in use and cannot be simply replaced by another without rewriting a large amount of code - the budget does not allow us. Writing the 4th will lead to even more confusion (the problem is not connected with ++ , but with the unpredictable complexity of adding functionality and the growing time for refactoring code)

Every language has its good and bad sides. It is very important to choose the right one for the project.

Although C ++ provides enough flexibility compared to other languages, it is not a tool for tasks where development speed is needed.


Sorry, but the tool you described has nothing to do with a hammer.
The fact that development in C ++ is more expensive says more about the team than about the programming language, doesn’t it? I'm not sure about what type of software you are talking about, but if we are talking about a network application (I understood it by using ACE / TAO), then I don’t see where problems may arise. Knowing ACE and professionally using it earlier, I am sure that you quickly implement the required functionality, since this is a ready-made framework.

When you talk about stupid mistakes, in fact it depends on the person writing the code. I wrote a client to memcache from scratch in 1 week using the modern C ++ style, and the library is still used in the place where I wrote it (hint: search by the keyword memcache ++). I rewrote the server from scratch in two months, I used it for testing and improvements for 1 month, despite the fact that it worked alone - the server can handle about 5k requests per second (RPS), while using no more than 60% CPU and average load 2: 1 for CPU. And it's hard for me to understand why many people have difficulty with ++ when I manage to do such things.

I am sure that I am not the only one who has the same positive experience.

Porting to another platform is only a matter of using standard language constructs. It also implies the use of abstractions that hide platform-specific things from the programmer. Write libraries and at the same time think about how it will be supported.

If we talk about error messages, it is the responsibility of the compiler. Agreed, GCC is terrible in this regard. But other compilers can infer diagnostics better than GCC - I mean clang - it should fire soon. MSVC 10 can also give good messages.

About your project, I have to say that you should hire an expert who knows what to do in this situation. Hire BoostPro and train your team to use modern C ++ approaches, rather than those that were a decade ago.

I know the good and bad sides of C ++ , and they have nothing to do with the problems of the person who is programming on it. If you need fast development, then you need to improve your processes and learn the tools used. I sincerely doubt that there is a programming language that can prevent someone from quickly prototyping.

Source: https://habr.com/ru/post/111199/


All Articles