SlideShare a Scribd company logo
Refactoring
Does your code smell?
 by Martin Tschischauskas
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?
Motivation                                             gems


                  Tools                      Conclusion


Martin Tschischauskas     Refactoring – Does your code smell?
Motivation

Does your code smell?




Martin Tschischauskas   Refactoring – Does your code smell?
Motivation

Situation at work




Martin Tschischauskas   Refactoring – Does your code smell?
Motivation

Lots of articles / books




Martin Tschischauskas   Refactoring – Does your code smell?
Motivation

But how to start?




Martin Tschischauskas   Refactoring – Does your code smell?
gems
Code Sadist




Martin Tschischauskas   Refactoring – Does your code smell?
flog

gem install flog

find yourapp -name *.rb | xargs flog




Martin Tschischauskas                   Refactoring – Does your code smell?
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?
flay

gem install flay

find yourapp -name *.rb | xargs flay




Martin Tschischauskas                   Refactoring – Does your code smell?
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?
heckle

gem install heckle

heckle Class method –t path_to_your_test –T timeout_in_seconds




Martin Tschischauskas            Refactoring – Does your code smell?
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?
reek

gem install reek

find yourapp -name *.rb | xargs reek




Martin Tschischauskas               Refactoring – Does your code smell?
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?
brakeman


gem install brakeman

brakeman yourapp




Martin Tschischauskas   Refactoring – Does your code smell?
brakeman


• Detects possible security issues
• No configuration is needed
• Finds possible
    • XSS
    • SQL Injection
    • …

• http://brakemanscanner.org/




Martin Tschischauskas                Refactoring – Does your code smell?
rails_best_
                                                                          practises



gem install rails_best_practises

rails_best_practices -f html




Martin Tschischauskas              Refactoring – Does your code smell?
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?
Code
                                                               climate
https://codeclimate.com/github/rails/rails




Martin Tschischauskas     Refactoring – Does your code smell
???




Thank
You!
Martin Tschischauskas   Refactoring – Does your code smell?
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?

More Related Content

Viewers also liked (12)

PPTX
Refactoring for design smells
Ganesh Samarthyam
 
PDF
Code Smells and Its type (With Example)
Anshul Vinayak
 
PPTX
Code smells and remedies
Md.Mojibul Hoque
 
PPTX
Refaktoryzacja kodu w języku PHP
DevCastZone
 
ODP
Clean code and refactoring
Yuriy Gerasimov
 
KEY
Clean code and Code Smells
Mario Sangiorgio
 
PPT
Refactoring Tips by Martin Fowler
Igor Crvenov
 
PDF
Code Refactoring
kim.mens
 
PPTX
Code refactoring
Lalit Kale
 
PDF
Code Refactoring
Yu-Chih Lin
 
PDF
Code Smells and Refactoring
Stanly Lau
 
PPT
The Smells Of Bad Design
guest446c0
 
Refactoring for design smells
Ganesh Samarthyam
 
Code Smells and Its type (With Example)
Anshul Vinayak
 
Code smells and remedies
Md.Mojibul Hoque
 
Refaktoryzacja kodu w języku PHP
DevCastZone
 
Clean code and refactoring
Yuriy Gerasimov
 
Clean code and Code Smells
Mario Sangiorgio
 
Refactoring Tips by Martin Fowler
Igor Crvenov
 
Code Refactoring
kim.mens
 
Code refactoring
Lalit Kale
 
Code Refactoring
Yu-Chih Lin
 
Code Smells and Refactoring
Stanly Lau
 
The Smells Of Bad Design
guest446c0
 

Similar to Refactoring code smell (19)

PPTX
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...
Theo Jungeblut
 
PPTX
Clean Code Part III - Craftsmanship at SoCal Code Camp
Theo Jungeblut
 
PPTX
Badneedles
dimisec
 
PDF
Effective code reviews
Sebastian Marek
 
