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
Václav Novotný
June 07, 2013
Technology
46
0
Share
Č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
62
Čtvrtkon #3 - Git
ven
0
31
Other Decks in Technology
See All in Technology
20260415_生成AIを専属DSに_自動レポート作成_ハンズオン_交通事故データ
doradora09
PRO
0
110
Rebirth of Software Craftsmanship in the AI Era
lemiorhan
PRO
4
1.8k
Eight Engineering Unit 紹介資料
sansan33
PRO
3
7.2k
Azure PortalなどにみるWebアクセシビリティ
tomokusaba
0
370
終盤で崩壊させないAI駆動開発
j5ik2o
2
2.2k
AWS認定資格は本当に意味があるのか?
nrinetcom
PRO
1
260
Code Interpreter で、AIに安全に コードを書かせる。
yokomachi
0
6.9k
Snowflake Intelligence導入で 分かった活用のコツ
wonohe
0
110
Rapid Start: Faster Internet Connections, with Ruby's Help
kazuho
2
150
2026年、知っておくべき最新 サーバレスTips10選/serverless-10-tips
slsops
13
5k
Data Hubグループ 紹介資料
sansan33
PRO
0
2.9k
The Journey of Box Building
tagomoris
4
300
Featured
See All Featured
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
180
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
210
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
520
A better future with KSS
kneath
240
18k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
320
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
230
Darren the Foodie - Storyboard
khoart
PRO
3
3.2k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
Navigating Team Friction
lara
192
16k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.4k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
730
Building AI with AI
inesmontani
PRO
1
900
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