早く失敗する! 原則:デバッグを減らし、より信頼性の高いソフトウェアを作成する

画像
アプリケーションでエラーが発生した場合、このエラーを処理するための正反対のアプローチが2つあります。
許して! アプローチ:アプリケーションは引き続き実行され、エラーの結果を最小限に抑えようとします。
早く失敗する! アプローチ:アプリケーションはすぐに動作を停止し、エラーを報告します。


これらの質問に答えるために、簡単な例を見てみましょう。

噴水の横にある水が汚染されているという警告を表示する簡単なWebページを作成する必要があるとします。
次のHTMLがこのタスクを実行します。
<html> <body> <h2 style="color:red;">Important!</h2> <p>Please <b>DO NOT</b> drink this water!</p> </body> </html> 

ブラウザでのこのコードの結果は次のようになります。
画像

ここで、HTMLコード内で小さな間違いを犯します。
タグの代わりに、タグを使用します
    DO NOT,    : 
<p>Please <b>DO NOT<b> drink this water!</p>
:
? ?

. HTML- . Firefox, Google Chrome, Internet Explorer, Opera Safari :
画像

, Forgive!, . , , . . !

: Forgive! !

. <b DO NOT, :
<p>Please <b DO NOT</b> drink this water!</p>
:
画像

! , , . . , , -.

: Forgive! !

, - . , " " . , Mariner 1 - " ". List of software bugs .

, Forgive! . , " ?"

, . , , .
:
Fail fast!

:
Fail fast! . - , , , . , Fail fast! . , . , , . , .

, , . , ---. , Fail fast! . , , , , . "", . , . "" " ". Fail fast! .

. , , . , Fail fast! , . - . Forgive! " ".

- Fail fast!, . , , , (", ... abc.tmp"), .

:
Fail fast! . :
Fail fast!. , , , . , , Forgive! .


Rule of Repair The Art of Unix Programming , :
- , .

6 - , :
, , , " ", .

, - , Fail fast! . , Fail fast! , . , , :
var table_row_index = 1 ... table_row_indx = table_row_index + 1

Fail fast!. / .

Fail fast! , . :
, , , .

(= + + ), , .

:
, , fail fast fail fast .
.
. Assert
. fail fast .
, - .
DO NOT, :
<p>Please <b>DO NOT<b> drink this water!</p>

:
? ?

. HTML- . Firefox, Google Chrome, Internet Explorer, Opera Safari :
画像

, Forgive!, . , , . . !

: Forgive! !

. <b DO NOT, :
<p>Please <b DO NOT</b> drink this water!</p>
:
画像

! , , . . , , -.

: Forgive! !

, - . , " " . , Mariner 1 - " ". List of software bugs .

, Forgive! . , " ?"

, . , , .
:
Fail fast!

:
Fail fast! . - , , , . , Fail fast! . , . , , . , .

, , . , ---. , Fail fast! . , , , , . "", . , . "" " ". Fail fast! .

. , , . , Fail fast! , . - . Forgive! " ".

- Fail fast!, . , , , (", ... abc.tmp"), .

:
Fail fast! . :
Fail fast!. , , , . , , Forgive! .


Rule of Repair The Art of Unix Programming , :
- , .

6 - , :
, , , " ", .

, - , Fail fast! . , Fail fast! , . , , :
var table_row_index = 1 ... table_row_indx = table_row_index + 1

Fail fast!. / .

Fail fast! , . :
, , , .

(= + + ), , .

:
, , fail fast fail fast .
.
. Assert
. fail fast .
, - .
DO NOT, :
<p>Please <b>DO NOT<b> drink this water!</p>

:
? ?

. HTML- . Firefox, Google Chrome, Internet Explorer, Opera Safari :
画像

, Forgive!, . , , . . !

: Forgive! !

. <b DO NOT, :
<p>Please <b DO NOT</b> drink this water!</p>
:
画像

! , , . . , , -.

: Forgive! !

, - . , " " . , Mariner 1 - " ". List of software bugs .

, Forgive! . , " ?"

, . , , .
:
Fail fast!

:
Fail fast! . - , , , . , Fail fast! . , . , , . , .

, , . , ---. , Fail fast! . , , , , . "", . , . "" " ". Fail fast! .

. , , . , Fail fast! , . - . Forgive! " ".

- Fail fast!, . , , , (", ... abc.tmp"), .

:
Fail fast! . :
Fail fast!. , , , . , , Forgive! .


Rule of Repair The Art of Unix Programming , :
- , .

6 - , :
, , , " ", .

, - , Fail fast! . , Fail fast! , . , , :
var table_row_index = 1 ... table_row_indx = table_row_index + 1

