Your SlideShare is downloading. ×
0
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean code
Clean 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

Clean code

110

Published on

Software design principles, patterns and smells.

Software design principles, patterns and smells.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
110
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
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. clean codefrom theory to practice by Luís Zamith
  • 2. @zamith
  • 3. Clean CodeTAKING YOUR PROGRAMS TO THE LAUNDRY
  • 4. My d efin ition1. Looks like you cared2. Pretty much what you expected3. Language looks as perfect fitfor problem
  • 5. circular frictionreduction device =with central axisDesign Patterns
  • 6. template method: reports bad code class Report def initialize @title = Monthly Report @text = [ Things are going, really, really well. ] end def output_report ...HTML specific stuff... end end
  • 7. template method: reports bett er coclass Report de def initialize @title = Monthly Report def output_start; end @text = [Things are going, really, reallywell.] def output_head end output_line(@title) end def output_report output_start def output_line(line) output_head raise Called abstract method: output_line @text.each do |line| end output_line(line) end def output_end; end output_end end end
  • 8. Design Principles THE THEORY BEHIND THE THEORY
  • 9. Single responsibilityOpen closedLiskov substitutionInterface segragation Uncle Bob MartinDependency inversion
  • 10. RECA PDESIGNPRINCIPLES + = CODE CLEANDESIGNPATTERNS
  • 11. Code Smells Sir, your issues have some code.
  • 12. Smell number 1long method
  • 13. TOO LONG Can’t tell what itdoes at a glance, it’s TOOO T R LONGMore than one level of C LONG nesting, probably E FATOOMore than one level of R TOO LONG abstraction, may be Flog score greater than 15, may be
  • 14. Solu tion #1Extract Method:Split method into manyauxiliary methods
  • 15. Solu tion #2Replace temp with query:Move local variablesinto methods
  • 16. Smell number 2large class
  • 17. TOO BIGNeed to scroll to know what it does, it’s O R TOO BIG TMore private methods C BIG than public, it’s E FA TOO More than seven R TOO BIG methods, probably Flog score greater than 50, may be
  • 18. Solu tion #1Extract class:If the class has multipleresponsibilities
  • 19. Solu tion #2Extract service object:If the class has manyobjects related to asingle action
  • 20. strategy pattern: reportsreport = Report.new(HTMLFormatter.new)report.output_reportreport.formatter = PlainTextFormatter.newreport.output_report
  • 21. beware ofthe god class
  • 22. Smell number 3feature envy All your features are mine
  • 23. 4Smelling feature envy: SYMPTOMS
  • 24. Smelling feature envy: Many references to the same object
  • 25. Smelling feature envy: Local variables or params that are used more than instance variables and methods
  • 26. Smelling feature envy: Methods that include a class name in their name
  • 27. Smelling feature envy:Private methods on the sameclass with the same parameter
  • 28. Solu tion #1Extract method:If possible move part of amethod to theappropriate class
  • 29. Solu tion #2Move method:Move the entire methodinto the right class
  • 30. DESIGNPRINCIPLES + = CODE CLEANDESIGNPATTERNS
  • 31. missing somestyle
  • 32. Learn the principles use the patterns Know the smells
  • 33. thanks!
  • 34. luís zamithblog.zamith.pttwitter+github: @zamith

×