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
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
【Data Engineering Summit2026_登壇資料】医療ビッグデータ×AIエージェントを支えるデータ基盤とハーネスエンジニアリング
jmdc_presentation
0
150
ブラウザとサーバーから考えるAI時代のフロントエンド監視
shogo4131
3
900
hackers_champloo_2026_tidb
makocchi
0
150
Conditional PED-ANOVA: Hyperparameter Importance in Hierarchical & Dynamic Search Spaces
pfn
PRO
0
120
実践! SRE × AI - ABEMA における AIOps -
tetsuya28
8
3k
実体験から学ぶ分析エージェントの開発と運⽤
recruitengineers
PRO
8
2.3k
WasmをRustにする
sansantech
PRO
0
240
NDIでApple Vision Proにリアルタイム映像送信
jyouryuusui
0
110
Persisting Massive Data with Rails ~Designing for 60 billion rows, and fighting the bottlenecks~ Railsで挑む大量データ永続化 〜600億件を永続化するための設計とボトルネックとの戦い〜
occhi
0
650
DGX Spark でどこまでハッキングができるのか?
kash1064
2
1.3k
「事実」を「計測」して、「解釈」する 〜AWS Lambdaのメモリ最適解の見つけ方〜
maimyyym
0
150
味覇で作るパスタが美味い - 20261001_yabaubuki.dev
livesense
PRO
0
130
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
310
The Cost Of JavaScript in 2023
addyosmani
55
10k
Amusing Abliteration
ianozsvald
1
340
How Software Deployment tools have changed in the past 20 years
geshan
2
35k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
From π to Pie charts
rasagy
1
400
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
800
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
YesSQL, Process and Tooling at Scale
rocio
174
15k
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