SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Similaire à 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
 

Similaire à 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
 

Plus de 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
 

Plus de 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
 

Dernier

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 

Dernier (20)

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 

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