1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

EAFPとLBYLについて解説(学習まとめ)

1
Last updated at Posted at 2022-11-16

今更ですが、「EAFP」と「LBYL」について解説していきたいと思います。
プログラミングする上で大事なことなので、筆者自身が忘れないように書き留めておきます。

「EAFP」は、「Easier to Ask Forgiveness than Permission」「許可を得るよりも、許しを請うほうが簡単」という格言です。
「EAFP」は、例外処理機構を用いることから、コード中にtry/except文が頻繁に出てくる方式であり、安全なエラー処理が可能な反面、実行時のオーバーヘッドが大きいというデメリットがあります。

「LBYL」は、「Look Before You Leap」「飛ぶ前に見ろ/転ばぬ先の杖」という格言です。
「LBYL」は、オブジェクト指向以前の手続き型言語で採用されていました。例えば、関数の戻り値や、関数に渡すポインタ引数を用いて、関数側で結果コード(=ステータスコード)を書き込んでもらい、呼出し元でチェックをするという方式です。コード中にif文が頻繁に出てくる方式です。前段の「EAFP」に比べると若干コードの可読性が下がる一方で、実行時のオーバーヘッドが小さいというメリットがあります。

以上が、「EAFP」と「LBYL」についての解説でした。
また懲りずに記事を書いていこうと思います。
それではまた~。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?