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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
96
アジャイル開発を始める前におさえておきたいこと
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
顧客の言葉を、そのまま信じない勇気
yamatai1212
1
370
顧客との商談議事録をみんなで読んで顧客解像度を上げよう
shibayu36
0
340
登壇駆動学習のすすめ — CfPのネタの見つけ方と書くときに意識していること
bicstone
3
130
Red Hat OpenStack Services on OpenShift
tamemiya
0
140
プロダクト成長を支える開発基盤とスケールに伴う課題
yuu26
4
1.4k
生成AIを活用した音声文字起こしシステムの2つの構築パターンについて
miu_crescent
PRO
3
230
1,000 にも届く AWS Organizations 組織のポリシー運用をちゃんとしたい、という話
kazzpapa3
0
190
猫でもわかるKiro CLI(セキュリティ編)
kentapapa
0
120
AWS DevOps Agent x ECS on Fargate検証 / AWS DevOps Agent x ECS on Fargate
kinunori
2
230
データの整合性を保ちたいだけなんだ
shoheimitani
8
3.2k
コスト削減から「セキュリティと利便性」を担うプラットフォームへ
sansantech
PRO
3
1.6k
こんなところでも(地味に)活躍するImage Modeさんを知ってるかい?- Image Mode for OpenShift -
tsukaman
1
170
Featured
See All Featured
The Cult of Friendly URLs
andyhume
79
6.8k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.2k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
150
Deep Space Network (abreviated)
tonyrice
0
67
Paper Plane (Part 1)
katiecoart
PRO
0
4.3k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
190
GraphQLとの向き合い方2022年版
quramy
50
14k
Producing Creativity
orderedlist
PRO
348
40k
Building Adaptive Systems
keathley
44
2.9k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.3k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
290
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
180
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
まとめ コードの静的解析ツールはルールの統一だけでなく、コードのスコアリングも してくれる 基準となるのは ・ 凝集度 ・ 結合度 ・ 循環的複雑度
注意点 あくまでコードを多角的にみるためのもの 指標に囚われすぎるのはよくない 運用してみて、しっくりこないのであれば緩くするのもあり