Your SlideShare is downloading. ×
Bad smells in code
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Bad smells in code

370
views

Published on

Bad smells in code, coding, dojo, refactor

Bad smells in code, coding, dojo, refactor

Published in: Technology, Education

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
370
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Bad Smells in Code CocoDojo
  • 2. Duplicated Code Extract out the common bits into theirown method (extract method) if code is in same class if two classes duplicate code, consider extract class to create a new class to hold the shared functionality.
  • 3. Long Method extract method!
  • 4. Large Class Class trying to do too much often shows up as too many instance variables.
  • 5. Long Parameter List replace parameter with method (receiver explicitly asks sender for data via sender getter method) Example: day month, year, hour minute second ==> date
  • 6. Divergent Change If you have a fixed class that does distinctly different things consider separating out the varying code into varying classes (extract class) that either subclassor are contained by the non-varying class.
  • 7. Shotgun Surgery The smell: a change in one class repeatedly requires little changes in a bunch of other classes. try to move method and move field to get all the bits into one class since they areobviously highly dependent.
  • 8. Feature Envy Method in one class uses lots of pieces from another class. move method to move it to the other class.
  • 9. Data Clumps Data that's always hanging with each other (e.g. name street zip). Extract out a class (extract class) for the data. Will help trim argument lists too since name street zip now passed as one address object.
  • 10. Primitive Obsession
  • 11. Switch Statements Use inheritance and polymorphism instead (example of this was in Fowler Chapter 1; this is one of the more difficult refactorings)
  • 12. Lazy Class
  • 13. Speculative Generality
  • 14. Temporary Field
  • 15. Message Chains