SlideShare a Scribd company logo
1 of 19
Your Code Smells Too!
Time to Deodorize
Gino Marckx
cb pyroclastichawk - https://www.flickr.com/photos/18536761@N00/367669179
cb Iwan Gabovitch - https://www.flickr.com/photos/qubodup/4439090296
cb Iwan Gabovitch - https://www.flickr.com/photos/qubodup/4438310359
CAUTION
BAD ROAD
AHEAD
CAUTION
BAD CODE
AHEAD
public class Person {
public String m_name;
public String m_street;
public String m_zip;
public String m_city;
public String m_province;
public String m_country;
public Person(String name, String country) { ... }
public Person(String name, String town, String country) { ... }
public Person(String name, String s, String z, String c, String p,
String country) { ... } 

public void add(Person person) { ... }
public final List getFriends() { ... }
public double between(Person person) { ... }
public Person closestFriend() { ... }
}
The Wallaroo Prints © 2011
public class Person {
public String name;
public Address address;
public Person(String name, Address address) { ... }
public void addFriend(Person person) { ... }
public List<Person> getFriends() { ... }
/**
* Find the friend who lives closest.
*
* @return the friend who lives closest
* @throws NoSuchElementException in case this person has no friends
*/
public Person getNearestFriend() { ... }
}
• Meaningful names
• Excessive use of literals
• Long parameter list
• Excessively short identifiers
• Feature envy
• Readability
• Maintainability
• Velocity
public class Address {
public Address(String country) { ... }
public Address(String city, String country) { ... }
public Address(String street, String postalCode, String city,
String state, String country) { ... }
public String getStreet() { ... }
public String getPostalCode() { ... }
public String getCity() { ... }
public String getState() { ... }
public String getCountry() { ... }
public Point getGeographicalLocation() { ... }
/**
* Calculate the distance in kilometres to another address.
*
* @param anotherAddress the other address to calculate the distance to
* @return the distance in kilometres between this address and the other
* address
* @throws IllegalArgumentException when location of either address is
* unknown
*/
public double distanceTo(Address anotherAddress) { ... }
}
http://www.zazzle.ca/comments_a_deodorant_to_mask_code_smells_tshirt-235182622652051339
The Wallaroo Prints © 2011
public class AddressBuilder {
public AddressBuilder(AddressLocator addressLocator) { ... }
public AddressBuilder() { ... }
public AddressBuilder withCountry(String country) { ... }
public AddressBuilder withStreet(String street) { ... }
public AddressBuilder withCity(String city) { ... }
public AddressBuilder withPostalCode(String postalCode) { ... }
public AddressBuilder withState(String state) { ... }
public Address build() throws UnknownGeographicalLocation { ... }
}
public class Address {
Address(AddressLocator locator, String street, String zipCode,
String city, String state, String country) { ... }
...
public Distance distanceTo(Address anotherAddress) { ... }
}
public class AddressTest {
public AddressLocator createMockLocatorWithPolandCentreOfTheUniverse() {
... }
@Test
public void testDistanceTo() throws Throwable {
AddressBuilder builder = new AddressBuilder(
createMockLocatorWithPolandCentreOfTheUniverse());
Address polishAddress = builder.withCountry("Poland").build(),
canadianAddress = builder.withCountry("Canada").build();
assertEquals(new Distance(1000, Distance.Unit.KILOMETRE),
polishAddress.distanceTo(canadianAddress));
}
}
• Dependency inversion
• Excessive use of literals
• Long parameter list
• Feature envy
• Testability
• Maintainability
• Velocity
Velocity
Testability
Maintainability
Build Software

The Right Way
… to be agile
Thank you!
Gino Marckx
Director, Agile Competency Center

More Related Content

More from Gino Marckx (8)

Measuring outcomes... or how to get meaningful metrics
Measuring outcomes... or how to get meaningful metricsMeasuring outcomes... or how to get meaningful metrics
Measuring outcomes... or how to get meaningful metrics
 
Building powerful roadmaps
Building powerful roadmapsBuilding powerful roadmaps
Building powerful roadmaps
 