Fail fast!. / .

Fail fast! , . :
, , , .

(= + + ), , .

:
, , fail fast fail fast .
.
. Assert
. fail fast .
, - .
    DO NOT,    : 
<p>Please <b>DO NOT<b> drink this water!</p>

:
? ?

. HTML- . Firefox, Google Chrome, Internet Explorer, Opera Safari :
画像

, Forgive!, . , , . . !

: Forgive! !

. <b DO NOT, :
<p>Please <b DO NOT</b> drink this water!</p>
:
画像

! , , . . , , -.

: Forgive! !

, - . , " " . , Mariner 1 - " ". List of software bugs .

, Forgive! . , " ?"

, . , , .
:
Fail fast!

:
Fail fast! . - , , , . , Fail fast! . , . , , . , .

, , . , ---. , Fail fast! . , , , , . "", . , . "" " ". Fail fast! .

. , , . , Fail fast! , . - . Forgive! " ".

- Fail fast!, . , , , (", ... abc.tmp"), .

:
Fail fast! . :
Fail fast!. , , , . , , Forgive! .


Rule of Repair The Art of Unix Programming , :
- , .

6 - , :
, , , " ", .

, - , Fail fast! . , Fail fast! , . , , :
var table_row_index = 1 ... table_row_indx = table_row_index + 1

Fail fast!. / .

Fail fast! , . :
, , , .

(= + + ), , .

:
, , fail fast fail fast .
.
. Assert
. fail fast .
, - .
DO NOT, :
<p>Please <b>DO NOT<b> drink this water!</p>

:
? ?

. HTML- . Firefox, Google Chrome, Internet Explorer, Opera Safari :
画像

, Forgive!, . , , . . !

: Forgive! !

. <b DO NOT, :
<p>Please <b DO NOT</b> drink this water!</p>
:
画像

! , , . . , , -.

: Forgive! !

, - . , " " . , Mariner 1 - " ". List of software bugs .

, Forgive! . , " ?"

, . , , .
:
Fail fast!

:
Fail fast! . - , , , . , Fail fast! . , . , , . , .

, , . , ---. , Fail fast! . , , , , . "", . , . "" " ". Fail fast! .

. , , . , Fail fast! , . - . Forgive! " ".

- Fail fast!, . , , , (", ... abc.tmp"), .

:
Fail fast! . :
Fail fast!. , , , . , , Forgive! .


Rule of Repair The Art of Unix Programming , :
- , .

6 - , :
, , , " ", .

, - , Fail fast! . , Fail fast! , . , , :
var table_row_index = 1 ... table_row_indx = table_row_index + 1

Fail fast!. / .

Fail fast! , . :
, , , .

(= + + ), , .

:
, , fail fast fail fast .
.
. Assert
. fail fast .
, - .
DO NOT, :
<p>Please <b>DO NOT<b> drink this water!</p>

:
? ?

. HTML- . Firefox, Google Chrome, Internet Explorer, Opera Safari :
画像

, Forgive!, . , , . . !

: Forgive! !

. <b DO NOT, :
<p>Please <b DO NOT</b> drink this water!</p>
:
画像

! , , . . , , -.

: Forgive! !

, - . , " " . , Mariner 1 - " ". List of software bugs .

, Forgive! . , " ?"

, . , , .
:
Fail fast!

:
Fail fast! . - , , , . , Fail fast! . , . , , . , .

, , . , ---. , Fail fast! . , , , , . "", . , . "" " ". Fail fast! .

. , , . , Fail fast! , . - . Forgive! " ".

- Fail fast!, . , , , (", ... abc.tmp"), .

:
Fail fast! . :
Fail fast!. , , , . , , Forgive! .


Rule of Repair The Art of Unix Programming , :
- , .

6 - , :
, , , " ", .

, - , Fail fast! . , Fail fast! , . , , :
var table_row_index = 1 ... table_row_indx = table_row_index + 1

Fail fast!. / .

Fail fast! , . :
, , , .

(= + + ), , .

:
, , fail fast fail fast .
.
. Assert
. fail fast .
, - .
DO NOT, :
<p>Please <b>DO NOT<b> drink this water!</p>

:
? ?

. HTML- . Firefox, Google Chrome, Internet Explorer, Opera Safari :
画像

, Forgive!, . , , . . !

: Forgive! !

. <b DO NOT, :
<p>Please <b DO NOT</b> drink this water!</p>
:
画像

! , , . . , , -.

: Forgive! !

, - . , " " . , Mariner 1 - " ". List of software bugs .

, Forgive! . , " ?"

