Is C ++ too complex?
Sometimes I read Habr. And when I noticed the post
http://habrahabr.ru/blogs/cpp/111403/ , I honestly admit that he touched me to the quick. I have been using C ++ as the main language for many years. Once again I honestly admit: I don’t know it completely. Hardly I could create something like Boost :: MPL, Boost :: Spirit or Boost :: Xpressive. But is this a reason to talk about the complexity of the language? Yes, the C ++ standard is twice as large as the C # standard. But look at the content:
http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf and
http://www.open-std.org/jtc1/sc22/wg21/docs /papers/2007/n2461.pdf . The difference is noticeable? I suggest that for completeness of use, the C # language lacks very much of what is part of .NET. In general, C ++ can also be used without STL and even without the run-time part at all. In his youth, even the OS began to write where the loader was in assembler, and everything else in C ++. The fact that STL is included in the standard and described in detail, in contrast to .NET, is a big plus for the C ++ language and a big minus for C #. That is why, although I look with a little bit of envy at the news about C #, I do not plan to use it. My main OS is Linux and the Mono project does not seem to me to be a solution to the problem with .NET.
Any programming language is complicated until you find time to deal with it. Or does someone think that there are ideal full-fledged languages ​​with a full description on 10 pages and absolutely no pitfalls? I have not heard of such. But for many years I heard that C ++ is already dead or slowly dying, tips to bypass its corpse side. All sorts of ratings show that in the first place we have Java, or C #. But you will look at the contents of the hard disk, where is most of the software in Java or C #? Yes, Java and C # themselves are written in C ++ (well, at least that was the case before).
What I hate C.
Immediately I clarify that my hatred originates from the time of C89. As soon as I looked at this language, I immediately realized that I hate it. Especially here such constructions:
void main(argc, argv) int argc; char **argv; { ... }
')
Why repeat the arguments twice? Or function declarations just like
func()
, what arguments does it take? It is clear that any and returns int, but what about the type control? And you have to look for the implementation to find out the type of arguments. Only when I change the implementation, I may not know about it, which will lead to indefinite behavior.
I still have to work with code inherited from C. It’s just a bunch of buffer overflows and leaks. Often you come across an error and you are not wondering, and how has it worked so far? “C ++ bydlokod does not tolerate,” correctly. But C for some reason, on the contrary contributes to its writing. More precisely, for some reason, the reasons are clear: there are no links (which are safer than pointers), there is no type safety (solid
void *
) ... a lot of things are not. And the fact that there is, only contributes to errors: strcat, printf, gets ... There is no RAII, no garbage collection, and from here a lot of leaks. Over the years, I have accumulated a huge number of arguments against the C language, and I rarely use it so much that now I don’t even remember everything.
But I do not suggest writing drivers and OS kernels in C ++. Of course, C fits better. Probably, for small libraries and utilities, the C language is also a more suitable choice than C ++. But for a medium or large project being developed by ordinary hired programmers, choosing C as the language is hardly a good idea. Who might need to translate at least a hundred thousand lines into an assembler? And millions? If someone likes this idea, the more C ++ is the best choice, there will be much more of this assembly code :–)
Advantages of C ++ over C:
- Greater safety
- Ability to write generic code using templates
- Ability to use object-oriented approach
- Resource Management with RAII
- Simplify code by overloading functions and operators
- Easier error handling due to exceptions
- C ++ 11!
- ...
It only remains to use these advantages correctly. For example, do not use exceptions as a
goto
substitute, do not overload the operator comma, etc.
Disadvantages:
- Long compilation
- Larger generated machine code
Long compilation becomes a problem only in case of incorrect approach to header files (when everything that exists is uncontrollably thrust into them) or when using libraries like Boost :: Xpressive. For example, a rather large Qt project on my machine (2 years old, 4 cores, 8GB of RAM) is completely reassembled in just 15 minutes. Well, the volume ... the necessary sacrifice.
What I hate java for.
I honestly tried to use programs written in Java. Many times and over the years. But almost none of them could work normally. For example, the well-known Eclipse program of sample 2008 in the Windows version as IDE for C ++. It did not start using eclipse.exe. I do not remember what was there for the error, but refused to work. Only if you run it with eclipse
c .exe, which left the console window, which is tolerable. But after a while this method stopped working. Got on the forums, found the secret actions for the eclipse.ini file and it all worked! But not for long. First, running eclipse.exe stopped working, and then eclipse
c .exe. Again I had to find a way to start it. It turned out that it is desirable to immediately specify the workspace at startup. Made a .bat file. But this was not enough for a long time. Perhaps the problem was that the project contained several million lines of code ... but in my opinion, this is not a reason to behave this way.
The most annoying thing is that in all cases eclipse issued a call stack in Java and closed it. No imputed error message. And even more unpleasant, that practically all programs written in Java did this!
The second long history was with the AS2 server (
http://en.wikipedia.org/wiki/AS2 ). It was in the form of an application for Apache Tomcat. Back then, I didn’t know how Java programmers like to torture people with XML files and considered it to be an acceptable format. But I don’t think so anymore, and I hate XML as well as Java. So, after installing the server, he refused to start and wrote all the same incomprehensible call stacks to the log. Corrected java.policy and java.security, found the necessary files local_policy.jar and US_export_policy.jar, started working. But not always, from time to time he continued to write stacks instead of working. In the end, came to the conclusion that it is easier to write your server. Would do it earlier, save a lot of time.
Java programs are slow and consume a lot of memory. Not all, and certainly not most, but many of those I have tested. At the same time I enjoy using programs in python or ruby ​​and do not feel any inconvenience. And now the
incomprehensible behavior of Oracle .
And I also hate C ++
Love and hate at the same time. For a heavy legacy in the form of C. For a long compilation. For a lot of ambiguities, not all of which are inherited from C. For having to wait C ++ 11 for so long. For the monstrous designs that have to create. For the lack of the word
finality
. For the lack of introspection. For multiple inheritance and the absence of impurities. For differences in different compilers and OS ... Yes, he has flaws. They are everywhere. But in my domain, in most cases, the advantages of C ++ outweigh. And most importantly, it does not conflict at all with interpreted languages ​​like JavaScript, Ruby, Python ... and it gets along quite peacefully.
And what do I love?
GW-Basic. First love is for life.