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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
hihats
August 28, 2017
Technology
250
0
Share
コードの静的解析ツールを使う目的と効用
最近の解析ツールはソースコードのスコアリングもしてくれますが、それってどういう基準なの?
というお話をしました。
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
130
ソフトウェア設計についての基本認識
hihats
1
100
アジャイル開発を始める前におさえておきたいこと
hihats
0
110
AWS Lambdaの今現在
hihats
0
810
DIコンテナを学ぶ
hihats
2
400
Laravel勉強会 2016
hihats
0
1.5k
Other Decks in Technology
See All in Technology
Oracle Cloud Infrastructure(OCI):Onboarding Session(はじめてのOCI/Oracle Supportご利⽤ガイド)
oracle4engineer
PRO
2
17k
Cortex Codeでデータの仕事を全部Agenticにやりきろう!
gappy50
0
120
Bref でサービスを運用している話
sgash708
0
220
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
5
1.3k
CREがSLOを握ると 何が変わるのか
nekomaho
0
370
AIエージェント勉強会第3回 エージェンティックAIの時代がやってきた
ymiya55
0
210
Oracle AI Database@AWS:サービス概要のご紹介
oracle4engineer
PRO
3
2.1k
開発チームとQAエンジニアの新しい協業モデル -年末調整開発チームで実践する【QAリード施策】-
kaomi_wombat
0
290
Network Firewall Proxyで 自前プロキシを消し去ることができるのか
gusandayo
0
160
第26回FA設備技術勉強会 - Claude/Claude_codeでデータ分析 -
happysamurai294
0
330
JEDAI認定プログラム JEDAI Order 2026 受賞者一覧 / JEDAI Order 2026 Winners
databricksjapan
0
470
AIにより大幅に強化された AWS Transform Customを触ってみる
0air
0
270
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
187
22k
Into the Great Unknown - MozCon
thekraken
40
2.3k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
150
The Mindset for Success: Future Career Progression
greggifford
PRO
0
290
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.6k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
170
Making the Leap to Tech Lead
cromwellryan
135
9.8k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Utilizing Notion as your number one productivity tool
mfonobong
4
280
Tell your own story through comics
letsgokoyo
1
880
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.8k
The Cost Of JavaScript in 2023
addyosmani
55
9.8k
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
まとめ コードの静的解析ツールはルールの統一だけでなく、コードのスコアリングも してくれる 基準となるのは ・ 凝集度 ・ 結合度 ・ 循環的複雑度
注意点 あくまでコードを多角的にみるためのもの 指標に囚われすぎるのはよくない 運用してみて、しっくりこないのであれば緩くするのもあり