SlideShare a Scribd company logo
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! (20)

PDF
To successfully deliver your IT project: build your team, build your Agile it...
Jean-François Nguyen
 
PDF
Automated Developer Testing: Achievements and Challenges
Tao Xie
 
PPTX
Tech talks#6: Code Refactoring
Nguyễn Việt Khoa
 
PDF
If you want to automate, you learn to code
Alan Richardson
 
PPTX
Write tests, please
Joan López de la Franca
 
PPT
GIDS13 - Building Service for Any Clients
Lohith Goudagere Nagaraj
 
ODP
New Ideas for Old Code - Greach
HamletDRC
 
PPTX
Tech talk on code quality
Alexander Osin
 
PDF
Microservices Chaos Testing at Jet
C4Media
 
PPT
Developing a Culture of Quality Code (Midwest PHP 2020)
Scott Keck-Warren
 
PDF
Unit testing PHP apps with PHPUnit
Michelangelo van Dam
 
PPTX
Useful practices of creation automatic tests by using cucumber jvm
Anton Shapin
 
PDF
LINQ Inside
jeffz
 
PPTX
Coding Naked 2023
Caleb Jenkins
 
PPTX
Improving the Quality of Existing Software
Steven Smith
 
PPTX
Swift meetup22june2015
Claire Townend Gee
 
PPTX
Anatomy of Test Driven Development
Dhaval Shah
 
PDF
A journey to_be_a_software_craftsman
Jaehoon Oh
 
PDF
Apex Unit Testing in the Real World
Salesforce Developers
 
To successfully deliver your IT project: build your team, build your Agile it...
Jean-François Nguyen
 
Automated Developer Testing: Achievements and Challenges
Tao Xie
 
Tech talks#6: Code Refactoring
Nguyễn Việt Khoa
 
If you want to automate, you learn to code
Alan Richardson
 
Write tests, please
Joan López de la Franca
 
GIDS13 - Building Service for Any Clients
Lohith Goudagere Nagaraj
 
New Ideas for Old Code - Greach
HamletDRC
 
Tech talk on code quality
Alexander Osin
 
Microservices Chaos Testing at Jet
C4Media
 
Developing a Culture of Quality Code (Midwest PHP 2020)
Scott Keck-Warren
 
Unit testing PHP apps with PHPUnit
Michelangelo van Dam
 
Useful practices of creation automatic tests by using cucumber jvm
Anton Shapin
 
LINQ Inside
jeffz
 
Coding Naked 2023
Caleb Jenkins
 
Improving the Quality of Existing Software
Steven Smith
 
Swift meetup22june2015
Claire Townend Gee
 
Anatomy of Test Driven Development
Dhaval Shah
 
A journey to_be_a_software_craftsman
Jaehoon Oh
 
Apex Unit Testing in the Real World
Salesforce Developers
 

More from XPDays (20)

PPTX
Change the Conversation! Unleash Your Potential in a Complex World.pptx
XPDays
 
PDF
Agile Culture Transformation
XPDays
 
PDF
Re-engineering Technology to break barriers with Business
XPDays
 
PPTX
Ready, Steady, Sprint
XPDays
 
PPTX
The Whole Story of The User Story
XPDays
 
PPTX
Scrum Master Facilitation Techniques
XPDays
 
PPTX
Unit Testing in Action - C#, NUnit, and Moq
XPDays
 
PPTX
An Introduction to The Cynefin Framework
XPDays
 
PPTX
Team Mental Health
XPDays
 
PPTX
Business Analyst in the Agile Space
XPDays
 
PPTX
DevOps in action - Azure DevOps
XPDays
 
PPTX
Priotrization techniques
XPDays
 
PPTX
Scaled Agile Framework
XPDays
 
PDF
Building Team Habits
XPDays
 
PPTX
4 Keys to Success in your Agile Journey
XPDays
 
PPTX
Coaching stances
XPDays
 
PPTX
Re-focus for Agile leaders
XPDays
 
PPTX
Business Decomposition
XPDays
 
PPTX
Agile projects | Prioritization
XPDays
 
PPTX
Scaling Agile | Spotify
XPDays
 
Change the Conversation! Unleash Your Potential in a Complex World.pptx
XPDays
 
Agile Culture Transformation
XPDays
 
Re-engineering Technology to break barriers with Business
XPDays
 
Ready, Steady, Sprint
XPDays
 
The Whole Story of The User Story
XPDays
 
Scrum Master Facilitation Techniques
XPDays
 
Unit Testing in Action - C#, NUnit, and Moq
XPDays
 
An Introduction to The Cynefin Framework
XPDays
 
Team Mental Health
XPDays
 
Business Analyst in the Agile Space
XPDays
 
DevOps in action - Azure DevOps
XPDays
 
Priotrization techniques
XPDays
 
Scaled Agile Framework
XPDays
 
Building Team Habits
XPDays
 
4 Keys to Success in your Agile Journey
XPDays
 
Coaching stances
XPDays
 
Re-focus for Agile leaders
XPDays
 
Business Decomposition
XPDays
 
Agile projects | Prioritization
XPDays
 
Scaling Agile | Spotify
XPDays
 
Ad

Recently uploaded (20)

PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Ad

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