In this experiential workshop, we will practice doing Test Driven Development (TDD). We will follow TDD process of Red, Green, Refactor and put more focus to the Refactor part as well as utilizing Pair Programming techniques.
If you would like to start your journey of being an eXtreme Programming (XP) practitioner, this session is for you. Also, it will be very helpful if you are a developer or quality engineer.
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
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
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