, . , , .
:
Fail fast!

:
Fail fast! . - , , , . , Fail fast! . , . , , . , .

, , . , ---. , Fail fast! . , , , , . "", . , . "" " ". Fail fast! .

. , , . , Fail fast! , . - . Forgive! " ".

- Fail fast!, . , , , (", ... abc.tmp"), .

:
Fail fast! . :
Fail fast!. , , , . , , Forgive! .


Rule of Repair The Art of Unix Programming , :
- , .

6 - , :
, , , " ", .

, - , Fail fast! . , Fail fast! , . , , :
var table_row_index = 1 ... table_row_indx = table_row_index + 1

Fail fast!. / .

Fail fast! , . :
, , , .

(= + + ), , .

:
, , fail fast fail fast .
.
. Assert
. fail fast .
, - .
DO NOT, :
<p>Please <b>DO NOT<b> drink this water!</p>

:
? ?

. HTML- . Firefox, Google Chrome, Internet Explorer, Opera Safari :
画像

, Forgive!, . , , . . !

: Forgive! !

. <b DO NOT, :
<p>Please <b DO NOT</b> drink this water!</p>
:
画像

! , , . . , , -.

: Forgive! !

, - . , " " . , Mariner 1 - " ". List of software bugs .

, Forgive! . , " ?"

, . , , .
:
Fail fast!

:
Fail fast! . - , , , . , Fail fast! . , . , , . , .

, , . , ---. , Fail fast! . , , , , . "", . , . "" " ". Fail fast! .

. , , . , Fail fast! , . - . Forgive! " ".

- Fail fast!, . , , , (", ... abc.tmp"), .

:
Fail fast! . :
Fail fast!. , , , . , , Forgive! .


Rule of Repair The Art of Unix Programming , :
- , .

6 - , :
, , , " ", .

, - , Fail fast! . , Fail fast! , . , , :
var table_row_index = 1 ... table_row_indx = table_row_index + 1

Fail fast!. / .

Fail fast! , . :
, , , .

(= + + ), , .

:
, , fail fast fail fast .
.
. Assert
. fail fast .
, - .
DO NOT, :
<p>Please <b>DO NOT<b> drink this water!</p>

:
? ?

. HTML- . Firefox, Google Chrome, Internet Explorer, Opera Safari :
画像

, Forgive!, . , , . . !

: Forgive! !

. <b DO NOT, :
<p>Please <b DO NOT</b> drink this water!</p>
:
画像

! , , . . , , -.

: Forgive! !

, - . , " " . , Mariner 1 - " ". List of software bugs .

, Forgive! . , " ?"

, . , , .
:
Fail fast!

:
Fail fast! . - , , , . , Fail fast! . , . , , . , .

, , . , ---. , Fail fast! . , , , , . "", . , . "" " ". Fail fast! .

. , , . , Fail fast! , . - . Forgive! " ".

- Fail fast!, . , , , (", ... abc.tmp"), .

:
Fail fast! . :
Fail fast!. , , , . , , Forgive! .


Rule of Repair The Art of Unix Programming , :
- , .

6 - , :
, , , " ", .

, - , Fail fast! . , Fail fast! , . , , :
var table_row_index = 1 ... table_row_indx = table_row_index + 1

Fail fast!. / .

Fail fast! , . :
, , , .

(= + + ), , .

:
, , fail fast fail fast .
.
. Assert
. fail fast .
, - .
DO NOT, :
<p>Please <b>DO NOT<b> drink this water!</p>

:
? ?

. HTML- . Firefox, Google Chrome, Internet Explorer, Opera Safari :
画像

, Forgive!, . , , . . !

: Forgive! !

. <b DO NOT, :
<p>Please <b DO NOT</b> drink this water!</p>
:
画像

! , , . . , , -.

: Forgive! !

, - . , " " . , Mariner 1 - " ". List of software bugs .

, Forgive! . , " ?"

, . , , .
:
Fail fast!

:
Fail fast! . - , , , . , Fail fast! . , . , , . , .

, , . , ---. , Fail fast! . , , , , . "", . , . "" " ". Fail fast! .

. , , . , Fail fast! , . - . Forgive! " ".

- Fail fast!, . , , , (", ... abc.tmp"), .

:
Fail fast! . :
Fail fast!. , , , . , , Forgive! .


Rule of Repair The Art of Unix Programming , :
- , .

6 - , :
, , , " ", .

, - , Fail fast! . , Fail fast! , . , , :
var table_row_index = 1 ... table_row_indx = table_row_index + 1

Fail fast!. / .

Fail fast! , . :
, , , .

(= + + ), , .

