CSC/ECE 517 Fall 2010/ch4 4h am: Difference between revisions
Line 41: | Line 41: | ||
===Saikuro=== | ===Saikuro=== | ||
Saikuro is a cyclomatic complexity analyzer <sup><span id="2body">[[#2foot | Saikuro is a cyclomatic complexity analyzer <sup><span id="2body">[[#2foot|[2]]]</span></sup> | ||
, which essentially counts the number of independent paths through the code <sup><span id="3body">[[#3foot | , which essentially counts the number of independent paths through the code <sup><span id="3body">[[#3foot|[3]]]</span></sup> | ||
[[Image:filename.jpg|frame|center|Message Forwarding]] | [[Image:filename.jpg|frame|center|Message Forwarding]] |
Revision as of 03:03, 16 October 2010
Static Analysis Tools for Ruby
Static analysis tools are used to create an interface between the program, analysis, and the user. These tools perform many different functions through simple commands. The results of the tools are shown in various ways; through graphs, underlines in code, pop-up text boxes, and many other possibilities. A downside to the use of static analysis tools is knowing whether or not the tool knows exactly what the coder intended. For example, a programmer may not care that the current piece of code is used in another section because it may be more important for it to be in two places, yet not important enough to become its own method.
Tools
There are a number of static analysis tools and code metrics tools that programmers use to sift through their code. The ones that appear to be most popular are described below.
Reek
"Reek v1.2.8 is a tool that examines Ruby classes, modules and methods and reports any Code Smells it finds." [1]
Code Smells
"Smells are indicators of where your code might be hard to read, maintain or evolve, rather than things that are specifically wrong. Naturally this means that Reek is looking towards your code’s future." [1] The following items describe the smells that Reek can find
- Attribute - attr, attr_reader, attr_writer, and attr_accessor raise a warning
- Class Variable - these variables are used globally and can break many places where the variable is used
- Control Couple - the most common type of control couple is a conditional statement that determines the path of execution
- Data Clump - this occurs when a group of items appear in the same fashion in classes, parameter lists, or when instance variables contain similar substrings
- Duplication - this occurs when code fragments are similar or perform similar tasks
- Irresponsible Module - these are classes and methods that do not have comments preceding them that describe the purpose
- Large Class - this is a class with a large number of variables, methods, or lines of code
- Long Method - a large number of lines of code
- Long Parameter List - a method with more than two or three parameters
- Low Cohesion
- Feature Envy - the use of other class variables or methods more times than its own class items
- Utility Function - a function that is never called within the class it is defined in, but is called within other classes
- Nested Iterators - a block of code that includes another block of code
- Simulated Polymorphism - case statements with different types in each case, comparisons using if statements of the same variable with different types, etc...
- Uncommunicative Name - names of variables, methods, or classes that don't make sense for what it is being used
Ruby version compliance
Ruby version requirement - 1.9.1, 1.8.7, 1.8.6
Installing Reek
From the command line or in eclipse, type
gem install reek
Running Reek
From the command line or in eclipse, type
reek [options] [dir_or_source_file]*
Saikuro
Saikuro is a cyclomatic complexity analyzer [2] , which essentially counts the number of independent paths through the code [3]
Image taken from http://www.link.com
Roodi
Here is what Roodi can do
Flog
Here is what Flog can do
Flay
Here is what Flay can do
Nitpick
Here is what Dust can do
Rufus
Here is what Rufus can do
Metric_fu
Here is what Metric_fu can do
Conclusion
Here it is
References
1. a,b Rutherford, K. (2010, April 26). Reek Wiki. Retrieved October 15, 2010, from Github: http://github.com/kevinrutherford/reek/wiki
2. Blut, Z. (n.d.). Saikuro:A Cyclomatic Complexity Analyzer. Retrieved October 15, 2010, from Rubyforge: http://saikuro.rubyforge.org
3. Watson, A. H., & McCabe, T. J. (1996). Structured Testing: A Testing Methodology Using the Cyclomatic Complexity Metric. National Institute of Standards and Technology, Computer Systems Laboratory. Gaithersburg: National Institute of Standards and Technology.
3. Clark, K. (n.d.). Nitpick Wiki. Retrieved October 15, 2010, from Github: http://github.com/kevinclark/nitpick/wiki
4. Ruby Sadists. (n.d.). Retrieved October 15, 2010, from Confessions of a Ruby Sadist: http://ruby.sadi.st
5. Andrews, M. (n.d.). Roodi. Retrieved October 15, 2010, from Rubyforge: http://roodi.rubyforge.org
6. Schuster, W. (2008, November 07). Static Analysis Tools Roundup: Roodi, Rufus, Reek, Flay. Retrieved October 15, 2010, from InfoQ: http://www.infoq.com/news/2008/11/static-analysis-tool-roundup
7. Sidorov, D. (2009, June 29). Static Analysis for Ruby/Python. Retrieved October 13, 2010, from Klockwork: http://www.klocwork.com/blog/2009/06/static-analysis-for-rubypython/
8. Skruggs, J. (n.d.). Metric_fu. Retrieved October 15, 2010, from Rubyforge: http://metric-fu.rubyforge.org/