2012/01/31

[Book review] Advanced C++ Programming Styles and Idioms

Advanced C++ Programming Styles and Idioms    C++ プログラミングの筋と定石



今回は私がC++の世界にはまった最初の書籍について紹介します。

C++で最も有名な書籍といえば Scott Meyers氏のEffective C++ だと思いますが、
初めてEffective C++を読んだ時には、文章ばかりであまりピンと来ませんでした。
そもそも自分の C++及びオブジェクト指向に対する不勉強のためだったと思います。

そういう状況で見つけたのが本書籍でした。US Amazonのレビューで見つけて、邦訳本が
あることを知らなかったので、洋書で購入して読みました。遠回りしてしまった感もある
にはあるのですが、実際に邦訳本を立ち読みしてみましたが、分かりにくいというか
頭にしっくり入ってこない部分もあったので、時間は掛かったけど洋書で読んで正解だった
かなという風にも思っています。

驚くことにこの本の出版日はなんと 1991年だそうです。もう20年以上も前のこと。著者
の James O. Coplienは 「C++の設計と進化」によると C++の最初のユーザー(正確には
Cfront)だったということですが、その時点でここまで深堀りできているという点に驚き
です。

当然古い出版のため、新しい言語仕様に対する記載(例えば templateや namespaceなど)に
関する説明はなかったり、一部現行仕様と相容れない記述もあるかと思いますが、非常に
参考になるテクニックが記載されています。

しかしながら、この本の多くの技巧のアプローチは、C++の強力なタイプシステムを
いくらか柔軟にして利用するために、Polymorphismを多用したものとなっています。
現在のオブジェクト指向プログラミングでは、なんでもかんでも共通のベースクラスから
派生させるようなスタイルはあまり採用しないと思います。紹介されているテクニック
そのものはプロダクトコードに用いずに、そのテクニックのエッセンスを自身の
プログラミングに利用するというのが良いかと思います。

この書籍では「イディオム」という形で、テクニックやコンセプトに名前を付け、その
コンパクトに名付けられた「イディオム」で、プログラマーが共通認識を持って
ソフトウェアの生産性を上げることを狙っていたものと思われます。この流れが、その後
の「デザインパターン」といったムーブメントへ繋がっていったんでしょうね。

Scott Meyersの More Effective C++では参考文献として、本書は LSD本として紹介
されています。洋書のカバーの色合いと、紹介されている技巧から LSDとは・・・なるほど
言い得て妙だなと感じました。




This time let me introduce a book on C++ programming language which took me into
the deep world of C++.

I wonder the world-most-famous book on C++ should be "Effective C++" by Scott
Meyers. However, when I first read the book, I had a feeling that I didn't fully
understand what the book tries to address very well. I must admit that it was due to
my lack of well-understanding of the language as well as sort of lengthy text in that
book.

In such situation, I found this book. Since I didn't know that Japanese translation was
also available at that moment, I bought English version by checking US Amazon
review. When I realized that Japanese version was available, it is true that I felt like I
went a long way around. However, when I browsed the Japanese version in a
bookstore, I found some portion seems not so intuitive. Now I wonder it deserves
reading English version even if it takes me some more time to complete it.

I was surprised that the publication date was in 1991 - more than 20 years before.
The author James O. Coplien was said to be the first user of C++ (to be precise,
Cfront) according to the book 'Design and Evolution of C++'. Anyway, I'm quite
surprised that he has deeply investigated into that much even in this early stage of
C++.

As this is quite old book, there are some of missing portions in terms of rather
new language specification such as template, namespace etc.. and also you may
find something which is not aligned with the current C++ specification. But it is also
true that it contains a lot of techniques which are very helpful.

However, many of the techniques introduced in this book are sort of one-sided.
I mean they often adopt polymorphism, attempting to lessen the benefit of C++
strong type system to get some more flexibility. I don't think that present way of
doing object-oriented programming is like creating inheritance hierarchy among
almost all the objects from a single commonal base class. It would be better not to
make use of the code technique shown in this book into production code as it is.
Instead, we can make better use of those essences into our daily programming.

In this book, it names various techniques and concepts in the form of 'idioms'.
I believe that those idioms are aimed to be widely shared among programmers
in order to get common understanding via such compact names, which helps to
improve our software productivity and quality etc.. and I also believe this idea must
have had something to do with the later 'design pattern' movement.

In famous book 'More Effective C++' by Scott Meyers, this book was introduced as
'LSD' book. Now I can relate to, from the coloring adapted by the book cover and
its various techniques introduced in this book.


0 件のコメント:

コメントを投稿