Fighting Ruby code smell
-
Upload
olegshpynov -
Category
Technology
-
view
4.622 -
download
1
Transcript of Fighting Ruby code smell
![Page 1: Fighting Ruby code smell](https://reader033.fdocuments.in/reader033/viewer/2022052619/5555aa9fd8b42afe5d8b4727/html5/thumbnails/1.jpg)
www.jetbrains.com
Fighting Code Smell
with RubyMine
Dennis Ushakov
Oleg Shpynov
![Page 2: Fighting Ruby code smell](https://reader033.fdocuments.in/reader033/viewer/2022052619/5555aa9fd8b42afe5d8b4727/html5/thumbnails/2.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022052619/5555aa9fd8b42afe5d8b4727/html5/thumbnails/3.jpg)
3 www.jetbrains.com
Working with code
20%
Write new code
80% Modify existing
code: bugfixes,
optimizations,
etc.
![Page 4: Fighting Ruby code smell](https://reader033.fdocuments.in/reader033/viewer/2022052619/5555aa9fd8b42afe5d8b4727/html5/thumbnails/4.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022052619/5555aa9fd8b42afe5d8b4727/html5/thumbnails/5.jpg)
5 www.jetbrains.com
Code quality tools
• Static
• Runtime
![Page 6: Fighting Ruby code smell](https://reader033.fdocuments.in/reader033/viewer/2022052619/5555aa9fd8b42afe5d8b4727/html5/thumbnails/6.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022052619/5555aa9fd8b42afe5d8b4727/html5/thumbnails/7.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022052619/5555aa9fd8b42afe5d8b4727/html5/thumbnails/8.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022052619/5555aa9fd8b42afe5d8b4727/html5/thumbnails/9.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022052619/5555aa9fd8b42afe5d8b4727/html5/thumbnails/10.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022052619/5555aa9fd8b42afe5d8b4727/html5/thumbnails/11.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022052619/5555aa9fd8b42afe5d8b4727/html5/thumbnails/12.jpg)
12 www.jetbrains.com
Practice
![Page 13: Fighting Ruby code smell](https://reader033.fdocuments.in/reader033/viewer/2022052619/5555aa9fd8b42afe5d8b4727/html5/thumbnails/13.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022052619/5555aa9fd8b42afe5d8b4727/html5/thumbnails/14.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022052619/5555aa9fd8b42afe5d8b4727/html5/thumbnails/15.jpg)
15 www.jetbrains.com
GO AND TRY!
jetbrains.com/ruby
![Page 16: Fighting Ruby code smell](https://reader033.fdocuments.in/reader033/viewer/2022052619/5555aa9fd8b42afe5d8b4727/html5/thumbnails/16.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022052619/5555aa9fd8b42afe5d8b4727/html5/thumbnails/17.jpg)
www.jetbrains.com
Develop with pleasure!
[email protected] @en_dal
[email protected] @oleg_s
Copyrights are retained by their respective owners