2. Author
• http://twitter.com/MartynasC
• https://www.xing.com/profile/Martin_Ts
chischauskas
Martin Tschischauskas
• Diplom Technische Informatik /
Computer Engineering
• Ruby on Rails Developer
• XING AG
• Jobs Team
Martin Tschischauskas Refactoring – Does your code smell?
3. Motivation gems
Tools Conclusion
Martin Tschischauskas Refactoring – Does your code smell?
9. flog
gem install flog
find yourapp -name *.rb | xargs flog
Martin Tschischauskas Refactoring – Does your code smell?
10. flog
• ABC metrics
• computed by counting the number of assignments, branches and conditions
for a section of code
• Assignment - an explicit transfer of data into a variable
• Branch - an explicit forward program branch out of scope - a function
call, class method call, or new operator
• Condition - a logical/Boolean test
• |ABC| = sqrt((A*A)+(B*B)+(C*C))
• http://ruby.sadi.st/Flog.html
Martin Tschischauskas Refactoring – Does your code smell?
11. flay
gem install flay
find yourapp -name *.rb | xargs flay
Martin Tschischauskas Refactoring – Does your code smell?
12. flay
• DRY – Don’t Repeat yourself
• Analyzes ruby code for structural similarities
• Differences in literal values,
• Names,
• Whitespace,
• Programming style
• Are ignored
• http://ruby.sadi.st/Flay.html
Martin Tschischauskas Refactoring – Does your code smell?
13. heckle
gem install heckle
heckle Class method –t path_to_your_test –T timeout_in_seconds
Martin Tschischauskas Refactoring – Does your code smell?
14. heckle
• Mutation tester
• Changes code and checks if tests fail
• If tests still succeed
• Code is not covered
• Or code does nothing
• http://ruby.sadi.st/Heckle.html
Martin Tschischauskas Refactoring – Does your code smell?
15. reek
gem install reek
find yourapp -name *.rb | xargs reek
Martin Tschischauskas Refactoring – Does your code smell?
16. reek
• Detects code smell
• Long Method
• Large Class
• Feature Envy (using methods of different class excessively)
• Uncommunicative Name
• Long Parameter List
• Nested Iterators
• https://github.com/troessner/reek/wiki/Code-Smells
Martin Tschischauskas Refactoring – Does your code smell?
18. brakeman
• Detects possible security issues
• No configuration is needed
• Finds possible
• XSS
• SQL Injection
• …
• http://brakemanscanner.org/
Martin Tschischauskas Refactoring – Does your code smell?
19. rails_best_
practises
gem install rails_best_practises
rails_best_practices -f html
Martin Tschischauskas Refactoring – Does your code smell?
20. rails_best_
practises
• Tries to check code for rails best practises
• Move code from Controller to Model
• RESTful Conventions
• Model
• Mailer
• Migration
• …
• http://rails-bestpractices.com/
Martin Tschischauskas Refactoring – Does your code smell?
21. Code
climate
https://codeclimate.com/github/rails/rails
Martin Tschischauskas Refactoring – Does your code smell
23. Credits
http://www.flickr.com/photos/dana_moos/5495380861/sizes/o/in/photostream/
http://www.flickr.com/photos/digitalsextant/4842845805/sizes/o/in/photostream/
http://www.flickr.com/photos/seatbelt67/502255276/sizes/o/in/photostream/
Martin Tschischauskas Refactoring – Does your code smell?