Fighting Ruby code smell


Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Fighting Ruby code smell

  1. 1. Fighting Code Smell with RubyMine Dennis Ushakov Oleg Shpynov
  2. 2. Goals of this workshop• Show available code quality tools• How do they work• Show what RubyMine can offer 2
  3. 3. Working with code 20% Write new code 80% Modify existing code: bugfixes, optimizations, etc. 3
  4. 4. Code quality tools Reek Flay Flog Roodi Dust Heckle Metrics_fu RSpec Cucumber Autotest RCov SimpleCov 4
  5. 5. Code quality tools• Static• Runtime 5
  6. 6. Static tools• Inspect your code without launching it•100% side effects free•Easy to use•Challenging to implement•Rails DSL magic kills ‘em•Ruby has no formal specification 6
  7. 7. Runtime tools• Inspect your code by launching it•100% follow the way Ruby works•Cope well with Rails DSL•MAY have side effects•Works until the very first failure 7
  8. 8. Code that smells• Runtime errors• Runtime warnings (like parens in calls etc.)• Dead code• Copy/paste• Complex method bodies• Code style violations (i.e. naming conventions, etc)• Framework pattern violations (MVC pattern violations) 8
  9. 9. Metrics• Reek – Uncommunicative name – One char name – Name ends with number – Camelcase variable – instance_of?, kind_of?, is_a? instead of polymorphism – Duplication – Long class, method, parameter list – Nested iterators 9
  10. 10. Metrics• Flog – Assignment Branch Call metrics• Saikuro – Cyclomatic complexity• Roodi – Assignment in condition – Missing else in case – Long class/module/method – Class/module/method name check – Cyclomatic complexity• Flay – Duplicates 10
  11. 11. Testing and Coverage tools• RSpec• Cucumber• Autotest• RCov, SimpleCov• Continuous integration• Heckle – Change code (if <-> unless, calls, numbers, assignments, etc.) to see if test fail 11
  12. 12. 12
  13. 13. What else can be done?All these tools use Abstract Syntax Tree, but this is not all the information that can be extracted!The main problem is Ruby object model complexityLEXICAL analysis• Lexer -> Parser -> Abstract Syntax Tree -> Control Flow Graph -> Data Flow Analysis 13
  14. 14. RubyMine• On the fly code inspections• Code duplicates• Test tools integration with graphical UI• Coverage tool integration• Everything is tightly integrated in IDE 14
  15. 15. GO AND TRY! 15
  16. 16. Thank you!• Visit us• Read about• Post bugs• Follow us on twitter @rubymine 16
  17. 17. Develop with pleasure! @oleg_s Copyrights are retained by their respective owners
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.