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
220
コードの静的解析ツールを使う目的と効用
最近の解析ツールはソースコードのスコアリングもしてくれますが、それってどういう基準なの?
というお話をしました。
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
110
ソフトウェア設計についての基本認識
hihats
1
79
アジャイル開発を始める前におさえておきたいこと
hihats
0
100
AWS Lambdaの今現在
hihats
0
780
DIコンテナを学ぶ
hihats
2
390
Laravel勉強会 2016
hihats
0
1.4k
Other Decks in Technology
See All in Technology
ギークの理想が7つ集まるエムスリーで夢を叶えよう - エムスリー株式会社
m3_engineering
1
260
OSSコミットしてZennの課題を解決した話
dyoshikawa1993
0
150
Classmethod Odyssey 登壇資料
yamahiro
0
390
Luupの開発組織におけるインシデントマネジメントの変遷 ver.RoadtoSRENEXT2024
grimoh
1
270
Datadog Cloud SIEMを使ってAWS環境の脅威を可視化した話/lifeistech-datadog-cloud-siem
gidajun
0
480
CTOから見た事業開発とプロダクト開発 / My Perspective on Business and Product Development as CTO
keisuke69
4
960
データベース研修 DB基礎【MIXI 24新卒技術研修】
mixi_engineers
PRO
0
210
技術負債による事業の失敗はなぜ起こるのか / Why do business failures due to technical debt occur?
i35_267
0
190
エンジニアリングマネージャーはどう学んでいくのか #devsumi / How Do Engineering Managers Continue to Learn and Grow?
expajp
4
1.3k
What is DRE? - Road to SRE NEXT@広島
chanyou0311
3
630
コンテナ・K8s研修 - 後半 Kubernetes 基礎&ハンズオン【MIXI 24新卒技術研修】
mixi_engineers
PRO
1
120
テストケースの自動生成に生成AIの導入を試みた話と生成AIによる今後の期待
shift_evolve
0
180
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
24
1.8k
Testing 201, or: Great Expectations
jmmastey
33
6.9k
Building Adaptive Systems
keathley
34
2k
Why Our Code Smells
bkeepers
PRO
332
56k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
17
8.7k
A Tale of Four Properties
chriscoyier
155
22k
ParisWeb 2013: Learning to Love: Crash Course in Emotional UX Design
dotmariusz
105
6.8k
What's new in Ruby 2.0
geeforr
338
31k
The Power of CSS Pseudo Elements
geoffreycrofte
64
5.2k
Creatively Recalculating Your Daily Design Routine
revolveconf
214
11k
Raft: Consensus for Rubyists
vanstee
134
6.5k
Fireside Chat
paigeccino
25
2.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
まとめ コードの静的解析ツールはルールの統一だけでなく、コードのスコアリングも してくれる 基準となるのは ・ 凝集度 ・ 結合度 ・ 循環的複雑度
注意点 あくまでコードを多角的にみるためのもの 指標に囚われすぎるのはよくない 運用してみて、しっくりこないのであれば緩くするのもあり