SHOEISHA iD

※旧SEメンバーシップ会員の方は、同じ登録情報(メールアドレス&パスワード)でログインいただけます

DeveloperZine(デベロッパージン)- エンジニアの意思決定を支える技術情報メディア ProductZine

CodeZine編集部では、現場で活躍するデベロッパーをスターにするためのカンファレンス「Developers Summit」や、エンジニアの生きざまをブーストするためのイベント「Developers Boost」など、さまざまなカンファレンスを企画・運営しています。

Bjarne Stroustrup氏との対話

C++の次期仕様「C++0x」のポイント
~Bjarne Stroustrup氏との対話~

第5回 C++国際標準化委員会による初心者への配慮

Stroustrup氏の回答: 新機能の追加で標準ライブラリはより使いやすく、高速になります

 There are a lot of compiler, tools, and language experts on the committee. Those and library builders dominate, and that's a pity. Ideally, we'd have a majority of experienced developers to help guide the work. However, the committee is not alone in its fault here. Essentially every one of those 100 proposals and maybe 200 more distinct "mere suggestions" came from people outside the committee. A member of the committee rarely just comes up with a proposal on his own. The community is the source of much of the pressure to add language features; just watch any web discussion on how to improve the language and you'll find a chorus of demands for new features together with some (often loud and unconstructive) complaints that the language is too large already.

 標準化委員会にはコンパイラー、ツール、あるいは、言語などの各分野を代表する多数のエキスパートが参加しています。彼らが委員会の主導権を握っています。これは確かに哀れむべきことです。理想的には、経験を積んだ開発者が委員会の主流を形成するべきでしょう。しかし、委員会だけを責めることはできません。提案のほとんどは、委員会外部から提出されています。各委員が提案を出すようなことはめったにありません。言語機能の追加を迫るのは、コミュニティーなのです。言語改善を論じるWebサイトを閲覧すると分かりますが、肥大化した言語への大小の(非建設的な)不満と共に、新機能を求める大合唱が湧き起こっています。

 Fortunately, most of the about 50 proposals that were accepted are so minor that most users will say something like "Huh? We couldn't do that before?" Examples are creating an alias for a template with a template argument bound and using a local type as a template argument:

 // define Vec<T> to be an alias for vector<T,My_allocator<V>>:

 using template<class T> Vec = std::vector<T,My_allocator<T>>;

 void f()

 {

 enum Color { blue, green, red };

 std::vector<Color> vc; // not allowed in C++98

 // …

 }

 The alias mechanism was frequently requested under the name "template typedef." Did you know you couldn't do that? Did you know that the definition of vc in f() was not allowed and why? Well, both work in C++0x, and you don't even have to add a space between the two >s in vector<T,My_allocator<V>>.

 So, one thing that C++0x does for novices is saving them from unnecessary restrictions in a number of places. To do so was a stated aim: "To make the language rules more general and uniform." That's one of the two ways of making a language easier to use for novices. The other is "provide features that directly support doing simple things simply." Most of those would be new libraries, and there are preciously few of those.

 幸い、採択された約50個の提案のほとんどは、“以前はこんなことができなかったの?”といった程度のマイナーなものばかりです。例えば、引数を持つテンプレートのエイリアスを作成し、ローカル型を引数として使用できるようにするといった提案があります。

