Python 模擬試験

PythonZen & PEP 8 模擬試験 第2回 問5・The Zen of Python(The Zen of Python の格言)

実装を説明できるか

「If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea.」の考え方に最も沿った行動として、適切なものを1つ選べ。

  1. A

    説明が難しいほど、高度で優れた実装だと考える。

  2. B

    説明できなくても、動けばよいのでコメントは書かない。

  3. C

    簡単に説明できる実装は、必ず悪いと考える。

  4. D

    実装の説明が難しいときは、設計が複雑すぎないかを見直す。

正解と解説を見る

正解:D

実装が説明しにくいなら、設計が複雑すぎるかもしれない。説明しやすい実装は、理解・保守がしやすい。

The Zen of Python(PEP 20)の格言と意味。
格言意味
Beautiful is better than ugly.美しい方が、醜いよりよい
Explicit is better than implicit.明示的な方が、暗黙的よりよい
Simple is better than complex.単純な方が、複雑よりよい
Complex is better than complicated.複雑でも、ごちゃごちゃ(complicated)よりはよい
Flat is better than nested.平らな方が、入れ子より(深い入れ子より)よい
Sparse is better than dense.ゆとりのある方が、詰め込みよりよい
Readability counts.読みやすさは大事
Special cases aren't special enough to break the rules.特別な場合でも、規則を破るほど特別ではない
Although practicality beats purity.ただし、実用性は純粋さに勝る
Errors should never pass silently.エラーを黙って見過ごしてはいけない
Unless explicitly silenced.明示的に黙らせた場合は別
In the face of ambiguity, refuse the temptation to guess.あいまいなときは、推測したくなる誘惑を断る
There should be one-- and preferably only one --obvious way to do it.明白なやり方が1つ、できればただ1つだけあるべき
Although that way may not be obvious at first unless you're Dutch.その方法は、オランダ人でなければ最初は分かりにくいかもしれない
Now is better than never.やらないよりは、今やる方がよい
Although never is often better than *right* now.ただし、「今すぐ」よりやらない方がよいことも多い
If the implementation is hard to explain, it's a bad idea.実装を説明しにくいなら、悪い考え
If the implementation is easy to explain, it may be a good idea.実装を説明しやすいなら、よい考えかもしれない
Namespaces are one honking great idea -- let's do more of those!名前空間は素晴らしい考え。もっと活用しよう

学習のポイント:Simple is better than complex. とつながる。

この問題を演習で解く →

問題一覧へ

このサイトの問題は、各試験の公式に示された出題範囲に沿って作ったオリジナルの模擬問題です。本試験の問題ではありません。一般社団法人Pythonエンジニア育成推進協会の公式サービスではありません。