Increase your coaching capacity
Increase your coaching capacityIncrease your coaching capacity
Increase your coaching capacity
 
Don't go Agile unless you know why
Don't go Agile unless you know whyDon't go Agile unless you know why
Don't go Agile unless you know why
 
Why agile doesn't work in your organization
Why agile doesn't work in your organizationWhy agile doesn't work in your organization
Why agile doesn't work in your organization
 
Quadrants of Effectiveness v2.0
Quadrants of Effectiveness v2.0Quadrants of Effectiveness v2.0
Quadrants of Effectiveness v2.0
 
Both Sides
Both SidesBoth Sides
Both Sides
 
Pomodoro Show
Pomodoro ShowPomodoro Show
Pomodoro Show
 

Recently uploaded

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
+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
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Recently uploaded (20)

%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
+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...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 

Your code smells too! Time to deodorize

  • 1. Your Code Smells Too! Time to Deodorize Gino Marckx
  • 2. cb pyroclastichawk - https://www.flickr.com/photos/18536761@N00/367669179
  • 3. cb Iwan Gabovitch - https://www.flickr.com/photos/qubodup/4439090296
  • 4. cb Iwan Gabovitch - https://www.flickr.com/photos/qubodup/4438310359
  • 7. public class Person { public String m_name; public String m_street; public String m_zip; public String m_city; public String m_province; public String m_country; public Person(String name, String country) { ... } public Person(String name, String town, String country) { ... } public Person(String name, String s, String z, String c, String p, String country) { ... } 
 public void add(Person person) { ... } public final List getFriends() { ... } public double between(Person person) { ... } public Person closestFriend() { ... } }
  • 9. public class Person { public String name; public Address address; public Person(String name, Address address) { ... } public void addFriend(Person person) { ... } public List<Person> getFriends() { ... } /** * Find the friend who lives closest. * * @return the friend who lives closest * @throws NoSuchElementException in case this person has no friends */ public Person getNearestFriend() { ... } }
  • 10. • Meaningful names • Excessive use of literals • Long parameter list • Excessively short identifiers • Feature envy • Readability • Maintainability • Velocity
  • 11. public class Address { public Address(String country) { ... } public Address(String city, String country) { ... } public Address(String street, String postalCode, String city, String state, String country) { ... } public String getStreet() { ... } public String getPostalCode() { ... } public String getCity() { ... } public String getState() { ... } public String getCountry() { ... } public Point getGeographicalLocation() { ... } /** * Calculate the distance in kilometres to another address. * * @param anotherAddress the other address to calculate the distance to * @return the distance in kilometres between this address and the other * address * @throws IllegalArgumentException when location of either address is * unknown */ public double distanceTo(Address anotherAddress) { ... } }
  • 14. public class AddressBuilder { public AddressBuilder(AddressLocator addressLocator) { ... } public AddressBuilder() { ... } public AddressBuilder withCountry(String country) { ... } public AddressBuilder withStreet(String street) { ... } public AddressBuilder withCity(String city) { ... } public AddressBuilder withPostalCode(String postalCode) { ... } public AddressBuilder withState(String state) { ... } public Address build() throws UnknownGeographicalLocation { ... } } public class Address { Address(AddressLocator locator, String street, String zipCode, String city, String state, String country) { ... } ... public Distance distanceTo(Address anotherAddress) { ... } }
  • 15. public class AddressTest { public AddressLocator createMockLocatorWithPolandCentreOfTheUniverse() { ... } @Test public void testDistanceTo() throws Throwable { AddressBuilder builder = new AddressBuilder( createMockLocatorWithPolandCentreOfTheUniverse()); Address polishAddress = builder.withCountry("Poland").build(), canadianAddress = builder.withCountry("Canada").build(); assertEquals(new Distance(1000, Distance.Unit.KILOMETRE), polishAddress.distanceTo(canadianAddress)); } }
  • 16. • Dependency inversion • Excessive use of literals • Long parameter list • Feature envy • Testability • Maintainability • Velocity
  • 18. Build Software
 The Right Way … to be agile
  • 19. Thank you! Gino Marckx Director, Agile Competency Center