www.jetbrains.com Fighting Code Smell with RubyMine Dennis Ushakov Oleg Shpynov
www.jetbrains.com
Fighting Code Smell
with RubyMine
Dennis Ushakov
Oleg Shpynov
2 www.jetbrains.com
Goals of this workshop
• Show available code quality tools
• How do they work
• Show what RubyMine can offer
3 www.jetbrains.com
Working with code
20%
Write new code
80% Modify existing
code: bugfixes,
optimizations,
etc.
4 www.jetbrains.com
Code quality tools
Reek
Flay Flog
Roodi Dust Heckle
Metrics_fu
RSpec Cucumber Autotest
RCov SimpleCov
5 www.jetbrains.com
Code quality tools
• Static
• Runtime
6 www.jetbrains.com
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
7 www.jetbrains.com
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
8 www.jetbrains.com
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)
9 www.jetbrains.com
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
10 www.jetbrains.com
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
11 www.jetbrains.com
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
12 www.jetbrains.com
Practice
13 www.jetbrains.com
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 complexity
LEXICAL analysis
• Lexer -> Parser -> Abstract Syntax Tree -> Control Flow Graph -> Data Flow Analysis
14 www.jetbrains.com
RubyMine
• On the fly code inspections
• Code duplicates
• Test tools integration with graphical UI
• Coverage tool integration
• Everything is tightly integrated in IDE
15 www.jetbrains.com
GO AND TRY!
jetbrains.com/ruby
16 www.jetbrains.com
Thank you!
• Visit us http://www.jetbrains.com/ruby
• Read about http://blogs.jetbrains.com/ruby/
• Post bugs http://youtrack.jetbrains.net/issues/RUBY
• Follow us on twitter @rubymine
www.jetbrains.com
Develop with pleasure!
[email protected] @en_dal
[email protected] @oleg_s
Copyrights are retained by their respective owners