SSブログ

a single exit [プログラマー現役続行]

書籍『Implementation Patterns』を読んでいて、「Guard Clause」の説明の中で次のように述べられていた。

Back in the old days of programming, a commandment was issued: each rountine shall have a single entry and a single exit. This was to prevent the confusion possible when jumping into and out of many locations in the same routine. It made good sense when applied to FORTRAN or assembly language programs written with lots of global data where even understanding which statements were executed was hard work. In Java, with small methods and mostly local data, it is needlessly conservative. However, this bit of programming folklore, thoughtlessly obeyed, prevents the use of guard clauses.

プログラムの読みやすさや理解の容易性よりも、ここで述べられているfolklore(民間伝承、言い伝え)をかたくなに信じてプログラミングしているプログラマーを見かけることがある。

今まで、この「出口は一つ」というのがどこから生まれたのかと不思議に思っていた。たしかに、グローバル変数を多用し、GOTO文やブランチ命令を使用する言語でプログラミングすれば、制御の流れがあっちへ行ったり、こっちへ行ったりして、理解するのが困難になるのは確かである。

FORTRANやアセンブリ言語を用いてプログラミングをしていたのは、20年以上前の大学時代だったので、私自身はどのようなプログラムを書いていたのが、すっかり忘れている。しかし、現実のソフトウェア開発では、アセンブリ言語からC言語へ移ったという(年配?)プログラマーもいたりする。


nice!(0)  コメント(0)  トラックバック(1) 

nice! 0

コメント 0

コメントを書く

お名前:[必須]
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

Facebook コメント

トラックバック 1