Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
コードの静的解析ツールを使う目的と効用
Search
hihats
August 28, 2017
Technology
270
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
コードの静的解析ツールを使う目的と効用
最近の解析ツールはソースコードのスコアリングもしてくれますが、それってどういう基準なの?
というお話をしました。
hihats
August 28, 2017
More Decks by hihats
See All by hihats
Which Json Serializer should we use in Ruby on Rails6 era
hihats
1
150
ソフトウェア設計についての基本認識
hihats
1
120
アジャイル開発を始める前におさえておきたいこと
hihats
0
130
AWS Lambdaの今現在
hihats
0
820
DIコンテナを学ぶ
hihats
2
410
Laravel勉強会 2016
hihats
0
1.5k
Other Decks in Technology
See All in Technology
AI開発に用いられるHPC技術について
gpuunite_official
0
280
Oracle MCP Servers Explained
thatjeffsmith
1
500
1.5時間を無駄にして学んだwsl2におけるaptとsnapの選択と仕組み
yosaka0123
0
440
:syncing_time:
sksat
2
750
Microsoft MVP プログラムを紹介するから目指す人増えてくれ
tsubakimoto_s
0
110
The Django UUID Story - DjangoCon US 2026
pauloxnet
0
260
医療の現場を変革に挑戦した半年間の軌跡 - PythonとAIで現場を変える / From Code to Care
soudai
PRO
1
620
dbt in Microsoft Fabric
ryomaru0825
0
250
OpenID for Verifiable Credentials 実装から見えた相互運用性確保までの道のり(OAuth/OIDC Numa (Immersion) Workshop 2026)
oidfj
PRO
0
270
【書籍出版記念】 10周回って、エージェント開発は RAGがすべてだった。〜RAGの歴史と開発現場で見えた実践知〜
akiratameto
20
7.5k
AI for Science時代を切り開く、政府の次世代HPC戦略の展望
gpuunite_official
0
250
研究開発部の紹介 / Sansan R&D Profile
sansan33
PRO
4
24k
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
174
15k
Building AI with AI
inesmontani
PRO
1
1.2k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.1k
Designing Powerful Visuals for Engaging Learning
tmiket
1
510
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
310
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
220
Statistics for Hackers
jakevdp
799
230k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
250
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
220
Transcript
コードの静的解析ツール コードメトリクスについて
コードを静的解析してくれるツール PHP • phpmd • phpcs Ruby • Rubocop Javascript
• ESLint
• 一般的な規約に沿っているか • コーディングスタイルの統一 導入目的
だけではない
コードのスコアリング コードの定量評価(いわゆる点数付け)もしてくれる
どういう基準で?
• Coupling • Cohesion • Size • Complexity
凝集度と結合度 構造化設計
凝集度 Cohesion 各モジュール内の関連性を最大に すること class A { int width; Int
height; function widen(int add){ width = width + add; } function highten(int add){ height = height + add; } } クラスのメンバ変数 は2つ 2つのメソッドで使 われているメンバ 変数はそれぞれ ひとつずつ
凝集度 Cohesion 各モジュール内の関連性を最大に すること class A { int width; Int
height; function widen(int add){ width = width + add; } function highten(int add){ height = height + add; } } クラスのメンバ変数 は2つ 2つのメソッドで使 われているメンバ 変数はそれぞれ ひとつずつ 凝集度はそれほど 高くない
結合度 Coupling モジュール間の関連性を最小にす ること class Square { require Rhombus; function
square(rhombus = new Rhombus){ return rhombus->width * rhombus->width; } } 属性は ・width ・angle があるが、angle がSquareの計算 に必要かというと 必要ない
結合度 Coupling モジュール間の関連性を最小にす ること class Square { function square(rhombus_width){ return
rhombus_width * rhombus_width; } } 属性は ・width ・angle があるが、angle がSquareの計算 に必要かというと 必要ない 結合度が下がった!
循環的複雑度 簡単に言うとコードの分岐数
ifやforを使うと1ずつ増えていく foreach ($array as $key => $value ){ for ($i+0;
$i< $max; $++){ switch($value[$i]){ case 1: If ($value…) …… 分岐がなければ1(Best値) function good_method($array){ return array_map(function($n) { return $n * $n; }, $array); }
ネストが深くなっている = 「責務を負いすぎている」 という考え方
詳しくはGoogleのブログ https://testing.googleblog.com/2011/02/this- code-is-crap.html
まとめ コードの静的解析ツールはルールの統一だけでなく、コードのスコアリングも してくれる 基準となるのは ・ 凝集度 ・ 結合度 ・ 循環的複雑度
注意点 あくまでコードを多角的にみるためのもの 指標に囚われすぎるのはよくない 運用してみて、しっくりこないのであれば緩くするのもあり