Refactoring. Ruby edition.Anatoli Makarevich@makaroni4
Who am I?
Our projects look like
In next 15 minutes we will• spice up our knowledge about refactoring• look at some common smells• get acquainted with auto...
Refactoring isbut NOTwriting testschanging codereducing complexityadding new features
Refactoring != Moving backwards
To grow fast you need to grow right.
What refactoring does?ComplexityReadabilityMaintainabilityExtensibility
This is scientific!Martin Fowler, 1999
Your desk books are:
Code SmellAny symptom in the source code of aprogram that possibly indicates a deeperproblemKent Beck
Code smellsLong methodDuplicationsHeavy classStupid nameToo many paramsFeature envyUbercallbackComplex conditions
Refactoring cycleCheck testcoverageWrite testsif neededChange codeEnsure thattests passCheck overallcomplexity
Find code smellsCheck testcoverageWrite testsif neededChange codeEnsure thattests passCheck overallcomplexity
Check test coverageCheck testcoverageWrite testsif neededChange codeEnsure thattests passCheck overallcomplexity
Write new tests if neededCheck testcoverageWrite testsif neededChange codeEnsure thattests passCheck overallcomplexity
reFACTORCheck testcoverageWrite testsif neededChange codeEnsure thattests passCheck overallcomplexity
Ensure that tests passCheck testcoverageWrite testsif neededChange codeEnsure thattests passCheck overallcomplexity
Automate tests!Check testcoverageWrite testsif neededChange codeEnsure thattests passCheck overallcomplexityTravis CIJenki...
Automate complexity analysis?Check testcoverageWrite testsif neededChange codeEnsure thattests passCheck overallcomplexity
Could complexity analysis beautomated?
?How can we process code?
s(:class, :Sexp,s(:const, :Array),s(:defn, :sexp_type, s(:args), s(:call, nil, :first)),s(:defn, :sexp_body, s(:args), s(:c...
s(:class, :Sexp,s(:const, :Array),s(:defn, :sexp_type, s(:args), s(:call, nil, :first)),s(:defn, :sexp_body, s(:args), s(:c...
s(:class, :Sexp,s(:const, :Array),s(:defn, :sexp_type, s(:args), s(:call, nil, :first)),s(:defn, :sexp_body, s(:args), s(:c...
Automated analysis• Long methods• Complex class• Stupid variable name
Long methods(:class, :Sexp,s(:const, :Array),s(:defn, :sexp_type, s(:args), s(:call, nil, :first)),s(:defn, :sexp_body, s(:...
Long methods(:class, :Sexp,s(:const, :Array),s(:defn, :sexp_type, s(:args), s(:call, nil, :first)),s(:defn, :sexp_body, s(:...
Complex classs(:class, :Sexp,s(:const, :Array),s(:defn, :sexp_type, s(:args), s(:call, nil, :first)),s(:defn, :sexp_body, s...
Complex classs(:class, :Sexp,s(:const, :Array),s(:defn, :sexp_type, s(:args), s(:call, nil, :first)),s(:defn, :sexp_body, s...
Stupid variable names(:class, :HomerSimpson,s(:const, :BlahBlahBlah),s(:defn, :donuts, s(:args), s(:call, nil, :fist)),s(:d...
Automated analysis
Refactoring!=Rehacktoring@katrinyx
It is about perceptionWe READ code, NOT COMPILE it.
After this talk do:• gem install flog• gem install flay• gem install reek• flog PROJECT_PATH• flay PROJECT_PATH• reek PROJECT_...
Let’s refactor!Anatoli Makarevich@makaroni4
Upcoming SlideShare
Loading in …5
×

Рефакторинг Ruby-кода / Анатолий Макаревич (Evrone)

779 views

Published on

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
779
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
9
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Рефакторинг Ruby-кода / Анатолий Макаревич (Evrone)

  1. 1. Refactoring. Ruby edition.Anatoli Makarevich@makaroni4
  2. 2. Who am I?
  3. 3. Our projects look like
  4. 4. In next 15 minutes we will• spice up our knowledge about refactoring• look at some common smells• get acquainted with automated code analysis• become ready to refactor
  5. 5. Refactoring isbut NOTwriting testschanging codereducing complexityadding new features
  6. 6. Refactoring != Moving backwards
  7. 7. To grow fast you need to grow right.
  8. 8. What refactoring does?ComplexityReadabilityMaintainabilityExtensibility
  9. 9. This is scientific!Martin Fowler, 1999
  10. 10. Your desk books are:
  11. 11. Code SmellAny symptom in the source code of aprogram that possibly indicates a deeperproblemKent Beck
  12. 12. Code smellsLong methodDuplicationsHeavy classStupid nameToo many paramsFeature envyUbercallbackComplex conditions
  13. 13. Refactoring cycleCheck testcoverageWrite testsif neededChange codeEnsure thattests passCheck overallcomplexity
  14. 14. Find code smellsCheck testcoverageWrite testsif neededChange codeEnsure thattests passCheck overallcomplexity
  15. 15. Check test coverageCheck testcoverageWrite testsif neededChange codeEnsure thattests passCheck overallcomplexity
  16. 16. Write new tests if neededCheck testcoverageWrite testsif neededChange codeEnsure thattests passCheck overallcomplexity
  17. 17. reFACTORCheck testcoverageWrite testsif neededChange codeEnsure thattests passCheck overallcomplexity
  18. 18. Ensure that tests passCheck testcoverageWrite testsif neededChange codeEnsure thattests passCheck overallcomplexity
  19. 19. Automate tests!Check testcoverageWrite testsif neededChange codeEnsure thattests passCheck overallcomplexityTravis CIJenkins CIGitlab CI
  20. 20. Automate complexity analysis?Check testcoverageWrite testsif neededChange codeEnsure thattests passCheck overallcomplexity
  21. 21. Could complexity analysis beautomated?
  22. 22. ?How can we process code?
  23. 23. s(:class, :Sexp,s(:const, :Array),s(:defn, :sexp_type, s(:args), s(:call, nil, :first)),s(:defn, :sexp_body, s(:args), s(:call, nil, :[], s(:lit, 1..-1))))S-expressions
  24. 24. s(:class, :Sexp,s(:const, :Array),s(:defn, :sexp_type, s(:args), s(:call, nil, :first)),s(:defn, :sexp_body, s(:args), s(:call, nil, :[], s(:lit, 1..-1))))Sexp operator
  25. 25. s(:class, :Sexp,s(:const, :Array),s(:defn, :sexp_type, s(:args), s(:call, nil, :first)),s(:defn, :sexp_body, s(:args), s(:call, nil, :[], s(:lit, 1..-1))))Sexp body
  26. 26. Automated analysis• Long methods• Complex class• Stupid variable name
  27. 27. Long methods(:class, :Sexp,s(:const, :Array),s(:defn, :sexp_type, s(:args), s(:call, nil, :first)),s(:defn, :sexp_body, s(:args), s(:call, nil, :[], s(:lit, 1..-1))))Find method Sexp :defn
  28. 28. Long methods(:class, :Sexp,s(:const, :Array),s(:defn, :sexp_type, s(:args), s(:call, nil, :first)),s(:defn, :sexp_body, s(:args), s(:call, nil, :[], s(:lit, 1..-1))))Find method Sexp :defnCount sexp operators
  29. 29. Complex classs(:class, :Sexp,s(:const, :Array),s(:defn, :sexp_type, s(:args), s(:call, nil, :first)),s(:defn, :sexp_body, s(:args), s(:call, nil, :[], s(:lit, 1..-1))))Find method Sexp :class
  30. 30. Complex classs(:class, :Sexp,s(:const, :Array),s(:defn, :sexp_type, s(:args), s(:call, nil, :first)),s(:defn, :sexp_body, s(:args), s(:call, nil, :[], s(:lit, 1..-1))))Find method Sexp :classCound weights of Sexp operators
  31. 31. Stupid variable names(:class, :HomerSimpson,s(:const, :BlahBlahBlah),s(:defn, :donuts, s(:args), s(:call, nil, :fist)),s(:defn, :beersnstuff, s(:args), s(:call, nil, :[], s(:lit, 1..-1))))
  32. 32. Automated analysis
  33. 33. Refactoring!=Rehacktoring@katrinyx
  34. 34. It is about perceptionWe READ code, NOT COMPILE it.
  35. 35. After this talk do:• gem install flog• gem install flay• gem install reek• flog PROJECT_PATH• flay PROJECT_PATH• reek PROJECT_PATH
  36. 36. Let’s refactor!Anatoli Makarevich@makaroni4

×