:
, , fail fast fail fast .
.
. Assert
. fail fast .
, - .
DO NOT, :
<p>Please <b>DO NOT<b> drink this water!</p>

:
? ?

. HTML- . Firefox, Google Chrome, Internet Explorer, Opera Safari :
画像

, Forgive!, . , , . . !

: Forgive! !

. <b DO NOT, :
<p>Please <b DO NOT</b> drink this water!</p>
:
画像

! , , . . , , -.

: Forgive! !

, - . , " " . , Mariner 1 - " ". List of software bugs .

, Forgive! . , " ?"

, . , , .
:
Fail fast!

:
Fail fast! . - , , , . , Fail fast! . , . , , . , .

, , . , ---. , Fail fast! . , , , , . "", . , . "" " ". Fail fast! .

. , , . , Fail fast! , . - . Forgive! " ".

- Fail fast!, . , , , (", ... abc.tmp"), .

:
Fail fast! . :
Fail fast!. , , , . , , Forgive! .


Rule of Repair The Art of Unix Programming , :
- , .

6 - , :
, , , " ", .

, - , Fail fast! . , Fail fast! , . , , :
var table_row_index = 1 ... table_row_indx = table_row_index + 1

Fail fast!. / .

Fail fast! , . :
, , , .

(= + + ), , .

:
, , fail fast fail fast .
.
. Assert
. fail fast .
, - .
DO NOT, :
<p>Please <b>DO NOT<b> drink this water!</p>

:
? ?

. HTML- . Firefox, Google Chrome, Internet Explorer, Opera Safari :
画像

, Forgive!, . , , . . !

: Forgive! !

. <b DO NOT, :
<p>Please <b DO NOT</b> drink this water!</p>
:
画像

! , , . . , , -.

: Forgive! !

, - . , " " . , Mariner 1 - " ". List of software bugs .

, Forgive! . , " ?"

, . , , .
:
Fail fast!

:
Fail fast! . - , , , . , Fail fast! . , . , , . , .

, , . , ---. , Fail fast! . , , , , . "", . , . "" " ". Fail fast! .

. , , . , Fail fast! , . - . Forgive! " ".

- Fail fast!, . , , , (", ... abc.tmp"), .

:
Fail fast! . :
Fail fast!. , , , . , , Forgive! .


Rule of Repair The Art of Unix Programming , :
- , .

6 - , :
, , , " ", .

, - , Fail fast! . , Fail fast! , . , , :
var table_row_index = 1 ... table_row_indx = table_row_index + 1

Fail fast!. / .

Fail fast! , . :
, , , .

(= + + ), , .

:
, , fail fast fail fast .
.
. Assert
. fail fast .
, - .
DO NOT, :
<p>Please <b>DO NOT<b> drink this water!</p>

:
? ?

. HTML- . Firefox, Google Chrome, Internet Explorer, Opera Safari :
画像

, Forgive!, . , , . . !

: Forgive! !

. <b DO NOT, :
<p>Please <b DO NOT</b> drink this water!</p>
:
画像

! , , . . , , -.

: Forgive! !

, - . , " " . , Mariner 1 - " ". List of software bugs .

, Forgive! . , " ?"

, . , , .
:
Fail fast!

:
Fail fast! . - , , , . , Fail fast! . , . , , . , .

, , . , ---. , Fail fast! . , , , , . "", . , . "" " ". Fail fast! .

. , , . , Fail fast! , . - . Forgive! " ".

- Fail fast!, . , , , (", ... abc.tmp"), .

:
Fail fast! . :
Fail fast!. , , , . , , Forgive! .


Rule of Repair The Art of Unix Programming , :
- , .

6 - , :
, , , " ", .

, - , Fail fast! . , Fail fast! , . , , :
var table_row_index = 1 ... table_row_indx = table_row_index + 1

Fail fast!. / .

Fail fast! , . :
, , , .

(= + + ), , .

:
, , fail fast fail fast .
.
. Assert
. fail fast .
, - .
DO NOT, :
<p>Please <b>DO NOT<b> drink this water!</p>

:
? ?

. HTML- . Firefox, Google Chrome, Internet Explorer, Opera Safari :
画像

, Forgive!, . , , . . !

: Forgive! !

. <b DO NOT, :
<p>Please <b DO NOT</b> drink this water!</p>
:
画像

! , , . . , , -.

: Forgive! !

, - . , " " . , Mariner 1 - " ". List of software bugs .

, Forgive! . , " ?"

, . , , .
:
Fail fast!

:
Fail fast! . - , , , . , Fail fast! . , . , , . , .