PPTX
Using Tomorrow's CSS Today
Brian Graves
 
PDF
High Performance Object Pascal Code on Servers (at EKON 22)
Arnaud Bouchez
 
PPTX
Code samples that actually compile - Clare Macrae
Clare Macrae
 
PPTX
First impressions of SparkR: our own machine learning algorithm
InfoFarm
 
PPTX
Clean Code III - Software Craftsmanship
Theo Jungeblut
 
PDF
Ecmascript - Versão extendida
Fernanda Bernardo
 
ODP
DevOps, CLI, APIs, Oh My! Security Gone Agile
Matt Tesauro
 
PDF
From legacy to DDD
Andrzej Krzywda
 
PDF
Effective code reviews
Sebastian Marek
 
PDF
Feature Hashing for Scalable Machine Learning with Nick Pentreath
Spark Summit
 
PDF
Feature Hashing for Scalable Machine Learning with Nick Pentreath
Spark Summit
 
PPTX
Feature Hashing for Scalable Machine Learning: Spark Summit East talk by Nick...
Spark Summit
 
PDF
What is quality code? From cruft to craft
Nick DeNardis
 
PPTX
Reducing Bugs With Static Code Analysis php tek 2025
Scott Keck-Warren
 
PPTX
Old code doesn't stink
Martin Gutenbrunner
 
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...
Theo Jungeblut
 
Clean Code Part III - Craftsmanship at SoCal Code Camp
Theo Jungeblut
 
Badneedles
dimisec
 
Effective code reviews
Sebastian Marek
 
Using Tomorrow's CSS Today
Brian Graves
 
High Performance Object Pascal Code on Servers (at EKON 22)
Arnaud Bouchez
 
Code samples that actually compile - Clare Macrae
Clare Macrae
 
First impressions of SparkR: our own machine learning algorithm
InfoFarm
 
Clean Code III - Software Craftsmanship
Theo Jungeblut
 
Ecmascript - Versão extendida
Fernanda Bernardo
 
DevOps, CLI, APIs, Oh My! Security Gone Agile
Matt Tesauro
 
From legacy to DDD
Andrzej Krzywda
 
Effective code reviews
Sebastian Marek
 
Feature Hashing for Scalable Machine Learning with Nick Pentreath
Spark Summit
 
Feature Hashing for Scalable Machine Learning with Nick Pentreath
Spark Summit
 
Feature Hashing for Scalable Machine Learning: Spark Summit East talk by Nick...
Spark Summit
 
What is quality code? From cruft to craft
Nick DeNardis
 
Reducing Bugs With Static Code Analysis php tek 2025
Scott Keck-Warren
 
Old code doesn't stink
Martin Gutenbrunner
 
Ad

Recently uploaded (20)

PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
July Patch Tuesday
Ivanti
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Ad

Refactoring code smell

  • 1. Refactoring Does your code smell? by Martin Tschischauskas
  • 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?
  • 4. Motivation Does your code smell? Martin Tschischauskas Refactoring – Does your code smell?
  • 5. Motivation Situation at work Martin Tschischauskas Refactoring – Does your code smell?
  • 6. Motivation Lots of articles / books Martin Tschischauskas Refactoring – Does your code smell?
  • 7. Motivation But how to start? Martin Tschischauskas Refactoring – Does your code smell?
  • 8. gems Code Sadist 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?
  • 17. brakeman gem install brakeman brakeman yourapp 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
  • 22. ??? Thank You! 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?

Editor's Notes

  • #7: "http://www.amazon.de/gp/product/0321604814/ref=as_li_ss_tl?ie=UTF8&camp=1638&creative=19454&creativeASIN=0321604814&linkCode=as2&tag=woweffekt-21"
  • #8: "http://www.amazon.de/gp/product/0321604814/ref=as_li_ss_tl?ie=UTF8&camp=1638&creative=19454&creativeASIN=0321604814&linkCode=as2&tag=woweffekt-21"