// vector<T,My_allocator<V>>のエイリアスVec<T>を定義する:
using template<class T> Vec = std::vector<T,My_allocator<T>>;

	void f()
	{
		enum Color { blue, green, red };
		std::vector<Color> vc;	// C++98では不可
		// …
	}

 エイリアスメカニズムの導入は、“テンプレート再定義”の名の下に頻繁に要求されていました。これまではこんなことができなかったのです! ご存知でしたか? f()関数内でvcを定義することが許されていなかったのです。信じられないことです。C++0xでは、いずれもサポートされます。また、vector<T,My_allocator<V>>内の2つの>の間にスペースを入れる必要はありません。

 C++0xは、不要な制限を取り除き、初心者の負担を軽減するために2つの目標を立てています。委員会内部ではそれぞれ“言語規則をより汎用化し、統一すること”“単純なことをシンプルに行なえる機能を直接サポートすること”と表現されています。前者は、C++が初心者にとってより使いやすい言語となることを目指しています。後者は、新しいライブラリの提供ということになると思います。評価できるライブラリの数が限られているのが現状です。

 I would have liked to see many more libraries, but we did get a few: regular expressions, hashed containers (e.g. unordered_map), smart pointers, tuples, threads, time duration, an asynchronous return mechanism (future). Some of these will help novices as well as experts. None of these are new - you could have used them (or close equivalents) for years, but they now become standard and shipped with every implementation. That especially helps novices, who are often unwilling to download and install a key component (e.g. libraries from boost.org), and people in companies with policies against the use of non-standard libraries they didn't write in-house.

 Much of the help for novices comes from new features that makes the standard library easier to use and faster. My favorite is the initializer lists:

 vector<string> names = { "Aho", "Weinberger", "Kernighan" };

 map<const char*,string> designers = { {"C", "Ritchie"}, { "C++", "Stroustrup" }, { "BCPL", "Richards"} };

 None of the C++98 alternatives are as simple and direct.

 より多くのライブラリが提供されてほしいところですが、現実には、正規表現、ハッシュコンテナー(例えばunordered_map)、スマートポインター、タプル、スレッド、時間計測、非同期復帰メカニズム(future)などの限られたライブラリが提供されるだけです。これらのライブラリは、エキスパートと共に、初心者も利用できるでしょう。類似機能も含めると既に利用可能なものばかりであり、目新しいものはありません。しかし、標準仕様の一部になったことにより、すべてのコンパイラーで利用できます。キーとなるコンポーネント(例えば「boost.org」のライブラリなど)をダウンロード・インストールしたがらない初心者には朗報です。また、自分たちで作成した非標準ライブラリ以外のライブラリの使用を禁止している組織の開発者にも朗報です。

 新機能が追加されることにより、標準ライブラリはより使いやすく、より高速になります。私は次のような初期化リストを気に入っています。

vector<string> names = { "Aho", "Weinberger", "Kernighan" };
map<const char*,string> designers = { {"C", "Ritchie"}, { "C++", "Stroustrup" }, { "BCPL", "Richards"} };

 C++98仕様は、このような単純かつ直接的な記述をサポートしていません。

対話のポイント

 Stroustrup氏は、C++初心者への配慮と標準ライブラリの充実を常に強調してきました。今回の回答を読む限り、C++コミュニティーからの要望を優先するあまり、同氏自身の希望はそれほどかなえられていない印象を受けます。

 筆者は以前、Dennis Ritchie氏(C設計者)、Bjarne Stroustrup氏(C++設計者)、James Gosling氏(Java設計者)による鼎談の様子を伝える記事を読んだことがあります(『The C Family of Languages: Interview with Dennis Ritchie, Bjarne Stroustrup, and James Gosling』(英語原文)、筆者が整理した日本語概要:豊田孝の「IT談話館」)。記事の中で3人の設計者たちは、コミュニティーの存在の重さと付き合い方の難しさについて異口同音に触れています。興味のある方はぜひ目を通してみるとよいでしょう。

 C++標準化委員会のWebサイトでは、ドラフト仕様を含む膨大な数の資料を公開しています。次回は、C++0xの特徴と新機能を理解するための参考図書を紹介していただきます。お楽しみに!

この記事は参考になりましたか?

連載通知を行うには会員登録(無料)が必要です。
既に会員の方はを行ってください。
Bjarne Stroustrup氏との対話連載記事一覧

もっと読む

この記事の著者

豊田 孝(トヨタ タカシ)

「Windows PowerShell実践スクリプティング―オブジェクト指向と集合指向の統合シェル」(秀和システム発行)と「IT技術者として生き抜くための十ヶ条」(翔泳社発行)の近著2冊にて本音の数%を吐露。最近の活動傾向は、こちらを参照してください。 

※プロフィールは、執筆時点、または直近の記事の寄稿時点での内容です

この記事は参考になりましたか?

この記事をシェア

CodeZine(コードジン)
https://codezine.jp/article/detail/3220 2008/11/20 14:00

イベント

CodeZine編集部では、現場で活躍するデベロッパーをスターにするためのカンファレンス「Developers Summit」や、エンジニアの生きざまをブーストするためのイベント「Developers Boost」など、さまざまなカンファレンスを企画・運営しています。

新規会員登録無料のご案内

  • ・全ての過去記事が閲覧できます
  • ・会員限定メルマガを受信できます

メールバックナンバー