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
260
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
コードの静的解析ツールを使う目的と効用
最近の解析ツールはソースコードのスコアリングもしてくれますが、それってどういう基準なの?
というお話をしました。
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
140
ソフトウェア設計についての基本認識
hihats
1
110
アジャイル開発を始める前におさえておきたいこと
hihats
0
120
AWS Lambdaの今現在
hihats
0
810
DIコンテナを学ぶ
hihats
2
410
Laravel勉強会 2016
hihats
0
1.5k
Other Decks in Technology
See All in Technology
事業成長とAI活用を止めないデータ基盤アーキテクチャの設計思想
hiracky16
0
520
穢れた技術選定について
watany
19
6.1k
発表と総括 / Presentations and Summary
ks91
PRO
0
190
生成 AI 時代にいま一度「問い合わせ」について考えてみる
kazzpapa3
1
130
壊して学ぶAWS CDK: そのcdk deployで消えるもの、残るもの
k_adachi_01
1
480
StepFunctionsとGraphRAGを活用した暗黙知活用のためのRAG基盤
yakumo
0
130
テックカンファレンス三大ステークホルダーの文化人類学 ─ 違いを認め合う関係性作り
bash0c7
1
160
複数プロダクト組織のAIネイティブ化における戦略 / AICon2026_kude
rakus_dev
0
300
AI時代のYAGNI:「爆速で無駄になった機能」からの学び / 20260720 Naoki Takahashi
shift_evolve
PRO
3
520
AIエージェントがあれば技術書なんてすぐ書けるでしょ→無理でした
watany
2
240
Oracle Exadata Database Service on Cloud@Customer X11M (ExaDB-C@C) サービス概要
oracle4engineer
PRO
2
8.5k
Multicaで30個のミニプロジェクトをAIエージェント運用して見えてきたこと
eiei114
1
630
Featured
See All Featured
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.2k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
340
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
380
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
470
Crafting Experiences
bethany
1
230
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.1k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1k
Visualization
eitanlees
152
17k
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
まとめ コードの静的解析ツールはルールの統一だけでなく、コードのスコアリングも してくれる 基準となるのは ・ 凝集度 ・ 結合度 ・ 循環的複雑度
注意点 あくまでコードを多角的にみるためのもの 指標に囚われすぎるのはよくない 運用してみて、しっくりこないのであれば緩くするのもあり