Actually, I disagree quite strongly with this. Start writing applications using STL and boost immediately (or in your case, the STL plus the Symbian APIs).
Both libraries have enough quirks that it takes a significant
amount of time and experience to use them correctly. For
example, you don't need the std::vector or std::list
containers. Simply allocate a sufficiently large array to hold
your items, then allocate a larger array when the first one
fills up.
This is how we ended up with so much crappy C++ code in the 90s.
sigh. Yes, you do need std::vector and std::list. Those are the very first two data structures you should learn. If you're using int[] instead of std::vector<int>, there'd better be a good reason. Similarly if you're using char * instead of std::string. Learn to use iterators, and learn to use <algorithm>. Don't be afraid of streams, either. I think doing it any other way is just wasting time and making it harder to actually become proficient in C++, rather than just using the C++ compiler to give you C with a tiny bit of syntactic sugar.
IMHO, it's much better to learn the ins and outs of STL as you use it, not by putting off using it until you master it all (what kind of logic is that, anyway?). I.e., it's way better to start off using a std::vector exactly as you would an array and learn it as you go than to put off using std::vector entirely until you understand the default allocator and operator overloading.
You can't use an std::vector exactly as you would an array. There are quirks to every STL container, and it is easy to get burned once per quirk. Here is an example:
// create a list of numbers.
static const int kNumNumbers = 10;
int numbers[ kNumNumbers ];
for( int i = 0; i < kNumNumbers; ++i )
numbers[ i ] = i;
// do something useful with those numbers.
...
// zero-out the list.
memset( numbers, 0, sizeof( int ) * kNumNumbers );
... versus ...
// create a list of numbers.
std::vector< int > numbers;
for( int i = 0; i < 10; ++i )
numbers.push_back( i );
// do something useful with those numbers.
...
// zero-out the list.
memset( &numbers, 0, sizeof( int ) * numbers.size() );
The second example is evil. Can you spot the bug?
My point was, kashif wanted to be productive in C++ within a month. It is not reasonable to expect him to become familiar with all of the STL and Boost quirks within a month. He has a better chance of accomplishing something by using C++ as C plus constructors than by using C++ as a high-level language. The latter requires expertise and a large time investment.
static const int kNumNumbers = 10;
std::vector<int> numbers(kNumNumbers);
for (int i=0; i<kNumNumbers; ++i)
numbers[i] = i; // no .push_back necessary
// do something interesting
numbers.clear();
In your example (aside from the memset), you use .push_back(), and only use the defaults for std::vector, both of which aren't what you're doing with int[].
In my example, the only difference is that numbers is initialized with a () instead of [].
As for the call to memset(), looking at the documentation for API to see that you empty the vector with
std::vector<>::clear()
is not getting "burned by quirks". That's how you go about becoming productive in C++, which is what he wants. Also, getting burned by memset()-ing an object is not a quirk of the STL.
In general, what I'm not arguing is that he should use the entire STL right away. Of course you'll get burned by doing stupid stuff that you'll later realize is stupid. What you're arguing is to avoid the STL alltogether, and instead write C in a file with ".cpp" at the end, which is equally bad (because it's not productive C++).
The way to go is to put into practice the bits and pieces of the STL that you can right away. std::vector and std::list are the simplest containers, the fastest to learn, and the most commonly used, so he should start there. Once he discovers iterators, allocators, and <algorithm> (oh my!), he will wake up one day and realize that he now understands a large chunk of the expressiveness of C++.
It isn't possible to use a vector exactly as an array, and my example was an illustration of time that is spent getting used to the differences. The consensus seems to be that native arrays are bug-prone. However, using STL without sufficient knowledge is far more bug prone. Also, your example clears the vector (resets its size to zero) whereas mine sets each number inside the array to zero.
You're not getting the point. He is asking what will be an efficient way to learn to be productive in C++. If he follows your advice, he may be less bug-prone (doubtful, but maybe) in the beginning, but he also won't be learning C++. Instead of learning the ins and outs of a library that he will have to learn to achieve productiveness, he'll be learning the ins and outs of how sloppy your C can be and still get by the compiler, which isn't productive.
If learning C++ is the goal (and he stated it so), then he should use C++, which is how he will get the "sufficient knowledge" you seem to see as a roadblock.
And by the way...it's long since past time that we stopped calling it the STL. It's been a standard for plenty long enough that we should all be calling it the standard library.
I don't use a lot of STL, and I'm productive. Neither does John Carmack or John Ratcliff, and the word "productive" doesn't capture just how much they accomplish.
I'd like to ask, are you understanding my point? An amount of open-mindedness is required. Common wisdom has been proven incorrect time and time again throughout history, and the common wisdom of C++ that "you need to use STL containers and Boost to be productive" is incorrect.
You are trying too hard to make a point that people don't agree with. You don't need STL/Boost to be a productive c++ programmer. That's fine, no arguments there. But you don't have to avoid STL/Boost in order to be a productive/efficient c++ programmer either. Get over it.
Quoting Stroustrup from his 2007 History of Programming Languages paper:
'Alex named his containers, iterators, and algorithm library
“the STL”. Usually, that’s considered an acronym for
“Standard Template Library”. However, the library existed
—with that name—long before it was any kind of standard
and most parts of the standard library rely on templates. Wits have suggested “STepanov and Lee” as an alternative explanation, but let’s give Alex the final word: “ ‘STL’ stands for ‘STL’ ”. As in many other cases, an acronym has taken on a life of its own.'
sigh. Yes, you do need std::vector and std::list. Those are the very first two data structures you should learn. If you're using int[] instead of std::vector<int>, there'd better be a good reason. Similarly if you're using char * instead of std::string. Learn to use iterators, and learn to use <algorithm>. Don't be afraid of streams, either. I think doing it any other way is just wasting time and making it harder to actually become proficient in C++, rather than just using the C++ compiler to give you C with a tiny bit of syntactic sugar.
IMHO, it's much better to learn the ins and outs of STL as you use it, not by putting off using it until you master it all (what kind of logic is that, anyway?). I.e., it's way better to start off using a std::vector exactly as you would an array and learn it as you go than to put off using std::vector entirely until you understand the default allocator and operator overloading.