Reasons to Love C ++
C ++ is too complicated?
Sometimes I read a habr. And when I noticed the post http://habrahabr.ru/blogs/cpp/111403/ , I honestly admit, he touched me for a living. I have been using C ++ as a core language for many years. Once again, I honestly admit: I do not know him completely. It is unlikely that 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 ++ language standard is two times larger than 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. Is the difference noticeable? I suggest that for the full use of the C # language, a lot of what is part of .NET is missing. In fact, C ++ can also be used without STL and even without the run-time part in general. 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 is described in detail, unlike .NET, is a big plus for C ++ and a big minus for C #. That is why, although I look with a 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 without pitfalls? I have not heard of such. But for many years I hear that C ++ is already dead or slowly dying, there are tips to bypass his corpse. All sorts of ratings show that in the first place we have either Java or C #. But you look at the contents of the hard drive, 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).
For what I hate C.
I immediately specify that my hatred dates back to the time of C89. As soon as I looked at this language, I immediately realized that I hate it. Especially these designs:
void main(argc, argv)
int argc;
char **argv;
{
...
}
Why repeat the arguments twice? Or function declarations are just like
func(), what arguments does it take? It is clear that any returns int, but what about type control? And you have to look for an implementation to figure out the type of arguments. Only when changing the implementation, I may not know about it, which will lead to undefined behavior. I still have to work with code inherited from C. This is just a bunch of buffer overflows and leaks. You often come across a mistake and are perplexed, and how has it worked so far? “C ++ doesn’t tolerate code,” right. But C for some reason, on the contrary contributes to its writing. More precisely, not 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, there are a lot of leaks from here. Over the years, I have accumulated a huge number of arguments against the C language, and for so rarely I use it that now I can’t even remember everything. But I do not propose writing C ++ drivers and OS kernels. Of course, C is better for this. For small libraries and utilities, C is probably also a better choice than C ++. But for a medium or large project 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 assembler? And millions? If someone likes this idea, all the more C ++ is the best choice, there will be much more of this assembler code :–)
Advantages of C ++ over C:
- Great security
- Ability to write generic code using templates
- Ability to use an object oriented approach
- Resource Management with RAII
- Code simplification by overloading functions and operators
- Easier error handling through exceptions
- C ++ 11!
- ...
It remains only to use these advantages correctly. For example, do not use exceptions as a replacement
goto, do not overload the comma operator, etc. Disadvantages:
- Long compilation
- Larger generated machine code
A long compilation becomes a problem only if the header files are incorrectly accessed (when everything they have is uncontrollably popped into them) or when using libraries like Boost :: Xpressive. For example, the rather big Qt project on my machine (2 years ago, 4 cores, 8GB of RAM) is completely rebuilt in just 15 minutes. But volume ... a necessary sacrifice.
For what I hate Java.
I honestly tried to use programs written in Java. Many times and over many years. But practically none of them could work normally. For example, the famous Eclipse program of the 2008 model in the Windows version as an IDE for C ++. Using eclipse.exe it did not start. I don’t remember what the mistake was there, but I refused to work. Only if you run using eclipse c .exe, which left the console window, which is tolerable. But after a while, this method also stopped working. I climbed into the forums, found secret actions for the eclipse.ini file and it worked! But not for long. At first, starting eclipse.exe stopped working, then eclipse c.exe. Again I had to look for a way to start it. It turned out that it is advisable to immediately specify the workspace at startup. Made a .bat file. But this was not enough for long. 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 worst part is that in all cases, eclipse popped up a call stack in Java and closed. Not a single sane error message. And even more unpleasant that almost all programs written in Java did this!
The second long story was with AS2 server ( http://en.wikipedia.org/wiki/AS2) It was in the form of an application for Apache Tomcat. Then I did not yet know how Java programmers like to torment people with XML files and considered it a perfectly acceptable format. But I don’t think so anymore, and I hate XML as much as Java. So, after installing the server, he refused to start and wrote to the log all the same incomprehensible call stacks. Corrected java.policy and java.security, looked for 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 work. As a result, they came to the conclusion that it is easier to write your server. I would do it earlier, save a lot of time.
Java programs run slowly and consume a lot of memory. Not all and certainly not the majority, 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 C ++ I hate too
I love and hate at the same time. For a heavy legacy in the form of C. For a long compilation. For many ambiguities, not all of which are inherited from C. For the fact that it took so long to wait for C ++ 11. For the monstrous designs that have to be created. For the lack of a 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 area, in most cases, the benefits of C ++ outweigh. And most importantly, it does not conflict with interpreted languages at all like JavaScript, Ruby, Python ... but it gets along quite peacefully with them.What do I love?
GW-Basic. First love is for life.