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
Čtvrtkon #1 - Refactoring
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Václav Novotný
June 07, 2013
Technology
46
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
64
Čtvrtkon #3 - Git
ven
0
31
Other Decks in Technology
See All in Technology
プロダクト開発から業務改善コンサルまで。事業全体へ「染み出す」ことで広がるエンジニアの可能性
ham0215
0
130
Claude Code の Sandbox 機能を Anthropic Sandbox Runtime(srt) で試そう!/lets-play-anthropic-sandbox-runtime
tomoki10
1
590
自律型AIエージェントは何を破壊するのか
kojira
0
160
200個のGitHubリポジトリを横断調査したかった
icck
0
130
2026 TECHFRESH 畢業分享會 - AI-Native 重塑軟體工程與虛擬講師
line_developers_tw
PRO
0
1k
あなたの知らないPDFのアクセシビリティ
lycorptech_jp
PRO
0
190
スキルと MCP ツール、責務をどう分けるか? AI が迷わないインターフェース設計の戦略
cdataj
1
1.1k
On-behalf-of Token exchange with AgentCore Identity
hironobuiga
2
200
「エンジニア進化論」2028年の開発完全自動化、エンジニアはどう進化するか
cyberagentdevelopers
PRO
6
5.1k
2026TECHFRESH畢業分享會 - 葬送的通靈師:化系統與用戶雜訊成行動訊號
line_developers_tw
PRO
0
1k
Disciplined Vibes: Scaling AI-Assisted Engineering
sheharyar
0
140
【セミナー資料】Claude Code をセキュアに使うための考え方と設定の勘どころ / Claude Code Webinar 20260616
masahirokawahara
2
310
Featured
See All Featured
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
420
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
560
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
310
Exploring anti-patterns in Rails
aemeredith
3
410
Music & Morning Musume
bryan
47
7.2k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
570
Automating Front-end Workflow
addyosmani
1370
210k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
250
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.8k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
270
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