Post on 01-Sep-2014
description
Refactoring Does your code smell?
by Martin Tschischauskas
Refactoring – Does your code smell?
Author• http://twitter.com/MartynasC• https://www.xing.com/profile/
Martin_Tschischauskas
Martin Tschischauskas
Martin Tschischauskas
• Diplom Technische Informatik / Computer Engineering
• Ruby on Rails Developer• XING AG• Jobs Team
Martin Tschischauskas
gems
ConclusionTools
Motivation
Refactoring – Does your code smell?
Does your code smell?
Martin Tschischauskas
Motivation
Refactoring – Does your code smell?
Situation at work
Martin Tschischauskas
Motivation
Refactoring – Does your code smell?
Lots of articles / books
Martin Tschischauskas
Motivation
Refactoring – Does your code smell?
Refactoring – Does your code smell?
But how to start?
Martin Tschischauskas
Motivation
Refactoring – Does your code smell?
Code Sadist
Martin Tschischauskas
gems
Martin Tschischauskas
flog
gem install flog
find yourapp -name \*.rb | xargs flog
Refactoring – Does your code smell?
Martin Tschischauskas
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
Refactoring – Does your code smell?
Martin Tschischauskas
flay
gem install flay
find yourapp -name \*.rb | xargs flay
Refactoring – Does your code smell?
Martin Tschischauskas
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
Refactoring – Does your code smell?
Martin Tschischauskas
heckle
gem install heckle
heckle Class method –t path_to_your_test –T timeout_in_seconds
Refactoring – Does your code smell?
Martin Tschischauskas
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
Refactoring – Does your code smell?
Martin Tschischauskas
reek
gem install reek
find yourapp -name \*.rb | xargs reek
Refactoring – Does your code smell?
Martin Tschischauskas
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
Refactoring – Does your code smell?
Martin Tschischauskas
brakeman
gem install brakeman
brakeman yourapp
Refactoring – Does your code smell?
Martin Tschischauskas
brakeman
• Detects possible security issues• No configuration is needed• Finds possible
• XSS• SQL Injection• …
• http://brakemanscanner.org/
Refactoring – Does your code smell?
Martin Tschischauskas
rails_best_practises
gem install rails_best_practises
rails_best_practices -f html
Refactoring – Does your code smell?
Martin Tschischauskas
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/
Refactoring – Does your code smell?
Refactoring – Does your code smell
https://codeclimate.com/github/rails/rails
Martin Tschischauskas
Code climate
Martin Tschischauskas
???
Refactoring – Does your code smell?
Thank You!
Martin Tschischauskas
Credits
http://www.flickr.com/photos/dana_moos/5495380861/sizes/o/in/photostream/
http://www.flickr.com/photos/seatbelt67/502255276/sizes/o/in/photostream/
http://www.flickr.com/photos/digitalsextant/4842845805/sizes/o/in/photostream/
Refactoring – Does your code smell?