SlideShare a Scribd company logo
1 of 31
Practicing Red, Green, Refactor!
Held by, Ahmed Helmy
Ahmed Helmy
@helmy204
www.linkedin.com/in/helmy204
www.github.com/helmy204
Exercise in Self Organization
Hello everyone!
Line up and organize yourself into a single file line per
programming language from the most experience to the least
experience in coding
When you are done let me know.
Development Team
When you wake up in the morning and
you come in to work, you say, “what is
the focus – are we trying to ship or are
we trying to write code?” The answer is
we are trying to ship. You’re not trying to
write code, you’re trying not to write
code.
Former Microsoft Program Manager, Chris Peters
What is eXtreme
Programming?
XP aims to produce higher quality
software using appropriate engineering
practices
Agile Software Development Methodology
Lightweight Efficient Low-risk
XP Practices
Shared
understanding
Fine-scale
feedback
Continuous
process
Programmer
welfare
XP Practices
• Fine-scale feedback
• Pair programming
• The Planning Game
• Testing
• On-site customer
• Continuous process
• Continuous integration
• Refactoring
• Small releases
• Shared understanding
• Coding standards
• Collective ownership
• Simple design
• Metaphor
• Programmer welfare
• 40 hour week
XP Practices
Let’s Discuss
What is testing? And what are the testing types?
TDD
Red, Green, Refactor
Baby-steps Kata
•Pair up
•Design a system that generates an even number.
•Ends in 2.
•Greater than 9.
•Less than 100.
•Adding both digits should result in 6.
Pair Programming
• Two people write code together on one machine
https://martinfowler.com/articles/on-pair-programming.html
FizzBuzz Kata
BREAK!
GildedRose Kata
• Clone GildedRose Kata Repository
• C#: https://github.com/NotMyself/GildedRose
• Other: https://github.com/emilybache/GildedRose-Refactoring-Kata
• Gathering Requirements (readme file)
• Add tests based on requirements
• Add tests based on code coverage report
• Refactoring
• Adding new behavior
• Extract class • Simplify arithmetic
• Extract constant strings • Simplify Booleans
• Extract constant numbers • Group related logic
• Extract methods • Rename
GildedRose Kata
• Add tests based on requirements
Do you smell something?
<code />
[Fact]
public void Given_regular_item_SellIn_and_Quality_lower()
{
IList<Item> items =
new List<Item> { new Item { Name = "Regular Item", SellIn = 15, Quality = 25 } };
Program app = new Program() { Items = items };
app.UpdateQuality();
Assert.Equal(14, items[0].SellIn);
Assert.Equal(24, items[0].Quality);
}
[Fact]
public void Given_regular_item_past_SellIn_Then_Quality_degrades_twice_as_fast()
{
IList<Item> items =
new List<Item> { new Item { Name = "Regular Item", SellIn = 0, Quality = 25 } };
Program app = new Program() { Items = items };
app.UpdateQuality();
Assert.Equal(23, item.Quality);
}
Duplicated Code!
How can we fix this duplication code smell
GildedRose Kata
• Add tests based on requirements
Let’s Discuss
Are we done yet?
Can we now safely add new functionality?
Test Coverage
• Measure how much of your code base is exercised by your unit test suite
• A code base with less than 100% coverage does not necessarily mean that the code lacks
quality.
• A code base with 100% coverage ensures only that its quality is as good as the tests that
exercise it.
• A better measure of code coverage is whether the right code is covered by tests!
• This examination will always reveal one of two outcomes
• You are missing a test
• The code is unneeded and should be deleted (NOT COMMENTED)
GildedRose Kata
• Add tests based on requirements
• Add tests based on code coverage report
Time to Refactor!
What other code smells are there?
<code />
Large Class! More responsibilities!
Program.cs
namespace GildedRose.Console
{
public class Program
{
...
}
public class Item
{
public string Name { get; set; }
public int SellIn { get; set; }
public int Quality { get; set; }
}
}
Program.cs
namespace GildedRose.Console
{
public class Program
{
…
public void UpdateQuality()
{
…
}
}
public class Item
{
…
}
}
What other code smells are there?
<code />
Magic Strings!
public void UpdateQuality()
{
for (var i = 0; i < Items.Count; i++)
{
if (Items[i].Name != "Aged Brie" && Items[i].Name != "Backstage passes to a TAFKAL80ETC concert")
{
if (Items[i].Quality > 0)
{
if (Items[i].Name != "Sulfuras, Hand of Ragnaros")
{
Items[i].Quality = Items[i].Quality - 1;
}
}
}
else
{
…
}
}
}
What other code smells are there?
<code />
Magic Numbers!
public void UpdateQuality()
{
for (var i = 0; i < Items.Count; i++)
{
if (Items[i].Name != "Aged Brie" && Items[i].Name != "Backstage passes to a TAFKAL80ETC concert")
{
…
}
else
{
if (Items[i].Quality < 50)
{
Items[i].Quality = Items[i].Quality + 1;
…
}
}
}
What other code smells are there?
<code />
Nested Conditionals! Long Function!
public void UpdateQuality()
{
for (var i = 0; i < Items.Count; i++)
{
if (item.Name != "Aged Brie" && item.Name != "Backstage passes to a TAFKAL80ETC concert")
{
if (item.Quality > 0)
{
if (item.Name != "Sulfuras, Hand of Ragnaros")
{
item.Quality = item.Quality - 1;
}
}
}
else
{
…
}
}
}
Still Complex!
Code Smells and Anti-Code Smells
Code Smells Anti-Code Smells
Mysterious name Clear naming
Duplicated code Extract function
Long method Extract function
Nested conditionals Polymorphism
Speculative generality Change function declaration
Large class Extract class
Comments Extract function
Add New Behavior
Questions
Thank You
Ahmed Helmy
@helmy204
www.linkedin.com/in/helmy204
www.github.com/helmy204

More Related Content

Similar to Practicing Red, Green, Refactor!

To successfully deliver your IT project: build your team, build your Agile it...
To successfully deliver your IT project: build your team, build your Agile it...To successfully deliver your IT project: build your team, build your Agile it...
To successfully deliver your IT project: build your team, build your Agile it...Jean-François Nguyen
 
Automated Developer Testing: Achievements and Challenges
Automated Developer Testing: Achievements and ChallengesAutomated Developer Testing: Achievements and Challenges
Automated Developer Testing: Achievements and ChallengesTao Xie
 
If you want to automate, you learn to code
If you want to automate, you learn to codeIf you want to automate, you learn to code
If you want to automate, you learn to codeAlan Richardson
 
New Ideas for Old Code - Greach
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - GreachHamletDRC
 
Tech talk on code quality
Tech talk on code qualityTech talk on code quality
Tech talk on code qualityAlexander Osin
 
Microservices Chaos Testing at Jet
Microservices Chaos Testing at JetMicroservices Chaos Testing at Jet
Microservices Chaos Testing at JetC4Media
 
Developing a Culture of Quality Code (Midwest PHP 2020)
Developing a Culture of Quality Code (Midwest PHP 2020)Developing a Culture of Quality Code (Midwest PHP 2020)
Developing a Culture of Quality Code (Midwest PHP 2020)Scott Keck-Warren
 
Unit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnitUnit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnitMichelangelo van Dam
 
Useful practices of creation automatic tests by using cucumber jvm
Useful practices of creation automatic tests by using cucumber jvmUseful practices of creation automatic tests by using cucumber jvm
Useful practices of creation automatic tests by using cucumber jvmAnton Shapin
 
LINQ Inside
LINQ InsideLINQ Inside
LINQ Insidejeffz
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing SoftwareSteven Smith
 
Anatomy of Test Driven Development
Anatomy of Test Driven DevelopmentAnatomy of Test Driven Development
Anatomy of Test Driven DevelopmentDhaval Shah
 
A journey to_be_a_software_craftsman
A journey to_be_a_software_craftsmanA journey to_be_a_software_craftsman
A journey to_be_a_software_craftsmanJaehoon Oh
 

Similar to Practicing Red, Green, Refactor! (20)

To successfully deliver your IT project: build your team, build your Agile it...
To successfully deliver your IT project: build your team, build your Agile it...To successfully deliver your IT project: build your team, build your Agile it...
To successfully deliver your IT project: build your team, build your Agile it...
 
Automated Developer Testing: Achievements and Challenges
Automated Developer Testing: Achievements and ChallengesAutomated Developer Testing: Achievements and Challenges
Automated Developer Testing: Achievements and Challenges
 
Tech talks#6: Code Refactoring
Tech talks#6: Code RefactoringTech talks#6: Code Refactoring
Tech talks#6: Code Refactoring
 
If you want to automate, you learn to code
If you want to automate, you learn to codeIf you want to automate, you learn to code
If you want to automate, you learn to code
 
Write tests, please
Write tests, pleaseWrite tests, please
Write tests, please
 
GIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any ClientsGIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any Clients
 
New Ideas for Old Code - Greach
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - Greach
 
Tech talk on code quality
Tech talk on code qualityTech talk on code quality
Tech talk on code quality
 
Microservices Chaos Testing at Jet
Microservices Chaos Testing at JetMicroservices Chaos Testing at Jet
Microservices Chaos Testing at Jet
 
Developing a Culture of Quality Code (Midwest PHP 2020)
Developing a Culture of Quality Code (Midwest PHP 2020)Developing a Culture of Quality Code (Midwest PHP 2020)
Developing a Culture of Quality Code (Midwest PHP 2020)
 
Unit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnitUnit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnit
 
Useful practices of creation automatic tests by using cucumber jvm
Useful practices of creation automatic tests by using cucumber jvmUseful practices of creation automatic tests by using cucumber jvm
Useful practices of creation automatic tests by using cucumber jvm
 
LINQ Inside
LINQ InsideLINQ Inside
LINQ Inside
 
Coding Naked 2023
Coding Naked 2023Coding Naked 2023
Coding Naked 2023
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
Kku2011
Kku2011Kku2011
Kku2011
 
Swift meetup22june2015
Swift meetup22june2015Swift meetup22june2015
Swift meetup22june2015
 
Anatomy of Test Driven Development
Anatomy of Test Driven DevelopmentAnatomy of Test Driven Development
Anatomy of Test Driven Development
 
A journey to_be_a_software_craftsman
A journey to_be_a_software_craftsmanA journey to_be_a_software_craftsman
A journey to_be_a_software_craftsman
 
Apex Unit Testing in the Real World
Apex Unit Testing in the Real WorldApex Unit Testing in the Real World
Apex Unit Testing in the Real World
 

More from XPDays

Change the Conversation! Unleash Your Potential in a Complex World.pptx
Change the Conversation! Unleash Your Potential in a Complex World.pptxChange the Conversation! Unleash Your Potential in a Complex World.pptx
Change the Conversation! Unleash Your Potential in a Complex World.pptxXPDays
 
Agile Culture Transformation
Agile Culture TransformationAgile Culture Transformation
Agile Culture TransformationXPDays
 
Re-engineering Technology to break barriers with Business
Re-engineering Technology to break barriers with BusinessRe-engineering Technology to break barriers with Business
Re-engineering Technology to break barriers with BusinessXPDays
 
Ready, Steady, Sprint
Ready, Steady, SprintReady, Steady, Sprint
Ready, Steady, SprintXPDays
 
The Whole Story of The User Story
The Whole Story of The User StoryThe Whole Story of The User Story
The Whole Story of The User StoryXPDays
 
Scrum Master Facilitation Techniques
Scrum Master Facilitation TechniquesScrum Master Facilitation Techniques
Scrum Master Facilitation TechniquesXPDays
 
Unit Testing in Action - C#, NUnit, and Moq
Unit Testing in Action - C#, NUnit, and MoqUnit Testing in Action - C#, NUnit, and Moq
Unit Testing in Action - C#, NUnit, and MoqXPDays
 
An Introduction to The Cynefin Framework
An Introduction to The Cynefin FrameworkAn Introduction to The Cynefin Framework
An Introduction to The Cynefin FrameworkXPDays
 
Team Mental Health
Team Mental HealthTeam Mental Health
Team Mental HealthXPDays
 
Business Analyst in the Agile Space
Business Analyst in the Agile SpaceBusiness Analyst in the Agile Space
Business Analyst in the Agile SpaceXPDays
 
DevOps in action - Azure DevOps
DevOps in action - Azure DevOpsDevOps in action - Azure DevOps
DevOps in action - Azure DevOpsXPDays
 
Priotrization techniques
Priotrization techniquesPriotrization techniques
Priotrization techniquesXPDays
 
Scaled Agile Framework
Scaled Agile FrameworkScaled Agile Framework
Scaled Agile FrameworkXPDays
 
Building Team Habits
Building Team HabitsBuilding Team Habits
Building Team HabitsXPDays
 
4 Keys to Success in your Agile Journey
4 Keys to Success in your Agile Journey4 Keys to Success in your Agile Journey
4 Keys to Success in your Agile JourneyXPDays
 
Coaching stances
Coaching stancesCoaching stances
Coaching stancesXPDays
 
Re-focus for Agile leaders
Re-focus for Agile leadersRe-focus for Agile leaders
Re-focus for Agile leadersXPDays
 
Business Decomposition
Business DecompositionBusiness Decomposition
Business DecompositionXPDays
 
Agile projects | Prioritization
Agile projects | PrioritizationAgile projects | Prioritization
Agile projects | PrioritizationXPDays
 
Scaling Agile | Spotify
Scaling Agile | SpotifyScaling Agile | Spotify
Scaling Agile | SpotifyXPDays
 

More from XPDays (20)

Change the Conversation! Unleash Your Potential in a Complex World.pptx
Change the Conversation! Unleash Your Potential in a Complex World.pptxChange the Conversation! Unleash Your Potential in a Complex World.pptx
Change the Conversation! Unleash Your Potential in a Complex World.pptx
 
Agile Culture Transformation
Agile Culture TransformationAgile Culture Transformation
Agile Culture Transformation
 
Re-engineering Technology to break barriers with Business
Re-engineering Technology to break barriers with BusinessRe-engineering Technology to break barriers with Business
Re-engineering Technology to break barriers with Business
 
Ready, Steady, Sprint
Ready, Steady, SprintReady, Steady, Sprint
Ready, Steady, Sprint
 
The Whole Story of The User Story
The Whole Story of The User StoryThe Whole Story of The User Story
The Whole Story of The User Story
 
Scrum Master Facilitation Techniques
Scrum Master Facilitation TechniquesScrum Master Facilitation Techniques
Scrum Master Facilitation Techniques
 
Unit Testing in Action - C#, NUnit, and Moq
Unit Testing in Action - C#, NUnit, and MoqUnit Testing in Action - C#, NUnit, and Moq
Unit Testing in Action - C#, NUnit, and Moq
 
An Introduction to The Cynefin Framework
An Introduction to The Cynefin FrameworkAn Introduction to The Cynefin Framework
An Introduction to The Cynefin Framework
 
Team Mental Health
Team Mental HealthTeam Mental Health
Team Mental Health
 
Business Analyst in the Agile Space
Business Analyst in the Agile SpaceBusiness Analyst in the Agile Space
Business Analyst in the Agile Space
 
DevOps in action - Azure DevOps
DevOps in action - Azure DevOpsDevOps in action - Azure DevOps
DevOps in action - Azure DevOps
 
Priotrization techniques
Priotrization techniquesPriotrization techniques
Priotrization techniques
 
Scaled Agile Framework
Scaled Agile FrameworkScaled Agile Framework
Scaled Agile Framework
 
Building Team Habits
Building Team HabitsBuilding Team Habits
Building Team Habits
 
4 Keys to Success in your Agile Journey
4 Keys to Success in your Agile Journey4 Keys to Success in your Agile Journey
4 Keys to Success in your Agile Journey
 
Coaching stances
Coaching stancesCoaching stances
Coaching stances
 
Re-focus for Agile leaders
Re-focus for Agile leadersRe-focus for Agile leaders
Re-focus for Agile leaders
 
Business Decomposition
Business DecompositionBusiness Decomposition
Business Decomposition
 
Agile projects | Prioritization
Agile projects | PrioritizationAgile projects | Prioritization
Agile projects | Prioritization
 
Scaling Agile | Spotify
Scaling Agile | SpotifyScaling Agile | Spotify
Scaling Agile | Spotify
 

Recently uploaded

Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 

Recently uploaded (20)

Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 

Practicing Red, Green, Refactor!

  • 1. Practicing Red, Green, Refactor! Held by, Ahmed Helmy
  • 3. Exercise in Self Organization Hello everyone! Line up and organize yourself into a single file line per programming language from the most experience to the least experience in coding When you are done let me know.
  • 4. Development Team When you wake up in the morning and you come in to work, you say, “what is the focus – are we trying to ship or are we trying to write code?” The answer is we are trying to ship. You’re not trying to write code, you’re trying not to write code. Former Microsoft Program Manager, Chris Peters
  • 5. What is eXtreme Programming? XP aims to produce higher quality software using appropriate engineering practices Agile Software Development Methodology Lightweight Efficient Low-risk
  • 7. XP Practices • Fine-scale feedback • Pair programming • The Planning Game • Testing • On-site customer • Continuous process • Continuous integration • Refactoring • Small releases • Shared understanding • Coding standards • Collective ownership • Simple design • Metaphor • Programmer welfare • 40 hour week
  • 9. Let’s Discuss What is testing? And what are the testing types?
  • 11. Baby-steps Kata •Pair up •Design a system that generates an even number. •Ends in 2. •Greater than 9. •Less than 100. •Adding both digits should result in 6.
  • 12. Pair Programming • Two people write code together on one machine https://martinfowler.com/articles/on-pair-programming.html
  • 15. GildedRose Kata • Clone GildedRose Kata Repository • C#: https://github.com/NotMyself/GildedRose • Other: https://github.com/emilybache/GildedRose-Refactoring-Kata • Gathering Requirements (readme file) • Add tests based on requirements • Add tests based on code coverage report • Refactoring • Adding new behavior • Extract class • Simplify arithmetic • Extract constant strings • Simplify Booleans • Extract constant numbers • Group related logic • Extract methods • Rename
  • 16. GildedRose Kata • Add tests based on requirements
  • 17. Do you smell something? <code /> [Fact] public void Given_regular_item_SellIn_and_Quality_lower() { IList<Item> items = new List<Item> { new Item { Name = "Regular Item", SellIn = 15, Quality = 25 } }; Program app = new Program() { Items = items }; app.UpdateQuality(); Assert.Equal(14, items[0].SellIn); Assert.Equal(24, items[0].Quality); } [Fact] public void Given_regular_item_past_SellIn_Then_Quality_degrades_twice_as_fast() { IList<Item> items = new List<Item> { new Item { Name = "Regular Item", SellIn = 0, Quality = 25 } }; Program app = new Program() { Items = items }; app.UpdateQuality(); Assert.Equal(23, item.Quality); } Duplicated Code! How can we fix this duplication code smell
  • 18. GildedRose Kata • Add tests based on requirements
  • 19. Let’s Discuss Are we done yet? Can we now safely add new functionality?
  • 20. Test Coverage • Measure how much of your code base is exercised by your unit test suite • A code base with less than 100% coverage does not necessarily mean that the code lacks quality. • A code base with 100% coverage ensures only that its quality is as good as the tests that exercise it. • A better measure of code coverage is whether the right code is covered by tests! • This examination will always reveal one of two outcomes • You are missing a test • The code is unneeded and should be deleted (NOT COMMENTED)
  • 21. GildedRose Kata • Add tests based on requirements • Add tests based on code coverage report
  • 23. What other code smells are there? <code /> Large Class! More responsibilities! Program.cs namespace GildedRose.Console { public class Program { ... } public class Item { public string Name { get; set; } public int SellIn { get; set; } public int Quality { get; set; } } } Program.cs namespace GildedRose.Console { public class Program { … public void UpdateQuality() { … } } public class Item { … } }
  • 24. What other code smells are there? <code /> Magic Strings! public void UpdateQuality() { for (var i = 0; i < Items.Count; i++) { if (Items[i].Name != "Aged Brie" && Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") { if (Items[i].Quality > 0) { if (Items[i].Name != "Sulfuras, Hand of Ragnaros") { Items[i].Quality = Items[i].Quality - 1; } } } else { … } } }
  • 25. What other code smells are there? <code /> Magic Numbers! public void UpdateQuality() { for (var i = 0; i < Items.Count; i++) { if (Items[i].Name != "Aged Brie" && Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") { … } else { if (Items[i].Quality < 50) { Items[i].Quality = Items[i].Quality + 1; … } } }
  • 26. What other code smells are there? <code /> Nested Conditionals! Long Function! public void UpdateQuality() { for (var i = 0; i < Items.Count; i++) { if (item.Name != "Aged Brie" && item.Name != "Backstage passes to a TAFKAL80ETC concert") { if (item.Quality > 0) { if (item.Name != "Sulfuras, Hand of Ragnaros") { item.Quality = item.Quality - 1; } } } else { … } } }
  • 28. Code Smells and Anti-Code Smells Code Smells Anti-Code Smells Mysterious name Clear naming Duplicated code Extract function Long method Extract function Nested conditionals Polymorphism Speculative generality Change function declaration Large class Extract class Comments Extract function