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
240
コードの静的解析ツールを使う目的と効用
最近の解析ツールはソースコードのスコアリングもしてくれますが、それってどういう基準なの?
というお話をしました。
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
120
ソフトウェア設計についての基本認識
hihats
1
87
アジャイル開発を始める前におさえておきたいこと
hihats
0
110
AWS Lambdaの今現在
hihats
0
800
DIコンテナを学ぶ
hihats
2
400
Laravel勉強会 2016
hihats
0
1.4k
Other Decks in Technology
See All in Technology
Uniadex__公開版_20250617-AIxIoTビジネス共創ラボ_ツナガルチカラ_.pdf
iotcomjpadmin
0
160
AWS アーキテクチャ作図入門/aws-architecture-diagram-101
ma2shita
29
11k
「Chatwork」の認証基盤の移行とログ活用によるプロダクト改善
kubell_hr
1
150
Observability infrastructure behind the trillion-messages scale Kafka platform
lycorptech_jp
PRO
0
140
Абьюзим random_bytes(). Фёдор Кулаков, разработчик Lamoda Tech
lamodatech
0
340
米国国防総省のDevSecOpsライフサイクルをAWSのセキュリティサービスとOSSで実現
syoshie
2
1.1k
生成AI時代 文字コードを学ぶ意義を見出せるか?
hrsued
1
290
第9回情シス転職ミートアップ_テックタッチ株式会社
forester3003
0
230
AWS テクニカルサポートとエンドカスタマーの中間地点から見えるより良いサポートの活用方法
kazzpapa3
2
540
強化されたAmazon Location Serviceによる新機能と開発者体験
dayjournal
2
210
Yamla: Rustでつくるリアルタイム性を追求した機械学習基盤 / Yamla: A Rust-Based Machine Learning Platform Pursuing Real-Time Capabilities
lycorptech_jp
PRO
3
120
製造業からパッケージ製品まで、あらゆる領域をカバー!生成AIを利用したテストシナリオ生成 / 20250627 Suguru Ishii
shift_evolve
PRO
1
140
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
173
14k
Making Projects Easy
brettharned
116
6.3k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
Into the Great Unknown - MozCon
thekraken
39
1.9k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Six Lessons from altMBA
skipperchong
28
3.8k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
2.9k
Code Reviewing Like a Champion
maltzj
524
40k
Producing Creativity
orderedlist
PRO
346
40k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Site-Speed That Sticks
csswizardry
10
660
Gamification - CAS2011
davidbonilla
81
5.3k
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
まとめ コードの静的解析ツールはルールの統一だけでなく、コードのスコアリングも してくれる 基準となるのは ・ 凝集度 ・ 結合度 ・ 循環的複雑度
注意点 あくまでコードを多角的にみるためのもの 指標に囚われすぎるのはよくない 運用してみて、しっくりこないのであれば緩くするのもあり