Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
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
0
44
Čtvrtkon #1 - Refactoring
Václav Novotný
June 07, 2013
Tweet
Share
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
61
Čtvrtkon #3 - Git
ven
0
29
Other Decks in Technology
See All in Technology
Kiro を用いたペアプロのススメ
taikis
4
1.8k
Building Serverless AI Memory with Mastra × AWS
vvatanabe
0
510
AI with TiDD
shiraji
1
270
Bedrock AgentCore Memoryの新機能 (Episode) を試してみた / try Bedrock AgentCore Memory Episodic functionarity
hoshi7_n
2
1.8k
AI との良い付き合い方を僕らは誰も知らない
asei
0
250
MySQLとPostgreSQLのコレーション / Collation of MySQL and PostgreSQL
tmtms
1
1.2k
Oracle Database@AWS:サービス概要のご紹介
oracle4engineer
PRO
1
400
Next.js 16の新機能 Cache Components について
sutetotanuki
0
180
AWSに革命を起こすかもしれない新サービス・アップデートについてのお話
yama3133
0
500
MariaDB Connector/C のcaching_sha2_passwordプラグインの仕様について
boro1234
0
1k
Oracle Database@Google Cloud:サービス概要のご紹介
oracle4engineer
PRO
1
760
AIエージェント開発と活用を加速するワークフロー自動生成への挑戦
shibuiwilliam
5
840
Featured
See All Featured
Everyday Curiosity
cassininazir
0
110
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
0
100
AI: The stuff that nobody shows you
jnunemaker
PRO
1
19
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
90
The Mindset for Success: Future Career Progression
greggifford
PRO
0
200
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
680
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
My Coaching Mixtape
mlcsv
0
13
Crafting Experiences
bethany
0
22
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
1.8k
How to Talk to Developers About Accessibility
jct
1
85
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.1k
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