We've now completed 5 articles in the "Nobody Understands C++" series so here we are going to recap the misconceptions we have covered.
On occasion you will read or hear someone talking about C++ templates causing code bloat. I was thinking about it the other day and thought to myself, "self, if the code does exactly the same thing then the compiled code cannot really be any bigger, can it?"
Here are the test cases presented, first without the use of templates, second with the use of templates. Exactly the same functionality and exactly the same code output:
Standard Algorithms
Few C++ developers seem to appreciate that the standard C++ library is actually designed around functional programming principles. The standard library headers algorithm and functional header files provide functional algorithms and facilitate their use, respectively.
As usual we will try to provide a simple example of why we should put to use the functional techniques in the standard library.
C++ templates is a huge topic that we will not fully cover here. While we have covered templates in the past, this article will cover the very basics and the reasons why we would want to use templates.
A simple case of why you would want to understand templates is wrapped up in a question I used to ask when I would interview C++ developer candidates, "write for me a max() function which can compare any two values of the same type."
Understanding RAII is critical to understanding good C++ design.
RAII stands for "Resource Acquisition Is Initialization." The basic idea is that an object fully manages all of its own resources.
Understanding object lifetime is critical to understanding RAII. For the purposes of this article we will only be discussing objects created on the stack, not on the heap. That is, objects not created with "new."
There are just a couple of simple rules to understanding lifetime:
This is going to be the first post of several, though I'm not sure how many just yet. The title of the post should be self explanatory, but I will elaborate. It is my strongly held belief that C++ is generally poorly understood and gets a bad rap because of this. It is also my belief that this is NOT the fault of C++, but rather the fault of old-school C++ developers who learned the language before the language was ratified in 1998.
Recent comments
3 days 20 hours ago
3 days 22 hours ago
3 days 22 hours ago
6 days 23 hours ago
1 week 5 min ago
1 week 3 days ago
2 weeks 3 days ago
5 weeks 3 days ago
7 weeks 55 min ago
8 weeks 2 days ago