Top Banner
www.jetbrains.com Fighting Code Smell with RubyMine Dennis Ushakov Oleg Shpynov
17
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Fighting Ruby code smell

www.jetbrains.com

Fighting Code Smell

with RubyMine

Dennis Ushakov

Oleg Shpynov

Page 2: Fighting Ruby code smell

2 www.jetbrains.com

Goals of this workshop

• Show available code quality tools

• How do they work

• Show what RubyMine can offer

Page 3: Fighting Ruby code smell

3 www.jetbrains.com

Working with code

20%

Write new code

80% Modify existing

code: bugfixes,

optimizations,

etc.

Page 4: Fighting Ruby code smell

4 www.jetbrains.com

Code quality tools

Reek

Flay Flog

Roodi Dust Heckle

Metrics_fu

RSpec Cucumber Autotest

RCov SimpleCov

Page 5: Fighting Ruby code smell

5 www.jetbrains.com

Code quality tools

• Static

• Runtime

Page 6: Fighting Ruby code smell

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

Page 7: Fighting Ruby code smell

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

Page 8: Fighting Ruby code smell

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)

Page 9: Fighting Ruby code smell

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

Page 10: Fighting Ruby code smell

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

Page 11: Fighting Ruby code smell

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

Page 12: Fighting Ruby code smell

12 www.jetbrains.com

Practice

Page 13: Fighting Ruby code smell

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

Page 14: Fighting Ruby code smell

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

Page 15: Fighting Ruby code smell

15 www.jetbrains.com

GO AND TRY!

jetbrains.com/ruby

Page 16: Fighting Ruby code smell

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

Page 17: Fighting Ruby code smell

www.jetbrains.com

Develop with pleasure!

[email protected] @en_dal

[email protected] @oleg_s

Copyrights are retained by their respective owners