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
0
250
コードの静的解析ツールを使う目的と効用
最近の解析ツールはソースコードのスコアリングもしてくれますが、それってどういう基準なの?
というお話をしました。
hihats
August 28, 2017
Tweet
Share
More Decks by hihats
See All by hihats
Which Json Serializer should we use in Ruby on Rails6 era
hihats
1
130
ソフトウェア設計についての基本認識
hihats
1
93
アジャイル開発を始める前におさえておきたいこと
hihats
0
110
AWS Lambdaの今現在
hihats
0
800
DIコンテナを学ぶ
hihats
2
400
Laravel勉強会 2016
hihats
0
1.5k
Other Decks in Technology
See All in Technology
テストセンター受験、オンライン受験、どっちなんだい?
yama3133
0
180
Knowledge Work の AI Backend
kworkdev
PRO
0
290
Next.js 16の新機能 Cache Components について
sutetotanuki
0
190
AWSの新機能をフル活用した「re:Inventエージェント」開発秘話
minorun365
2
480
日本Rubyの会: これまでとこれから
snoozer05
PRO
6
250
Amazon Quick Suite で始める手軽な AI エージェント
shimy
2
1.9k
MySQLのSpatial(GIS)機能をもっと充実させたい ~ MyNA望年会2025LT
sakaik
0
140
LayerX QA Night#1
koyaman2
0
270
AI with TiDD
shiraji
1
310
Claude Skillsの テスト業務での活用事例
moritamasami
1
110
松尾研LLM講座2025 応用編Day3「軽量化」 講義資料
aratako
11
4.4k
業務の煩悩を祓うAI活用術108選 / AI 108 Usages
smartbank
9
15k
Featured
See All Featured
Everyday Curiosity
cassininazir
0
110
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.5k
Ruling the World: When Life Gets Gamed
codingconduct
0
100
The Limits of Empathy - UXLibs8
cassininazir
1
190
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.8k
Prompt Engineering for Job Search
mfonobong
0
130
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.2k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
0
79
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
0
260
Typedesign – Prime Four
hannesfritz
42
2.9k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
31
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
まとめ コードの静的解析ツールはルールの統一だけでなく、コードのスコアリングも してくれる 基準となるのは ・ 凝集度 ・ 結合度 ・ 循環的複雑度
注意点 あくまでコードを多角的にみるためのもの 指標に囚われすぎるのはよくない 運用してみて、しっくりこないのであれば緩くするのもあり