C++ is a horrible language. It's made more horrible by the fact that a lot of substandard programmers use it, to the point where it's much much easier to generate total and utter crap with it. Quite frankly, even if the choice of C were to do *nothing* but keep the C++ programmers out, that in itself would be a huge reason to use C.
Source is here. Many of you will recognize these words: it's a piece of Linus Torvalds' rant aganist C++, when some developers asked him to move Git from C to C++.
At the time I laughed satisfied at that, because I prefered for a long time C's semplicity, few keywords and easy concepts. I mean: when, in C++ should you use a struct rather than a class1? And after years developing in C++ I can confirm that it is a really complex language. If you want to have fun, this thread on Stack Overflow will explain something really interesting about the internals of C++14.
Is really that difficult?
I recently saw a video where Scott Meyers talks on a conference about the new (for the time) standard, C++14. It's a nice video and I totally suggest it. Expecially for what he says at 36:58.
(Courtesy of YouTube, Christian Semmler channel)
vector...and a BAD one.v(100000); for (auto& c : v) c = ~c;
vectorGuess what? They do the same. But the first is more readable than the second one. Why somebody should choose to write that way a fragment that can be way more easier to read? Probably to gain some speed and that's what I will talk about now.v(100000); for (size_t i = 0; i < v.size(); i += sizeof(uint64_t)) { uint64_t& quad_word = *reinterpret_cast (&v[i]); quad_word = ~quad_word; }
[C++ is] made more horrible by the fact that a lot of substandard programmers use it
C++ difficulties are caused by many developers approaching a problem the wrong way. In the name of abstraction and efficiency, they create mountains of overcomplex, unreadable code. Sure, not all of them, but if you're a professional C++ developer, you surely met the crazy colleagues (ab)using pointers math, ternary operator or templates metaprogramming.And maybe you even admire them!
So let's face it! If your code is unclear it's because:
- You're abstracting too much;
- You're doing premature optimization;
- You're using feature of the C language that were usefull when compilers were inefficient (the '80s);
And, sorry to say that, but doing this kind of errors, is what makes what Mr. Torvalds calls a substandard programmer.
So, what's really difficult about C++ is knowing how to do stuff the right way.
Conclusions
I wanted to end this post with a checklist, suggesting how to improve your C++ code. But I found a better rule of thumb, simple and clear.We could talk also optimization, but I think that is enough material for another post.
2 comments:
What a nice article! I loved it. You make me think of an old colleague of mine. He was very entertaining, knew to create a story around a topic to make people understand the problem. He was also an horrible person
Continue your good work dude
Maybe it is the problem of the C++ because it is too difficult to understand and that is why developers cannot make clear, readable codes.
Maybe I am wrong, because I only coded in Matlab :)
Post a Comment