Source monitorと複雑度のはなし

12
aomoriringo

Transcript of Source monitorと複雑度のはなし

Page 1: Source monitorと複雑度のはなし

aomoriringo

Page 2: Source monitorと複雑度のはなし

フリーソフトウェア

コードの静的メトリクス計測ツール

C, C++, C#, VB.NET, Java, Delphi, VB6, HTML

Page 3: Source monitorと複雑度のはなし

sourceMonitorはコード解析をして、 こんなものを表示してくれます

◦ コメントの割合

◦ ドキュメントの割合

◦ メソッド数/1クラス

◦ 構文数/1メソッド

◦ 一番複雑なメソッドの名前/行数

◦ Avg/Max Complexity

◦ Avg/Max Block Depth

Page 4: Source monitorと複雑度のはなし

ソースコード内の線形独立な経路の数

条件複雑度(Conditional Complexity)とも 呼ばれる

完全な分岐網羅ができるテストケースの数 ≦ 循環的複雑度 ≦ 完全な経路網羅ができるテストケースの数

Page 5: Source monitorと複雑度のはなし

Start with 1 for a straight path through the routine.

Add 1 for each of the following keywords or their equivalent: ◦ if, while, repeat, for, and, or

Add 1 for each case in a switch statement.

Page 6: Source monitorと複雑度のはなし

Public void ProcessPages() { while( nextPage != true ) { if( ( lineCount <= linePerPage ) && (status != Status.Cancelled) && (morePages == true ) ) { //… } } }

Page 7: Source monitorと複雑度のはなし

Public int getValue( int param1 ) { int value = 0; if ( param1 == 0 ) { value = 4; } else { value = 0; } return value; }

Page 8: Source monitorと複雑度のはなし

Complexity Risk Evaluation

<=10 よい構造。 ほとんどリスクなし

11 to 20 少し複雑。 わずかな(moderate)リスク

>30 複雑。 構造に疑問

>50 テストが不可能

>75 いかなる変更も誤修正を生む原因を作る

Page 9: Source monitorと複雑度のはなし

Complexity Risk Evaluation

<=10 よい構造。 ほとんどリスクなし

11 to 20 少し複雑。 わずかな(moderate)リスク

>30 複雑。 構造に疑問

>50 テストが不可能

>75 いかなる変更も誤修正を生む原因を作る

Page 10: Source monitorと複雑度のはなし

経路数が多く、テストケースもたくさん必要

意味を理解するのに多くの経路を 追わなければいけない

凝集度が低い傾向にある

Page 11: Source monitorと複雑度のはなし

あるコードがどれだけそのクラスの 責任分担に集中しているかを示す尺度

凝集度が高い ◦ コードが読みやすい

◦ 再利用しやすい

凝集度が低い ◦ クラスのメソッド群に共通性がない

◦ 各メソッドが全く関係のないデータを扱う

Page 12: Source monitorと複雑度のはなし

sourceMonitorは複雑度を解析してくれる

複雑度はテストや保守に関わる重要な指標 (しかも定量的)

たまには複雑度のこと、思い出してあげてください