I had to do some text processing and I wanted to learn sed & awk so I picked this book that is, to my knowledge, the only book completely dedicated to these tools. The chapter on 'advanced' sed programming is very scary because when using 'advanced' sed features, the syntax is cryptic. It is nice to know that these features are there but I want to stay away from them and perhaps use awk or perl for the tasks that would require those 'advanced' features. Still, when you stick with the 'basic' and 'intermediate' sed features, you can do cool things easily in shell scripts.
Overall, the book was not thrilling to read but it does a good job to teach you these text processing tools.
By having read the 3 books in the serie, I must say that this is my favorite because it has really answered a lot of small questions I had for a long time about several aspects of C++.
The only thing that I have disliked is that Mr. Sutter has contradicted himself with one of the advice that he was giving in the first book. The advice was to not write an assignment operator in terms of its copy constructor with the in place new operator and the explicit destructor and I did agree with the reasoning. Now in this book, it is written that is ok to use that idiom if and if and if and he goes for about a paragraph to describe the condition where it is ok to use the pattern. I can imagine that the author had to admit that there might be exceptional situation where it is ok to use that technique in a heated debate but my opinion is that out of context, he should not have mention that it might be ok to use that technique without devoting an entire item on that topic. It did just confuse me and I had to reread the item in the first book to convince me that there was effectively a contradiction between the 2 books and that it was not just my memory playing games with me.
Mr. Sutter's books biggest strength to my opinion is that they bring together a bunch of original advanced C++ topics that you cannot find anywhere else. This book has its share of very original content but I feel like the ratio original content vs topics that you can find in other books is lower in this book than with the other books of the serie. The most interesting section in this book in my opinion is the one on exception safety and the less original section is the one on generic programming and STL as you can find much of the information contained in this section in other books such as Effective STL from Scott Meyer or C++ Template from David Vandervoorde and Nicolai M. Josuttis.
In item 24 of the book Effective STL, Scott Meyers explains to be careful about using the overloaded subscript operator (std::map::operator[]
) when efficiency is important. The reason behind this advice being that when that operator is used to refer to an item that is not yet in the container, it will insert a new pair in the map by using the default constructor of the value part and then usually an assignation will be performed on the value reference returned by the operator. For non-trivial constructors and assignment operators, this can result to unnecessary overhead.
He then proceeds to present a function called efficientAddOrUpdate()
that calls std::map::lower_bound()
then performs some tests on the returned iterator to make sure that it is not equal to end()
iterator and if the key pointed by the iterator is equivalent to the key used with lower_bound()
. If the test is successful, then the value pointed by the iterator is updated or else std::map::insert()
is called with the std::map::lower_bound()
returned iterator as hint for the insertion point.
Few days ago, I had to recreate the efficientAddOrUpdate()
function without my copy of Efficient STL book available and I have being struggling for a good half an hour to an hour trying to recall the implementation details or find them back by doing searches on the Internet. I have finally come to the following realization by giving up searching the Internet and looking at the <map>
header file source code:
Scott Meyers efficientAddOrUpdate() function code is almost identical to the operator[] member source code function minus minor modifications
Here is the source code operator[]:
mapped_type& operator[](const key_type& _Keyval) { // find element matching _Keyval or // insert with default mapped iterator _Where = this->lower_bound(_Keyval); if (_Where == this->end() || this->comp(_Keyval, this->_Key(_Where._Mynode()))) _Where = this->insert(_Where, value_type(_Keyval, mapped_type())); return ((*_Where).second); }
and efficientAddOrUpdate()
code derived from it would be:
iterator efficientAddOrUpdate(map &m, const key_type& _Keyval,const val_type& _Val) { iterator _Where = m.lower_bound(_Keyval); if (_Where == m.end() || m.key_comp()(_Keyval, _Where->first))) { return m.insert(_Where,value_type(_Keyval, _Val)); } else { _Where->second = _Val; return _Where; } }
This book presents advices more or less in the same format than books from the Effective C++ serie. What is similar is that topics are divided in 47 small items of few pages each. The difference is that the author first ask questions to the readers or propose exercises and encourage the reader to put down the book and to take the time to think about the problem and then come back to read his answer. This format is more or less original as I have seen something similar in Tom Cargill's C++ Programming Style book.
I have read this book pretty fast which is a good sign of my interest in a book but in the same time this book did not leave me, at first, a strong impression that will make me remember this reading for a long time. It is hard for me to say exactly why but I think that it is because most items focus on very small details of C++. Some of these problems are very hard and probably is an indication that the book targeted audience is advanced C++ users which is not a bad thing by itself but I was not convinced that mastering these small details actually has a high impact on someone programming skills.
It took few months to let the wisdom contained in this book to sink in and I have found myself many times, in my day to day programming, confronted to problems where the material of this book helped to make wise design decisions. So now, I think that this book is very valuable for anyone that has mastered the C++ programming language and is ready to master tougher C++ issues.
I want you to find in this blog informations about C++ programming that I had a hard time to find in the first place on the web.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
<< < | > >> | |||||
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |