200行ぐらいある関数を、分かりやすく書きなおそう、というお話。お題はこんなJavaScript。あとで、軽く ActionScript 3.0 も出てくるよ。 function fly() { // 初期化処理 var init:Boolean = false; // 50行ぐらい初期化処理 // うまくいったら init が true になる // 実行 if(init) { var succeeded = false; // 100行ぐらい実行 } // 終了処理 // 30行ぐらい終了処理 } 構造化プログラミングについて知ってる人なら、きっとこうする。 function fly() { if(startFly()) { doFly(); } endFly(); } 構造がたいそうすっきりした。問題は、startFly()・doFly()・endFly() をどこに記述するか。fl