, , . , ---. , Fail fast! . , , , , . "", . , . "" " ". Fail fast! .

. , , . , Fail fast! , . - . Forgive! " ".

- Fail fast!, . , , , (", ... abc.tmp"), .

:
Fail fast! . :
Fail fast!. , , , . , , Forgive! .


Rule of Repair The Art of Unix Programming , :
- , .

6 - , :
, , , " ", .

, - , Fail fast! . , Fail fast! , . , , :
var table_row_index = 1 ... table_row_indx = table_row_index + 1

Fail fast!. / .

Fail fast! , . :
, , , .

(= + + ), , .

:
, , fail fast fail fast .
.
. Assert
. fail fast .
, - .
    DO NOT,    : 
<p>Please <b>DO NOT<b> drink this water!</p>

:
? ?

. HTML- . Firefox, Google Chrome, Internet Explorer, Opera Safari :
画像

, Forgive!, . , , . . !

: Forgive! !

. <b DO NOT, :
<p>Please <b DO NOT</b> drink this water!</p>
:
画像

! , , . . , , -.

: Forgive! !

, - . , " " . , Mariner 1 - " ". List of software bugs .

, Forgive! . , " ?"

, . , , .
:
Fail fast!

:
Fail fast! . - , , , . , Fail fast! . , . , , . , .

, , . , ---. , Fail fast! . , , , , . "", . , . "" " ". Fail fast! .

. , , . , Fail fast! , . - . Forgive! " ".

- Fail fast!, . , , , (", ... abc.tmp"), .

:
Fail fast! . :
Fail fast!. , , , . , , Forgive! .


Rule of Repair The Art of Unix Programming , :
- , .

6 - , :
, , , " ", .

, - , Fail fast! . , Fail fast! , . , , :
var table_row_index = 1 ... table_row_indx = table_row_index + 1

Fail fast!. / .

Fail fast! , . :
, , , .

(= + + ), , .

:
, , fail fast fail fast .
.
. Assert
. fail fast .
, - .
DO NOT, :
<p>Please <b>DO NOT<b> drink this water!</p>

:
? ?

. HTML- . Firefox, Google Chrome, Internet Explorer, Opera Safari :
画像

, Forgive!, . , , . . !

: Forgive! !

. <b DO NOT, :
<p>Please <b DO NOT</b> drink this water!</p>
:
画像

! , , . . , , -.

: Forgive! !

, - . , " " . , Mariner 1 - " ". List of software bugs .

, Forgive! . , " ?"

, . , , .
:
Fail fast!

:
Fail fast! . - , , , . , Fail fast! . , . , , . , .

, , . , ---. , Fail fast! . , , , , . "", . , . "" " ". Fail fast! .

. , , . , Fail fast! , . - . Forgive! " ".

- Fail fast!, . , , , (", ... abc.tmp"), .

:
Fail fast! . :
Fail fast!. , , , . , , Forgive! .


Rule of Repair The Art of Unix Programming , :
- , .

6 - , :
, , , " ", .

, - , Fail fast! . , Fail fast! , . , , :
var table_row_index = 1 ... table_row_indx = table_row_index + 1

Fail fast!. / .

Fail fast! , . :
, , , .

(= + + ), , .

:
, , fail fast fail fast .
.
. Assert
. fail fast .
, - .
DO NOT, :
<p>Please <b>DO NOT<b> drink this water!</p>

:
? ?

. HTML- . Firefox, Google Chrome, Internet Explorer, Opera Safari :
画像

, Forgive!, . , , . . !

: Forgive! !

. <b DO NOT, :
<p>Please <b DO NOT</b> drink this water!</p>
:
画像

! , , . . , , -.

: Forgive! !

, - . , " " . , Mariner 1 - " ". List of software bugs .

, Forgive! . , " ?"

, . , , .
:
Fail fast!

:
Fail fast! . - , , , . , Fail fast! . , . , , . , .

, , . , ---. , Fail fast! . , , , , . "", . , . "" " ". Fail fast! .

. , , . , Fail fast! , . - . Forgive! " ".

- Fail fast!, . , , , (", ... abc.tmp"), .

:
Fail fast! . :
Fail fast!. , , , . , , Forgive! .


Rule of Repair The Art of Unix Programming , :
- , .

6 - , :
, , , " ", .

, - , Fail fast! . , Fail fast! , . , , :
var table_row_index = 1 ... table_row_indx = table_row_index + 1

Fail fast!. / .

Fail fast! , . :
, , , .

(= + + ), , .

:
, , fail fast fail fast .
.
. Assert
. fail fast .
, - .


Source: https://habr.com/ru/post/J218325/


All Articles