Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Čtvrtkon #1 - Refactoring
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Václav Novotný
June 07, 2013
Technology
48
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Čtvrtkon #1 - Refactoring
Václav Novotný
June 07, 2013
More Decks by Václav Novotný
See All by Václav Novotný
Čtvrtkon 06.06. 2013 - Composer
ven
1
730
Čtvrtkon #1 - Čistý kód
ven
0
66
Čtvrtkon #3 - Git
ven
0
31
Other Decks in Technology
See All in Technology
30座EKS, 180次升級淬煉的EKS Upgrade Skill 的歷程
eric8230
0
210
人間はどの意思決定を手放せるのか
kawasima
15
7.9k
SREは、MCPとAutopilotをこう使え!
kazumax55
3
940
SREの視点で考えるSIEM活用術 〜AWS環境でのセキュリティ強化〜
cscengineer
PRO
0
170
株式会社シーエーシー エンジニア向け会社紹介資料
cac
0
57k
事業課題から技術的負債に向き合う
sansantech
PRO
2
2.2k
「ピッケル本」日本語版は4.0(第6版)が出版されるべき / pickaxe4-nagoyark05
kakutani
2
270
Claude in Chrome 入門 / Introduction to Claude in Chrome
cielo1985
0
880
銀行勘定系システムにおける開発プロセス刷新×AIによる環境モダナイゼーション / Development Process Transformation and AI-Driven Environment Modernization
muit
1
2.6k
その Lambda、8分で 管理者権限まで奪われます
k1nakayama
7
3.5k
AI時代、データエンジニアが一番おもろい
genshun9
0
680
AgentCore Runtime上にAgentic Coding基盤を構築・展開する際の設計ポイントと限界点 / Design considerations and limitations when building an agentic coding platform on AgentCore Runtime
har1101
5
640
Featured
See All Featured
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Facilitating Awesome Meetings
lara
57
7.1k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.1k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Test your architecture with Archunit
thirion
2
2.4k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
570
ラッコキーワード サービス紹介資料
rakko
1
5M
Designing for Performance
lara
611
70k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
65k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Transcript
Refactoring Václav Novotný, 6. září 2012, Čtvrtkon #1 (http://www.ctvrtkon.cz)
Problém Máme špatný kód. Jak z toho ven?
Řešením je refactoring zlepšování kvality bez změny funkčnosti
Příklad špatného kódu <?php $articles = $articleRepository->findAll(); foreach ($articles as
$article) { echo $article->getTitle(); echo $article->getText(); }
Trochu vylepšený kód <?php $articles = $articleRepository->findAll(); foreach ($articles as
$article) { printArticle($article); } function printArticle(Article $article) { echo $article->getTitle(); echo $article->getText(); }
Co jsme udělali? Snížili jsme složitost programu, aniž bychom změnili
jeho funkcionalitu.
Další příklad <?php // ArticleController.php if ($article->getPublishingDate() == date('Y-m-d') &&
$article->getStatus() == 2 && count($article->getComments()) > 0) { $article->setScore(10); }
Další příklad <?php // ArticleController.php if ($article->isPublishedToday() && $article->getStatus() ==
2 && count($article->getComments()) > 0) { $article->setScore(10); }
Další příklad <?php // ArticleController.php if ($article->isPublishedToday() && $article->isPublished() &&
count($article->getComments()) > 0) { $article->setScore(10); }
Další příklad <?php // ArticleController.php if ($article->isPublishedToday() && $article->isPublished() &&
$article->hasComments()) { $article->setScore(10); }
Další příklad <?php // ArticleController.php if ($article->isPublishedToday() && $article->isPublished() &&
$article->hasComments()) { $article->promoteArticle(); }
Další příklad <?php // ArticleController.php $articlePromoter->promoteArticle($article); // ArticlePromoter.php const TOP_ARTICLE
= 10; public function promoteArticle(Article $article) { if ($article->isPublishedToday() && $article->isPublished() && $article->hasComments()) { $article->setScore(self::TOP_ARTICLE); }
Kam až mám jít? Je to hodně o citu a
o domluvě v týmu.
Existuje chytrá kniha!
None
Je ale trochu nudná
Existuje chytrý web (trochu méně nudný) http://www.sourcemaking.com
Jak poznat, kde to hnije?
Pear rozšíření PHPMD PHP Mess Detector
None
Co PHPMD dělá? Pomocí statistické analýzy kódu ukazuje místa vhodná
pro refactoring.
Code Size Rules • Cyclomatic complexity • N-path complexity •
ExcessiveMethodLength • ExcessiveClassLength • ExcessiveParameterList • ExcessivePublicCount • TooManyFields • TooManyMethods • ExcessiveClassComplexity
Design Rules • ExitExpression • EvalExpression • GotoStatement • NumberOfChildren
• DepthOfInheritance • CouplingBetweenObjects
Naming Rules • ShortVariable • LongVariable • ShortMethodName • ConstructorWithNameAsEnclosingClass
• ConstantNamingConventions • BooleanGetMethodName
Vlastní pravidla Můžete si napsat vlastní pravidla. Třída implementující rozhraní
PHP_PMD_Rule.
Refactoring
Pamatujte • nesmíte přidávat novou funkcionalitu • dělejte malé kroky
• opravdu dělejte malé kroky!
Pamatujte #2 • bez testů se refactoruje těžko • jde
o nedílnou součást vývoje • refactorovaný kód co nejčastěji začleňujte zpět do hlavní vývojové větve
Dotazy?
Děkuji za pozornost @VaclavNovotny