<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Pysatosk</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Pysatosk"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Pysatosk"/>
	<updated>2026-09-18T23:56:21Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83091</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83091"/>
		<updated>2014-02-10T05:53:15Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Why is static analysis important? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools. Here are links to other pages that address the same topic [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2010/ch4_4h_sk one], [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2010/ch4_4h_am two] and a link to the [https://docs.google.com/a/ncsu.edu/document/d/1PEx2x5F7pJkyfeVRwV8CEDarZKmoXrQyKI1fGgBef00/edit writeup page].&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. [http://en.wikipedia.org/wiki/Software_bug Bugs] can be defects in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
[[File:Analysis Diagram.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
* False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
* True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
* True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
* False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
* False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
* Precision = TP/ (FP+TP) OR Precision = 1 - FPR&lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to [http://en.wikipedia.org/wiki/Don%27t_repeat_yourself DRY] principle.  Flay uses [http://rubyforge.org/forum/forum.php?forum_id=27971 sexp_processor] and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [http://docs.seattlerb.org/flay/README_txt.html Flay]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Information regarding some other tools for removing repeated code can be found on this [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html page]. Just gem install flay, and then flay *.rb to get playing with Flay.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
'''To Install Flay''': gem install flay&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's  [http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw ABC] (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the  [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67 source code]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
====Example==== &lt;br /&gt;
Report from Flog looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Total score = 211.720690020501&lt;br /&gt;
   &lt;br /&gt;
  WatchR#analyze_entry: (34.2)&lt;br /&gt;
     9.8: assignment&lt;br /&gt;
     7.0: branch&lt;br /&gt;
     4.5: mark_host_last_seen&lt;br /&gt;
     3.2: pattern&lt;br /&gt;
     2.8: []&lt;br /&gt;
     2.8: is_event?&lt;br /&gt;
     2.0: alert_type&lt;br /&gt;
     2.0: alert_target&lt;br /&gt;
     1.8: alert_msg&lt;br /&gt;
     1.8: notify&lt;br /&gt;
     1.6: event_notify?&lt;br /&gt;
     1.3: notify_log&lt;br /&gt;
     1.3: join&lt;br /&gt;
     1.3: split&lt;br /&gt;
     1.3: each&lt;br /&gt;
     1.3: now&lt;br /&gt;
     1.3: each_value&lt;br /&gt;
     1.3: record_host_if_unknown&lt;br /&gt;
     0.4: lit_fixnum&lt;br /&gt;
  WatchR#event_threshold_reached?: (31.6)&lt;br /&gt;
    21.3: []&lt;br /&gt;
     2.6: branch&lt;br /&gt;
     1.8: tv_sec&lt;br /&gt;
     1.6: -&lt;br /&gt;
     1.5: length&lt;br /&gt;
     1.4: &amp;gt;&lt;br /&gt;
     1.4: assignment&lt;br /&gt;
     1.3: &amp;gt;=&lt;br /&gt;
     1.3: mark_alert_last_seen&lt;br /&gt;
     1.3: delete_if&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''To install Flog''': gem install flog.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29 page].&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
[https://github.com/metricfu/metric_fu Metric_fu] is a nice gem which internally uses [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2014/ch1_1w1b_np#Saikuro Saikuro], [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2014/ch1_1w1b_np#Flog Flog], [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2014/ch1_1w1b_np#Flay Flay], [http://rubygems.org/gems/rcov Rcov], [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2014/ch1_1w1b_np#Reek Reek], [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2014/ch1_1w1b_np#Roodi Roodi], [https://github.com/danmayer/churn Churn], [http://rubygems.org/gems/rails_best_practices RailsBestPractices] and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Metric_fu ====&lt;br /&gt;
Metric_fu combines several different tools that provide reports that show which parts of your code might need extra work. So, if you are looking to find out which part of your code requires refactoring running metric_fu would be of great use. Metric_fu also provides individual results generated by each of these tools and looking at these results the user could decide which tool to run in detail to identify the problem areas in the code.&lt;br /&gt;
&lt;br /&gt;
=== Reek ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
[https://github.com/troessner/reek Reek] is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the [http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm code smells]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* '''Control Coupling''' - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
Given a source file demo.rb containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;class Dirty&lt;br /&gt;
  # This method smells of :reek:NestedIterators but ignores them&lt;br /&gt;
  def awful(x, y, offset = 0, log = false)&lt;br /&gt;
    puts @screen.title&lt;br /&gt;
    @screen = widgets.map {|w| w.each {|key| key += 3}}&lt;br /&gt;
    puts @screen.contents&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reek will report the following code smells in this file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ reek demo.rb&lt;br /&gt;
  spec/samples/demo/demo.rb -- 6 warnings:&lt;br /&gt;
  Dirty has no descriptive comment (IrresponsibleModule)&lt;br /&gt;
  Dirty#awful has 4 parameters (LongParameterList)&lt;br /&gt;
  Dirty#awful has boolean parameter 'log' (ControlCouple)&lt;br /&gt;
  Dirty#awful has the parameter name 'x' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the parameter name 'y' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the variable name 'w' (UncommunicativeName)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
[https://github.com/roodi/roodi Roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the [http://en.wikipedia.org/wiki/Cyclomatic_complexity cyclomatic complexity] of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
Roodi's output looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:152 - Block cyclomatic complexity is 11.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/rake/verify_rcov.rb:37 - Block cyclomatic complexity is 6.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/be.rb:57 - Method name &amp;quot;match_or_compare&amp;quot; has a cyclomatic complexity is 12.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:12 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 9.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/have.rb:28 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 11.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/expectations/errors.rb:6 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:186 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/expectations/differs/default.rb:20 - Method name &amp;quot;diff_as_string&amp;quot; has 21 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:35 - Method name &amp;quot;failure_message&amp;quot; has 24 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:31 - Method name &amp;quot;_message&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:35 - Method name &amp;quot;_pretty_print&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
[http://rufus.rubyforge.org/rufus-treechecker/files/README_txt.html Rufus] is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation. It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the [http://ruote.rubyforge.org/ route] open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:require 'rubygems'&lt;br /&gt;
:require 'rufus-treechecker'&lt;br /&gt;
&lt;br /&gt;
:tc = Rufus::TreeChecker.new do&lt;br /&gt;
:  exclude_fvcall :abort&lt;br /&gt;
:  exclude_fvcall :exit, :exit!&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:tc.check(&amp;quot;1 + 1; abort&amp;quot;)               # will raise a SecurityError&lt;br /&gt;
:tc.check(&amp;quot;puts (1..10).to_a.inspect&amp;quot;)  # OK&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
==== Introduction ====&lt;br /&gt;
[http://saikuro.rubyforge.org/ Saikuro] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code. Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
To run Saikuro: ~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
[[File:Saikuro_users_out.png]]&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby [https://github.com/bbatsov/ruby-style-guide style guide] recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
== User scenarios and tools ==&lt;br /&gt;
From our study of the tools, we think that each tool has its own usability. Under different circumstances, one would find a different tool useful. Thus, it would be useful to have a mapping of scenarios and the appropriate tool to use in that case. We would like to suggest the following mapping:&lt;br /&gt;
{| class=”wikitable” border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! '''Scenario'''&lt;br /&gt;
! '''Tool''' &lt;br /&gt;
! '''Explanation'''&lt;br /&gt;
|- &lt;br /&gt;
| '''Beginning of coding activity'''&lt;br /&gt;
| Roodi &lt;br /&gt;
| Roodi warns against bad design and we would prefer being warned about design problems early into the development rather than later.&lt;br /&gt;
|- &lt;br /&gt;
| '''When first few classes or modules are being fleshed out''' &lt;br /&gt;
| Rubocop&lt;br /&gt;
| To get familiarized with the stylistic conventions. Typically best for new developers.&lt;br /&gt;
|- &lt;br /&gt;
| '''Quick analysis of code after basic functionality implemented and tested''' &lt;br /&gt;
| Metric fu &lt;br /&gt;
| So that we can code, test and analyze. Then depending on the tool that returned most warnings, we could focus our attention on that particular aspect of the code.&lt;br /&gt;
|-&lt;br /&gt;
| '''Continuous code improvement / refactoring''' &lt;br /&gt;
| Reek, Rufus &lt;br /&gt;
| To check for code smells and potential bugs.&lt;br /&gt;
|- &lt;br /&gt;
| '''When code is large and/or you find yourself logically repeating yourself''' &lt;br /&gt;
| Flay &lt;br /&gt;
| When code base becomes large enough and you want to keep your code DRY, Flay can help detect repetition.&lt;br /&gt;
|- &lt;br /&gt;
| '''Improve readability''' &lt;br /&gt;
| Saikuro, Flog &lt;br /&gt;
| To reduce code complexity and to make code readable and ease support, especially legacy code.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Benefits of static analysis tools ==&lt;br /&gt;
In conclusion, the static analysis tools mentioned about could provide the following benefits:&lt;br /&gt;
* Code that adheres to standards and conventions.&lt;br /&gt;
* Learning of the language and object oriented concepts from the warnings generated by tools.&lt;br /&gt;
* Better readability of code.&lt;br /&gt;
* Maintainable code.&lt;br /&gt;
* Fewer defects.&lt;br /&gt;
* Reduced code complexity.&lt;br /&gt;
* Aid to refactoring.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* http://en.wikipedia.org/wiki/Software_bug&lt;br /&gt;
* http://en.wikipedia.org/wiki/Don%27t_repeat_yourself&lt;br /&gt;
* http://docs.seattlerb.org/flay/README_txt.html&lt;br /&gt;
* http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html&lt;br /&gt;
* http://www.c2.com/cgi/wiki?AbcMetric&lt;br /&gt;
* https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67&lt;br /&gt;
* http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29&lt;br /&gt;
* https://github.com/metricfu/metric_fu&lt;br /&gt;
* http://rubygems.org/gems/rcov&lt;br /&gt;
* https://github.com/danmayer/churn&lt;br /&gt;
* http://rubygems.org/gems/rails_best_practices&lt;br /&gt;
* https://github.com/troessner/reek&lt;br /&gt;
* https://github.com/roodi/roodi&lt;br /&gt;
* http://en.wikipedia.org/wiki/Cyclomatic_complexity&lt;br /&gt;
* http://rufus.rubyforge.org/rufus-treechecker/files/README_txt.html&lt;br /&gt;
* http://saikuro.rubyforge.org/&lt;br /&gt;
* https://github.com/bbatsov/ruby-style-guide&lt;br /&gt;
* https://www.ruby-toolbox.com/categories/code_metrics&lt;br /&gt;
* http://www.infoq.com/news/2008/11/static-analysis-tool-roundup&lt;br /&gt;
* http://silkandspinach.net/2008/09/23/reek-a-code-smells-detector-for-ruby/?referer=sphere_related_content/&lt;br /&gt;
* https://github.com/YorickPeterse/ruby-lint&lt;br /&gt;
* http://www.neevtech.com/blog/2011/07/04/static-code-analysis-in-ruby/&lt;br /&gt;
* http://asciicasts.com/episodes/166-metric-fu&lt;br /&gt;
* http://ruby.sadi.st/Flay.html&lt;br /&gt;
* http://silkandspinach.net/2008/10/19/reek-and-feature-envy/&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83038</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83038"/>
		<updated>2014-02-08T07:02:03Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to [http://en.wikipedia.org/wiki/Don%27t_repeat_yourself DRY] principle.  Flay uses [http://rubyforge.org/forum/forum.php?forum_id=27971 sexp_processor] and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [http://docs.seattlerb.org/flay/README_txt.htm Flay]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up.[http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html] &lt;br /&gt;
Just gem install flay, and then flay *.rb to get playing with Flay.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
'''To Install Flay''': gem install flay&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's  [http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw ABC] (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the  [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67 source code]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
====Example==== &lt;br /&gt;
Report from Flog looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Total score = 211.720690020501&lt;br /&gt;
   &lt;br /&gt;
  WatchR#analyze_entry: (34.2)&lt;br /&gt;
     9.8: assignment&lt;br /&gt;
     7.0: branch&lt;br /&gt;
     4.5: mark_host_last_seen&lt;br /&gt;
     3.2: pattern&lt;br /&gt;
     2.8: []&lt;br /&gt;
     2.8: is_event?&lt;br /&gt;
     2.0: alert_type&lt;br /&gt;
     2.0: alert_target&lt;br /&gt;
     1.8: alert_msg&lt;br /&gt;
     1.8: notify&lt;br /&gt;
     1.6: event_notify?&lt;br /&gt;
     1.3: notify_log&lt;br /&gt;
     1.3: join&lt;br /&gt;
     1.3: split&lt;br /&gt;
     1.3: each&lt;br /&gt;
     1.3: now&lt;br /&gt;
     1.3: each_value&lt;br /&gt;
     1.3: record_host_if_unknown&lt;br /&gt;
     0.4: lit_fixnum&lt;br /&gt;
  WatchR#event_threshold_reached?: (31.6)&lt;br /&gt;
    21.3: []&lt;br /&gt;
     2.6: branch&lt;br /&gt;
     1.8: tv_sec&lt;br /&gt;
     1.6: -&lt;br /&gt;
     1.5: length&lt;br /&gt;
     1.4: &amp;gt;&lt;br /&gt;
     1.4: assignment&lt;br /&gt;
     1.3: &amp;gt;=&lt;br /&gt;
     1.3: mark_alert_last_seen&lt;br /&gt;
     1.3: delete_if&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''To install Flog''': gem install flog.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29 page].&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
[https://github.com/metricfu/metric_fu Metric_fu] is a nice gem which internally uses [http://saikuro.rubyforge.org/ Saikuro], [http://ruby.sadi.st/Flog.html Flog], [http://ruby.sadi.st/Flog.html Flay], [http://rubygems.org/gems/rcov Rcov], [https://github.com/kevinrutherford/reek/ Reek], [https://github.com/martinjandrews/roodi Roodi], [https://github.com/danmayer/churn Churn], [http://rubygems.org/gems/rails_best_practices RailsBestPractices] and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Metric_fu ====&lt;br /&gt;
Metric_fu combines several different tools that provide reports that show which parts of your code might need extra work. So, if you are looking to find out which part of your code requires refactoring running metric_fu would be of great use. Metric_fu also provides individual results generated by each of these tools and looking at these results the user could decide which tool to run in detail to identify the problem areas in the code.&lt;br /&gt;
&lt;br /&gt;
=== Reek ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
[https://github.com/troessner/reek Reek] is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the [http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm code smells]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* '''Control Coupling''' - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
Given a source file demo.rb containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;class Dirty&lt;br /&gt;
  # This method smells of :reek:NestedIterators but ignores them&lt;br /&gt;
  def awful(x, y, offset = 0, log = false)&lt;br /&gt;
    puts @screen.title&lt;br /&gt;
    @screen = widgets.map {|w| w.each {|key| key += 3}}&lt;br /&gt;
    puts @screen.contents&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reek will report the following code smells in this file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ reek demo.rb&lt;br /&gt;
  spec/samples/demo/demo.rb -- 6 warnings:&lt;br /&gt;
  Dirty has no descriptive comment (IrresponsibleModule)&lt;br /&gt;
  Dirty#awful has 4 parameters (LongParameterList)&lt;br /&gt;
  Dirty#awful has boolean parameter 'log' (ControlCouple)&lt;br /&gt;
  Dirty#awful has the parameter name 'x' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the parameter name 'y' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the variable name 'w' (UncommunicativeName)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
[https://github.com/roodi/roodi Roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the [http://en.wikipedia.org/wiki/Cyclomatic_complexity cyclomatic complexity] of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
Roodi's output looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:152 - Block cyclomatic complexity is 11.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/rake/verify_rcov.rb:37 - Block cyclomatic complexity is 6.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/be.rb:57 - Method name &amp;quot;match_or_compare&amp;quot; has a cyclomatic complexity is 12.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:12 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 9.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/have.rb:28 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 11.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/expectations/errors.rb:6 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:186 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/expectations/differs/default.rb:20 - Method name &amp;quot;diff_as_string&amp;quot; has 21 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:35 - Method name &amp;quot;failure_message&amp;quot; has 24 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:31 - Method name &amp;quot;_message&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:35 - Method name &amp;quot;_pretty_print&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
[http://rufus.rubyforge.org/rufus-treechecker/files/README_txt.html Rufus] is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation. It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the [http://ruote.rubyforge.org/ route] open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:require 'rubygems'&lt;br /&gt;
:require 'rufus-treechecker'&lt;br /&gt;
&lt;br /&gt;
:tc = Rufus::TreeChecker.new do&lt;br /&gt;
:  exclude_fvcall :abort&lt;br /&gt;
:  exclude_fvcall :exit, :exit!&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:tc.check(&amp;quot;1 + 1; abort&amp;quot;)               # will raise a SecurityError&lt;br /&gt;
:tc.check(&amp;quot;puts (1..10).to_a.inspect&amp;quot;)  # OK&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
==== Introduction ====&lt;br /&gt;
[http://saikuro.rubyforge.org/ Saikuro] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code. Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
To run Saikuro: ~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
[[File:Saikuro_users_out.png]]&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
== User scenarios and tools ==&lt;br /&gt;
From our study of the tools, we think that each tool has its own usability. Under different circumstances, one would find a different tool useful. Thus, it would be useful to have a mapping of scenarios and the appropriate tool to use in that case. We would like to suggest the following mapping:&lt;br /&gt;
{| class=”wikitable” border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario&lt;br /&gt;
! Tool &lt;br /&gt;
! Explanation&lt;br /&gt;
|- &lt;br /&gt;
| Beginning of coding activity&lt;br /&gt;
| Roodi &lt;br /&gt;
| Roodi warns against bad design and we would prefer being warned about design problems early into the development rather than later.&lt;br /&gt;
|- &lt;br /&gt;
| When first few classes or modules are being fleshed out &lt;br /&gt;
| Rubocop&lt;br /&gt;
| To get familiarized with the stylistic conventions. Typically best for new developers.&lt;br /&gt;
|- &lt;br /&gt;
| Quick analysis of code after basic functionality implemented and tested &lt;br /&gt;
| Metric fu &lt;br /&gt;
| So that we can code, test and analyze. Then depending on the tool that returned most warnings, we could focus our attention on that particular aspect of the code.&lt;br /&gt;
|-&lt;br /&gt;
| Continuous code improvement / refactoring &lt;br /&gt;
| Reek, Rufus &lt;br /&gt;
| To check for code smells and potential bugs.&lt;br /&gt;
|- &lt;br /&gt;
| When code is large and/or you find yourself logically repeating yourself &lt;br /&gt;
| Flay &lt;br /&gt;
| When code base becomes large enough and you want to keep your code DRY, Flay can help detect repetition.&lt;br /&gt;
|- &lt;br /&gt;
| Improve readability &lt;br /&gt;
| Saikuro, Flog &lt;br /&gt;
| To reduce code complexity and to make code readable and ease support, especially legacy code.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Benefits of static analysis tools ==&lt;br /&gt;
In conclusion, the static analysis tools mentioned about could provide the following benefits:&lt;br /&gt;
* Code that adheres to standards and conventions.&lt;br /&gt;
* Learning of the language and object oriented concepts from the warnings generated by tools.&lt;br /&gt;
* Better readability of code.&lt;br /&gt;
* Maintainable code.&lt;br /&gt;
* Fewer defects.&lt;br /&gt;
* Reduced code complexity.&lt;br /&gt;
* Aid to refactoring.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
https://www.ruby-toolbox.com/categories/code_metrics&lt;br /&gt;
&lt;br /&gt;
http://www.infoq.com/news/2008/11/static-analysis-tool-roundup&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/09/23/reek-a-code-smells-detector-for-ruby/?referer=sphere_related_content/&lt;br /&gt;
&lt;br /&gt;
https://github.com/YorickPeterse/ruby-lint&lt;br /&gt;
&lt;br /&gt;
http://www.neevtech.com/blog/2011/07/04/static-code-analysis-in-ruby/&lt;br /&gt;
&lt;br /&gt;
http://asciicasts.com/episodes/166-metric-fu&lt;br /&gt;
&lt;br /&gt;
https://github.com/troessner/reek&lt;br /&gt;
&lt;br /&gt;
http://ruby.sadi.st/Flay.html&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/10/19/reek-and-feature-envy/&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Saikuro_users_out.png&amp;diff=83037</id>
		<title>File:Saikuro users out.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Saikuro_users_out.png&amp;diff=83037"/>
		<updated>2014-02-08T06:59:10Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: uploaded a new version of &amp;amp;quot;File:Saikuro users out.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The table is the output of a Saikuro run using the command saikuro -c -t -i app -y 0 -w 11 -e 16 -o out/, which analyzes all items in the app folder.  The other switches are explained on http://saikuro.rubyforge.org/.&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83030</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83030"/>
		<updated>2014-02-08T06:43:54Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Hyperlink to terms and references */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to [http://en.wikipedia.org/wiki/Don%27t_repeat_yourself DRY] principle.  Flay uses [http://rubyforge.org/forum/forum.php?forum_id=27971 sexp_processor] and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [http://docs.seattlerb.org/flay/README_txt.htm Flay]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up.[http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html] &lt;br /&gt;
Just gem install flay, and then flay *.rb to get playing with Flay.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
'''To Install Flay''': gem install flay&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's  [http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw ABC] (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the  [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67 source code]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
====Example==== &lt;br /&gt;
Report from Flog looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Total score = 211.720690020501&lt;br /&gt;
   &lt;br /&gt;
  WatchR#analyze_entry: (34.2)&lt;br /&gt;
     9.8: assignment&lt;br /&gt;
     7.0: branch&lt;br /&gt;
     4.5: mark_host_last_seen&lt;br /&gt;
     3.2: pattern&lt;br /&gt;
     2.8: []&lt;br /&gt;
     2.8: is_event?&lt;br /&gt;
     2.0: alert_type&lt;br /&gt;
     2.0: alert_target&lt;br /&gt;
     1.8: alert_msg&lt;br /&gt;
     1.8: notify&lt;br /&gt;
     1.6: event_notify?&lt;br /&gt;
     1.3: notify_log&lt;br /&gt;
     1.3: join&lt;br /&gt;
     1.3: split&lt;br /&gt;
     1.3: each&lt;br /&gt;
     1.3: now&lt;br /&gt;
     1.3: each_value&lt;br /&gt;
     1.3: record_host_if_unknown&lt;br /&gt;
     0.4: lit_fixnum&lt;br /&gt;
  WatchR#event_threshold_reached?: (31.6)&lt;br /&gt;
    21.3: []&lt;br /&gt;
     2.6: branch&lt;br /&gt;
     1.8: tv_sec&lt;br /&gt;
     1.6: -&lt;br /&gt;
     1.5: length&lt;br /&gt;
     1.4: &amp;gt;&lt;br /&gt;
     1.4: assignment&lt;br /&gt;
     1.3: &amp;gt;=&lt;br /&gt;
     1.3: mark_alert_last_seen&lt;br /&gt;
     1.3: delete_if&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''To install Flog''': gem install flog.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29 page].&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
[https://github.com/metricfu/metric_fu Metric_fu] is a nice gem which internally uses [http://saikuro.rubyforge.org/ Saikuro], [http://ruby.sadi.st/Flog.html Flog], [http://ruby.sadi.st/Flog.html Flay], [http://rubygems.org/gems/rcov Rcov], [https://github.com/kevinrutherford/reek/ Reek], [https://github.com/martinjandrews/roodi Roodi], [https://github.com/danmayer/churn Churn], [http://rubygems.org/gems/rails_best_practices RailsBestPractices] and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Metric_fu ====&lt;br /&gt;
Metric_fu combines several different tools that provide reports that show which parts of your code might need extra work. So, if you are looking to find out which part of your code requires refactoring running metric_fu would be of great use. Metric_fu also provides individual results generated by each of these tools and looking at these results the user could decide which tool to run in detail to identify the problem areas in the code.&lt;br /&gt;
&lt;br /&gt;
=== Reek ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
[https://github.com/troessner/reek Reek] is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the [http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm code smells]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* '''Control Coupling''' - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
Given a source file demo.rb containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;class Dirty&lt;br /&gt;
  # This method smells of :reek:NestedIterators but ignores them&lt;br /&gt;
  def awful(x, y, offset = 0, log = false)&lt;br /&gt;
    puts @screen.title&lt;br /&gt;
    @screen = widgets.map {|w| w.each {|key| key += 3}}&lt;br /&gt;
    puts @screen.contents&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reek will report the following code smells in this file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ reek demo.rb&lt;br /&gt;
  spec/samples/demo/demo.rb -- 6 warnings:&lt;br /&gt;
  Dirty has no descriptive comment (IrresponsibleModule)&lt;br /&gt;
  Dirty#awful has 4 parameters (LongParameterList)&lt;br /&gt;
  Dirty#awful has boolean parameter 'log' (ControlCouple)&lt;br /&gt;
  Dirty#awful has the parameter name 'x' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the parameter name 'y' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the variable name 'w' (UncommunicativeName)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the [http://en.wikipedia.org/wiki/Cyclomatic_complexity cyclomatic complexity] of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
Roodi's output looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:152 - Block cyclomatic complexity is 11.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/rake/verify_rcov.rb:37 - Block cyclomatic complexity is 6.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/be.rb:57 - Method name &amp;quot;match_or_compare&amp;quot; has a cyclomatic complexity is 12.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:12 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 9.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/have.rb:28 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 11.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/expectations/errors.rb:6 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:186 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/expectations/differs/default.rb:20 - Method name &amp;quot;diff_as_string&amp;quot; has 21 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:35 - Method name &amp;quot;failure_message&amp;quot; has 24 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:31 - Method name &amp;quot;_message&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:35 - Method name &amp;quot;_pretty_print&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation. It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:require 'rubygems'&lt;br /&gt;
:require 'rufus-treechecker'&lt;br /&gt;
&lt;br /&gt;
:tc = Rufus::TreeChecker.new do&lt;br /&gt;
:  exclude_fvcall :abort&lt;br /&gt;
:  exclude_fvcall :exit, :exit!&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:tc.check(&amp;quot;1 + 1; abort&amp;quot;)               # will raise a SecurityError&lt;br /&gt;
:tc.check(&amp;quot;puts (1..10).to_a.inspect&amp;quot;)  # OK&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code. Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
=== User scenarios and tools ===&lt;br /&gt;
From our study of the tools, we think that each tool has its own usability. Under different circumstances, one would find a different tool useful. Thus, it would be useful to have a mapping of scenarios and the appropriate tool to use in that case. We would like to suggest the following mapping:&lt;br /&gt;
{| class=”wikitable” border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario&lt;br /&gt;
! Tool &lt;br /&gt;
! Explanation&lt;br /&gt;
|- &lt;br /&gt;
| Beginning of coding activity&lt;br /&gt;
| Roodi &lt;br /&gt;
| Roodi warns against bad design and we would prefer being warned about design problems early into the development rather than later.&lt;br /&gt;
|- &lt;br /&gt;
| When first few classes or modules are being fleshed out &lt;br /&gt;
| Rubocop&lt;br /&gt;
| To get familiarized with the stylistic conventions. Typically best for new developers.&lt;br /&gt;
|- &lt;br /&gt;
| Quick analysis of code after basic functionality implemented and tested &lt;br /&gt;
| Metric fu &lt;br /&gt;
| So that we can code, test and analyze. Then depending on the tool that returned most warnings, we could focus our attention on that particular aspect of the code.&lt;br /&gt;
|-&lt;br /&gt;
| Continuous code improvement / refactoring &lt;br /&gt;
| Reek, Rufus &lt;br /&gt;
| To check for code smells and potential bugs.&lt;br /&gt;
|- &lt;br /&gt;
| When code is large and/or you find yourself logically repeating yourself &lt;br /&gt;
| Flay &lt;br /&gt;
| When code base becomes large enough and you want to keep your code DRY, Flay can help detect repetition.&lt;br /&gt;
|- &lt;br /&gt;
| Improve readability &lt;br /&gt;
| Saikuro, Flog &lt;br /&gt;
| To reduce code complexity and to make code readable and ease support, especially legacy code.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== References ===&lt;br /&gt;
https://www.ruby-toolbox.com/categories/code_metrics&lt;br /&gt;
&lt;br /&gt;
http://www.infoq.com/news/2008/11/static-analysis-tool-roundup&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/09/23/reek-a-code-smells-detector-for-ruby/?referer=sphere_related_content/&lt;br /&gt;
&lt;br /&gt;
https://github.com/YorickPeterse/ruby-lint&lt;br /&gt;
&lt;br /&gt;
http://www.neevtech.com/blog/2011/07/04/static-code-analysis-in-ruby/&lt;br /&gt;
&lt;br /&gt;
http://asciicasts.com/episodes/166-metric-fu&lt;br /&gt;
&lt;br /&gt;
https://github.com/troessner/reek&lt;br /&gt;
&lt;br /&gt;
http://ruby.sadi.st/Flay.html&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/10/19/reek-and-feature-envy/&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83027</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83027"/>
		<updated>2014-02-08T06:38:44Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to [http://en.wikipedia.org/wiki/Don%27t_repeat_yourself DRY] principle.  Flay uses [http://rubyforge.org/forum/forum.php?forum_id=27971 sexp_processor] and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [http://docs.seattlerb.org/flay/README_txt.htm Flay]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up.[http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html] &lt;br /&gt;
Just gem install flay, and then flay *.rb to get playing with Flay.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
'''To Install Flay''': gem install flay&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's  [http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw ABC] (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the  [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67 source code]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
====Example==== &lt;br /&gt;
Report from Flog looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Total score = 211.720690020501&lt;br /&gt;
   &lt;br /&gt;
  WatchR#analyze_entry: (34.2)&lt;br /&gt;
     9.8: assignment&lt;br /&gt;
     7.0: branch&lt;br /&gt;
     4.5: mark_host_last_seen&lt;br /&gt;
     3.2: pattern&lt;br /&gt;
     2.8: []&lt;br /&gt;
     2.8: is_event?&lt;br /&gt;
     2.0: alert_type&lt;br /&gt;
     2.0: alert_target&lt;br /&gt;
     1.8: alert_msg&lt;br /&gt;
     1.8: notify&lt;br /&gt;
     1.6: event_notify?&lt;br /&gt;
     1.3: notify_log&lt;br /&gt;
     1.3: join&lt;br /&gt;
     1.3: split&lt;br /&gt;
     1.3: each&lt;br /&gt;
     1.3: now&lt;br /&gt;
     1.3: each_value&lt;br /&gt;
     1.3: record_host_if_unknown&lt;br /&gt;
     0.4: lit_fixnum&lt;br /&gt;
  WatchR#event_threshold_reached?: (31.6)&lt;br /&gt;
    21.3: []&lt;br /&gt;
     2.6: branch&lt;br /&gt;
     1.8: tv_sec&lt;br /&gt;
     1.6: -&lt;br /&gt;
     1.5: length&lt;br /&gt;
     1.4: &amp;gt;&lt;br /&gt;
     1.4: assignment&lt;br /&gt;
     1.3: &amp;gt;=&lt;br /&gt;
     1.3: mark_alert_last_seen&lt;br /&gt;
     1.3: delete_if&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''To install Flog''': gem install flog.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29 page].&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
[https://github.com/metricfu/metric_fu Metric_fu] is a nice gem which internally uses [http://saikuro.rubyforge.org/ Saikuro], [http://ruby.sadi.st/Flog.html Flog], [http://ruby.sadi.st/Flog.html Flay], [http://rubygems.org/gems/rcov Rcov], [https://github.com/kevinrutherford/reek/ Reek], [https://github.com/martinjandrews/roodi Roodi], [https://github.com/danmayer/churn Churn], [http://rubygems.org/gems/rails_best_practices RailsBestPractices] and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Metric_fu ====&lt;br /&gt;
Metric_fu combines several different tools that provide reports that show which parts of your code might need extra work. So, if you are looking to find out which part of your code requires refactoring running metric_fu would be of great use. Metric_fu also provides individual results generated by each of these tools and looking at these results the user could decide which tool to run in detail to identify the problem areas in the code.&lt;br /&gt;
&lt;br /&gt;
=== Reek ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Reek [https://github.com/troessner/reek]is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* '''Control Coupling''' - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
Given a source file demo.rb containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;class Dirty&lt;br /&gt;
  # This method smells of :reek:NestedIterators but ignores them&lt;br /&gt;
  def awful(x, y, offset = 0, log = false)&lt;br /&gt;
    puts @screen.title&lt;br /&gt;
    @screen = widgets.map {|w| w.each {|key| key += 3}}&lt;br /&gt;
    puts @screen.contents&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reek will report the following code smells in this file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ reek demo.rb&lt;br /&gt;
  spec/samples/demo/demo.rb -- 6 warnings:&lt;br /&gt;
  Dirty has no descriptive comment (IrresponsibleModule)&lt;br /&gt;
  Dirty#awful has 4 parameters (LongParameterList)&lt;br /&gt;
  Dirty#awful has boolean parameter 'log' (ControlCouple)&lt;br /&gt;
  Dirty#awful has the parameter name 'x' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the parameter name 'y' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the variable name 'w' (UncommunicativeName)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
Roodi's output looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:152 - Block cyclomatic complexity is 11.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/rake/verify_rcov.rb:37 - Block cyclomatic complexity is 6.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/be.rb:57 - Method name &amp;quot;match_or_compare&amp;quot; has a cyclomatic complexity is 12.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:12 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 9.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/have.rb:28 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 11.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/expectations/errors.rb:6 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:186 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/expectations/differs/default.rb:20 - Method name &amp;quot;diff_as_string&amp;quot; has 21 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:35 - Method name &amp;quot;failure_message&amp;quot; has 24 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:31 - Method name &amp;quot;_message&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:35 - Method name &amp;quot;_pretty_print&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation. It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:require 'rubygems'&lt;br /&gt;
:require 'rufus-treechecker'&lt;br /&gt;
&lt;br /&gt;
:tc = Rufus::TreeChecker.new do&lt;br /&gt;
:  exclude_fvcall :abort&lt;br /&gt;
:  exclude_fvcall :exit, :exit!&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:tc.check(&amp;quot;1 + 1; abort&amp;quot;)               # will raise a SecurityError&lt;br /&gt;
:tc.check(&amp;quot;puts (1..10).to_a.inspect&amp;quot;)  # OK&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code. Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
=== User scenarios and tools ===&lt;br /&gt;
From our study of the tools, we think that each tool has its own usability. Under different circumstances, one would find a different tool useful. Thus, it would be useful to have a mapping of scenarios and the appropriate tool to use in that case. We would like to suggest the following mapping:&lt;br /&gt;
{| class=”wikitable” border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario&lt;br /&gt;
! Tool &lt;br /&gt;
! Explanation&lt;br /&gt;
|- &lt;br /&gt;
| Beginning of coding activity&lt;br /&gt;
| Roodi &lt;br /&gt;
| Roodi warns against bad design and we would prefer being warned about design problems early into the development rather than later.&lt;br /&gt;
|- &lt;br /&gt;
| When first few classes or modules are being fleshed out &lt;br /&gt;
| Rubocop&lt;br /&gt;
| To get familiarized with the stylistic conventions. Typically best for new developers.&lt;br /&gt;
|- &lt;br /&gt;
| Quick analysis of code after basic functionality implemented and tested &lt;br /&gt;
| Metric fu &lt;br /&gt;
| So that we can code, test and analyze. Then depending on the tool that returned most warnings, we could focus our attention on that particular aspect of the code.&lt;br /&gt;
|-&lt;br /&gt;
| Continuous code improvement / refactoring &lt;br /&gt;
| Reek, Rufus &lt;br /&gt;
| To check for code smells and potential bugs.&lt;br /&gt;
|- &lt;br /&gt;
| When code is large and/or you find yourself logically repeating yourself &lt;br /&gt;
| Flay &lt;br /&gt;
| When code base becomes large enough and you want to keep your code DRY, Flay can help detect repetition.&lt;br /&gt;
|- &lt;br /&gt;
| Improve readability &lt;br /&gt;
| Saikuro, Flog &lt;br /&gt;
| To reduce code complexity and to make code readable and ease support, especially legacy code.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;br /&gt;
https://www.ruby-toolbox.com/categories/code_metrics&lt;br /&gt;
&lt;br /&gt;
http://www.infoq.com/news/2008/11/static-analysis-tool-roundup&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/09/23/reek-a-code-smells-detector-for-ruby/?referer=sphere_related_content/&lt;br /&gt;
&lt;br /&gt;
https://github.com/YorickPeterse/ruby-lint&lt;br /&gt;
&lt;br /&gt;
http://www.neevtech.com/blog/2011/07/04/static-code-analysis-in-ruby/&lt;br /&gt;
&lt;br /&gt;
http://asciicasts.com/episodes/166-metric-fu&lt;br /&gt;
&lt;br /&gt;
https://github.com/troessner/reek&lt;br /&gt;
&lt;br /&gt;
http://ruby.sadi.st/Flay.html&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/10/19/reek-and-feature-envy/&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83026</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83026"/>
		<updated>2014-02-08T06:38:04Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to [http://en.wikipedia.org/wiki/Don%27t_repeat_yourself DRY] principle.  Flay uses [http://rubyforge.org/forum/forum.php?forum_id=27971 sexp_processor] and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [http://docs.seattlerb.org/flay/README_txt.htm Flay]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up.[http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html] &lt;br /&gt;
Just gem install flay, and then flay *.rb to get playing with Flay.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
'''To Install Flay''': gem install flay&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's  [http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw ABC] (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the  [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67 source code]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
====Example==== &lt;br /&gt;
Report from Flog looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Total score = 211.720690020501&lt;br /&gt;
   &lt;br /&gt;
  WatchR#analyze_entry: (34.2)&lt;br /&gt;
     9.8: assignment&lt;br /&gt;
     7.0: branch&lt;br /&gt;
     4.5: mark_host_last_seen&lt;br /&gt;
     3.2: pattern&lt;br /&gt;
     2.8: []&lt;br /&gt;
     2.8: is_event?&lt;br /&gt;
     2.0: alert_type&lt;br /&gt;
     2.0: alert_target&lt;br /&gt;
     1.8: alert_msg&lt;br /&gt;
     1.8: notify&lt;br /&gt;
     1.6: event_notify?&lt;br /&gt;
     1.3: notify_log&lt;br /&gt;
     1.3: join&lt;br /&gt;
     1.3: split&lt;br /&gt;
     1.3: each&lt;br /&gt;
     1.3: now&lt;br /&gt;
     1.3: each_value&lt;br /&gt;
     1.3: record_host_if_unknown&lt;br /&gt;
     0.4: lit_fixnum&lt;br /&gt;
  WatchR#event_threshold_reached?: (31.6)&lt;br /&gt;
    21.3: []&lt;br /&gt;
     2.6: branch&lt;br /&gt;
     1.8: tv_sec&lt;br /&gt;
     1.6: -&lt;br /&gt;
     1.5: length&lt;br /&gt;
     1.4: &amp;gt;&lt;br /&gt;
     1.4: assignment&lt;br /&gt;
     1.3: &amp;gt;=&lt;br /&gt;
     1.3: mark_alert_last_seen&lt;br /&gt;
     1.3: delete_if&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''To install Flog''': gem install flog.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29 page].&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
[https://github.com/metricfu/metric_fu Metric_fu] is a nice gem which internally uses [http://saikuro.rubyforge.org/ Saikuro], [http://ruby.sadi.st/Flog.html Flog], [http://ruby.sadi.st/Flog.html Flay], [http://rubygems.org/gems/rcov Rcov], [https://github.com/kevinrutherford/reek/ Reek], [https://github.com/martinjandrews/roodi Roodi], [https://github.com/danmayer/churn Churn], [http://rubygems.org/gems/rails_best_practices RailsBestPractices] and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Metric_fu ====&lt;br /&gt;
Metric_fu combines several different tools that provide reports that show which parts of your code might need extra work. So, if you are looking to find out which part of your code requires refactoring running metric_fu would be of great use. Metric_fu also provides individual results generated by each of these tools and looking at these results the user could decide which tool to run in detail to identify the problem areas in the code.&lt;br /&gt;
&lt;br /&gt;
=== Reek ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Reek [https://github.com/troessner/reek]is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* '''Control Coupling''' - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
&lt;br /&gt;
Given a source file demo.rb containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;class Dirty&lt;br /&gt;
  # This method smells of :reek:NestedIterators but ignores them&lt;br /&gt;
  def awful(x, y, offset = 0, log = false)&lt;br /&gt;
    puts @screen.title&lt;br /&gt;
    @screen = widgets.map {|w| w.each {|key| key += 3}}&lt;br /&gt;
    puts @screen.contents&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reek will report the following code smells in this file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ reek demo.rb&lt;br /&gt;
  spec/samples/demo/demo.rb -- 6 warnings:&lt;br /&gt;
  Dirty has no descriptive comment (IrresponsibleModule)&lt;br /&gt;
  Dirty#awful has 4 parameters (LongParameterList)&lt;br /&gt;
  Dirty#awful has boolean parameter 'log' (ControlCouple)&lt;br /&gt;
  Dirty#awful has the parameter name 'x' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the parameter name 'y' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the variable name 'w' (UncommunicativeName)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
Roodi's output looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:152 - Block cyclomatic complexity is 11.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/rake/verify_rcov.rb:37 - Block cyclomatic complexity is 6.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/be.rb:57 - Method name &amp;quot;match_or_compare&amp;quot; has a cyclomatic complexity is 12.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:12 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 9.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/have.rb:28 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 11.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/expectations/errors.rb:6 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:186 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/expectations/differs/default.rb:20 - Method name &amp;quot;diff_as_string&amp;quot; has 21 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:35 - Method name &amp;quot;failure_message&amp;quot; has 24 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:31 - Method name &amp;quot;_message&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:35 - Method name &amp;quot;_pretty_print&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation. It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:require 'rubygems'&lt;br /&gt;
:require 'rufus-treechecker'&lt;br /&gt;
&lt;br /&gt;
:tc = Rufus::TreeChecker.new do&lt;br /&gt;
:  exclude_fvcall :abort&lt;br /&gt;
:  exclude_fvcall :exit, :exit!&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:tc.check(&amp;quot;1 + 1; abort&amp;quot;)               # will raise a SecurityError&lt;br /&gt;
:tc.check(&amp;quot;puts (1..10).to_a.inspect&amp;quot;)  # OK&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code. Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
=== User scenarios and tools ===&lt;br /&gt;
From our study of the tools, we think that each tool has its own usability. Under different circumstances, one would find a different tool useful. Thus, it would be useful to have a mapping of scenarios and the appropriate tool to use in that case. We would like to suggest the following mapping:&lt;br /&gt;
{| class=”wikitable” border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario&lt;br /&gt;
! Tool &lt;br /&gt;
! Explanation&lt;br /&gt;
|- &lt;br /&gt;
| Beginning of coding activity&lt;br /&gt;
| Roodi &lt;br /&gt;
| Roodi warns against bad design and we would prefer being warned about design problems early into the development rather than later.&lt;br /&gt;
|- &lt;br /&gt;
| When first few classes or modules are being fleshed out &lt;br /&gt;
| Rubocop&lt;br /&gt;
| To get familiarized with the stylistic conventions. Typically best for new developers.&lt;br /&gt;
|- &lt;br /&gt;
| Quick analysis of code after basic functionality implemented and tested &lt;br /&gt;
| Metric fu &lt;br /&gt;
| So that we can code, test and analyze. Then depending on the tool that returned most warnings, we could focus our attention on that particular aspect of the code.&lt;br /&gt;
|-&lt;br /&gt;
| Continuous code improvement / refactoring &lt;br /&gt;
| Reek, Rufus &lt;br /&gt;
| To check for code smells and potential bugs.&lt;br /&gt;
|- &lt;br /&gt;
| When code is large and/or you find yourself logically repeating yourself &lt;br /&gt;
| Flay &lt;br /&gt;
| When code base becomes large enough and you want to keep your code DRY, Flay can help detect repetition.&lt;br /&gt;
|- &lt;br /&gt;
| Improve readability &lt;br /&gt;
| Saikuro, Flog &lt;br /&gt;
| To reduce code complexity and to make code readable and ease support, especially legacy code.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;br /&gt;
https://www.ruby-toolbox.com/categories/code_metrics&lt;br /&gt;
&lt;br /&gt;
http://www.infoq.com/news/2008/11/static-analysis-tool-roundup&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/09/23/reek-a-code-smells-detector-for-ruby/?referer=sphere_related_content/&lt;br /&gt;
&lt;br /&gt;
https://github.com/YorickPeterse/ruby-lint&lt;br /&gt;
&lt;br /&gt;
http://www.neevtech.com/blog/2011/07/04/static-code-analysis-in-ruby/&lt;br /&gt;
&lt;br /&gt;
http://asciicasts.com/episodes/166-metric-fu&lt;br /&gt;
&lt;br /&gt;
https://github.com/troessner/reek&lt;br /&gt;
&lt;br /&gt;
http://ruby.sadi.st/Flay.html&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/10/19/reek-and-feature-envy/&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83025</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83025"/>
		<updated>2014-02-08T06:37:20Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to [http://en.wikipedia.org/wiki/Don%27t_repeat_yourself DRY] principle.  Flay uses [http://rubyforge.org/forum/forum.php?forum_id=27971 sexp_processor] and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [http://docs.seattlerb.org/flay/README_txt.htm Flay]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up.[http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html] &lt;br /&gt;
Just gem install flay, and then flay *.rb to get playing with Flay.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
'''To Install Flay''': gem install flay&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's  [http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw ABC] (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the  [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67 source code]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
'''Example:''' Report from Flog looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Total score = 211.720690020501&lt;br /&gt;
   &lt;br /&gt;
  WatchR#analyze_entry: (34.2)&lt;br /&gt;
     9.8: assignment&lt;br /&gt;
     7.0: branch&lt;br /&gt;
     4.5: mark_host_last_seen&lt;br /&gt;
     3.2: pattern&lt;br /&gt;
     2.8: []&lt;br /&gt;
     2.8: is_event?&lt;br /&gt;
     2.0: alert_type&lt;br /&gt;
     2.0: alert_target&lt;br /&gt;
     1.8: alert_msg&lt;br /&gt;
     1.8: notify&lt;br /&gt;
     1.6: event_notify?&lt;br /&gt;
     1.3: notify_log&lt;br /&gt;
     1.3: join&lt;br /&gt;
     1.3: split&lt;br /&gt;
     1.3: each&lt;br /&gt;
     1.3: now&lt;br /&gt;
     1.3: each_value&lt;br /&gt;
     1.3: record_host_if_unknown&lt;br /&gt;
     0.4: lit_fixnum&lt;br /&gt;
  WatchR#event_threshold_reached?: (31.6)&lt;br /&gt;
    21.3: []&lt;br /&gt;
     2.6: branch&lt;br /&gt;
     1.8: tv_sec&lt;br /&gt;
     1.6: -&lt;br /&gt;
     1.5: length&lt;br /&gt;
     1.4: &amp;gt;&lt;br /&gt;
     1.4: assignment&lt;br /&gt;
     1.3: &amp;gt;=&lt;br /&gt;
     1.3: mark_alert_last_seen&lt;br /&gt;
     1.3: delete_if&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''To install Flog''': gem install flog.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29 page].&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
[https://github.com/metricfu/metric_fu Metric_fu] is a nice gem which internally uses [http://saikuro.rubyforge.org/ Saikuro], [http://ruby.sadi.st/Flog.html Flog], [http://ruby.sadi.st/Flog.html Flay], [http://rubygems.org/gems/rcov Rcov], [https://github.com/kevinrutherford/reek/ Reek], [https://github.com/martinjandrews/roodi Roodi], [https://github.com/danmayer/churn Churn], [http://rubygems.org/gems/rails_best_practices RailsBestPractices] and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Metric_fu ====&lt;br /&gt;
Metric_fu combines several different tools that provide reports that show which parts of your code might need extra work. So, if you are looking to find out which part of your code requires refactoring running metric_fu would be of great use. Metric_fu also provides individual results generated by each of these tools and looking at these results the user could decide which tool to run in detail to identify the problem areas in the code.&lt;br /&gt;
&lt;br /&gt;
=== Reek ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Reek [https://github.com/troessner/reek]is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* '''Control Coupling''' - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
&lt;br /&gt;
Given a source file demo.rb containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;class Dirty&lt;br /&gt;
  # This method smells of :reek:NestedIterators but ignores them&lt;br /&gt;
  def awful(x, y, offset = 0, log = false)&lt;br /&gt;
    puts @screen.title&lt;br /&gt;
    @screen = widgets.map {|w| w.each {|key| key += 3}}&lt;br /&gt;
    puts @screen.contents&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reek will report the following code smells in this file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ reek demo.rb&lt;br /&gt;
  spec/samples/demo/demo.rb -- 6 warnings:&lt;br /&gt;
  Dirty has no descriptive comment (IrresponsibleModule)&lt;br /&gt;
  Dirty#awful has 4 parameters (LongParameterList)&lt;br /&gt;
  Dirty#awful has boolean parameter 'log' (ControlCouple)&lt;br /&gt;
  Dirty#awful has the parameter name 'x' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the parameter name 'y' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the variable name 'w' (UncommunicativeName)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
Roodi's output looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:152 - Block cyclomatic complexity is 11.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/rake/verify_rcov.rb:37 - Block cyclomatic complexity is 6.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/be.rb:57 - Method name &amp;quot;match_or_compare&amp;quot; has a cyclomatic complexity is 12.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:12 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 9.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/have.rb:28 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 11.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/expectations/errors.rb:6 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:186 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/expectations/differs/default.rb:20 - Method name &amp;quot;diff_as_string&amp;quot; has 21 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:35 - Method name &amp;quot;failure_message&amp;quot; has 24 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:31 - Method name &amp;quot;_message&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:35 - Method name &amp;quot;_pretty_print&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation. It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:require 'rubygems'&lt;br /&gt;
:require 'rufus-treechecker'&lt;br /&gt;
&lt;br /&gt;
:tc = Rufus::TreeChecker.new do&lt;br /&gt;
:  exclude_fvcall :abort&lt;br /&gt;
:  exclude_fvcall :exit, :exit!&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:tc.check(&amp;quot;1 + 1; abort&amp;quot;)               # will raise a SecurityError&lt;br /&gt;
:tc.check(&amp;quot;puts (1..10).to_a.inspect&amp;quot;)  # OK&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code. Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
=== User scenarios and tools ===&lt;br /&gt;
From our study of the tools, we think that each tool has its own usability. Under different circumstances, one would find a different tool useful. Thus, it would be useful to have a mapping of scenarios and the appropriate tool to use in that case. We would like to suggest the following mapping:&lt;br /&gt;
{| class=”wikitable” border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario&lt;br /&gt;
! Tool &lt;br /&gt;
! Explanation&lt;br /&gt;
|- &lt;br /&gt;
| Beginning of coding activity&lt;br /&gt;
| Roodi &lt;br /&gt;
| Roodi warns against bad design and we would prefer being warned about design problems early into the development rather than later.&lt;br /&gt;
|- &lt;br /&gt;
| When first few classes or modules are being fleshed out &lt;br /&gt;
| Rubocop&lt;br /&gt;
| To get familiarized with the stylistic conventions. Typically best for new developers.&lt;br /&gt;
|- &lt;br /&gt;
| Quick analysis of code after basic functionality implemented and tested &lt;br /&gt;
| Metric fu &lt;br /&gt;
| So that we can code, test and analyze. Then depending on the tool that returned most warnings, we could focus our attention on that particular aspect of the code.&lt;br /&gt;
|-&lt;br /&gt;
| Continuous code improvement / refactoring &lt;br /&gt;
| Reek, Rufus &lt;br /&gt;
| To check for code smells and potential bugs.&lt;br /&gt;
|- &lt;br /&gt;
| When code is large and/or you find yourself logically repeating yourself &lt;br /&gt;
| Flay &lt;br /&gt;
| When code base becomes large enough and you want to keep your code DRY, Flay can help detect repetition.&lt;br /&gt;
|- &lt;br /&gt;
| Improve readability &lt;br /&gt;
| Saikuro, Flog &lt;br /&gt;
| To reduce code complexity and to make code readable and ease support, especially legacy code.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;br /&gt;
https://www.ruby-toolbox.com/categories/code_metrics&lt;br /&gt;
&lt;br /&gt;
http://www.infoq.com/news/2008/11/static-analysis-tool-roundup&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/09/23/reek-a-code-smells-detector-for-ruby/?referer=sphere_related_content/&lt;br /&gt;
&lt;br /&gt;
https://github.com/YorickPeterse/ruby-lint&lt;br /&gt;
&lt;br /&gt;
http://www.neevtech.com/blog/2011/07/04/static-code-analysis-in-ruby/&lt;br /&gt;
&lt;br /&gt;
http://asciicasts.com/episodes/166-metric-fu&lt;br /&gt;
&lt;br /&gt;
https://github.com/troessner/reek&lt;br /&gt;
&lt;br /&gt;
http://ruby.sadi.st/Flay.html&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/10/19/reek-and-feature-envy/&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83022</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83022"/>
		<updated>2014-02-08T06:32:42Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to [http://en.wikipedia.org/wiki/Don%27t_repeat_yourself DRY] principle.  Flay uses [http://rubyforge.org/forum/forum.php?forum_id=27971 sexp_processor] and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [http://docs.seattlerb.org/flay/README_txt.htm Flay]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up.[http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html] &lt;br /&gt;
Just gem install flay, and then flay *.rb to get playing with Flay.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
'''To Install Flay''': gem install flay&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's  [http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw ABC] (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the  [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67 source code]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
'''Example:''' Report from Flog looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Total score = 211.720690020501&lt;br /&gt;
   &lt;br /&gt;
  WatchR#analyze_entry: (34.2)&lt;br /&gt;
     9.8: assignment&lt;br /&gt;
     7.0: branch&lt;br /&gt;
     4.5: mark_host_last_seen&lt;br /&gt;
     3.2: pattern&lt;br /&gt;
     2.8: []&lt;br /&gt;
     2.8: is_event?&lt;br /&gt;
     2.0: alert_type&lt;br /&gt;
     2.0: alert_target&lt;br /&gt;
     1.8: alert_msg&lt;br /&gt;
     1.8: notify&lt;br /&gt;
     1.6: event_notify?&lt;br /&gt;
     1.3: notify_log&lt;br /&gt;
     1.3: join&lt;br /&gt;
     1.3: split&lt;br /&gt;
     1.3: each&lt;br /&gt;
     1.3: now&lt;br /&gt;
     1.3: each_value&lt;br /&gt;
     1.3: record_host_if_unknown&lt;br /&gt;
     0.4: lit_fixnum&lt;br /&gt;
  WatchR#event_threshold_reached?: (31.6)&lt;br /&gt;
    21.3: []&lt;br /&gt;
     2.6: branch&lt;br /&gt;
     1.8: tv_sec&lt;br /&gt;
     1.6: -&lt;br /&gt;
     1.5: length&lt;br /&gt;
     1.4: &amp;gt;&lt;br /&gt;
     1.4: assignment&lt;br /&gt;
     1.3: &amp;gt;=&lt;br /&gt;
     1.3: mark_alert_last_seen&lt;br /&gt;
     1.3: delete_if&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''To install Flog''': gem install flog.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29 page].&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Metric_fu[https://github.com/metricfu/metric_fu] is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Metric_fu ====&lt;br /&gt;
Metric_fu combines several different tools that provide reports that show which parts of your code might need extra work. So, if you are looking to find out which part of your code requires refactoring running metric_fu would be of great use. Metric_fu also provides individual results generated by each of these tools and looking at these results the user could decide which tool to run in detail to identify the problem areas in the code.&lt;br /&gt;
&lt;br /&gt;
=== Reek ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Reek [https://github.com/troessner/reek]is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* '''Control Coupling''' - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
&lt;br /&gt;
Given a source file demo.rb containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;class Dirty&lt;br /&gt;
  # This method smells of :reek:NestedIterators but ignores them&lt;br /&gt;
  def awful(x, y, offset = 0, log = false)&lt;br /&gt;
    puts @screen.title&lt;br /&gt;
    @screen = widgets.map {|w| w.each {|key| key += 3}}&lt;br /&gt;
    puts @screen.contents&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reek will report the following code smells in this file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ reek demo.rb&lt;br /&gt;
  spec/samples/demo/demo.rb -- 6 warnings:&lt;br /&gt;
  Dirty has no descriptive comment (IrresponsibleModule)&lt;br /&gt;
  Dirty#awful has 4 parameters (LongParameterList)&lt;br /&gt;
  Dirty#awful has boolean parameter 'log' (ControlCouple)&lt;br /&gt;
  Dirty#awful has the parameter name 'x' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the parameter name 'y' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the variable name 'w' (UncommunicativeName)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
&lt;br /&gt;
'''Example:'''Roodi's output looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:152 - Block cyclomatic complexity is 11.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/rake/verify_rcov.rb:37 - Block cyclomatic complexity is 6.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/be.rb:57 - Method name &amp;quot;match_or_compare&amp;quot; has a cyclomatic complexity is 12.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:12 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 9.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/have.rb:28 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 11.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/expectations/errors.rb:6 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:186 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/expectations/differs/default.rb:20 - Method name &amp;quot;diff_as_string&amp;quot; has 21 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:35 - Method name &amp;quot;failure_message&amp;quot; has 24 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:31 - Method name &amp;quot;_message&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:35 - Method name &amp;quot;_pretty_print&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation. It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:require 'rubygems'&lt;br /&gt;
:require 'rufus-treechecker'&lt;br /&gt;
&lt;br /&gt;
:tc = Rufus::TreeChecker.new do&lt;br /&gt;
:  exclude_fvcall :abort&lt;br /&gt;
:  exclude_fvcall :exit, :exit!&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:tc.check(&amp;quot;1 + 1; abort&amp;quot;)               # will raise a SecurityError&lt;br /&gt;
:tc.check(&amp;quot;puts (1..10).to_a.inspect&amp;quot;)  # OK&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code. Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
=== User scenarios and tools ===&lt;br /&gt;
From our study of the tools, we think that each tool has its own usability. Under different circumstances, one would find a different tool useful. Thus, it would be useful to have a mapping of scenarios and the appropriate tool to use in that case. We would like to suggest the following mapping:&lt;br /&gt;
{| class=”wikitable” border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario&lt;br /&gt;
! Tool &lt;br /&gt;
! Explanation&lt;br /&gt;
|- &lt;br /&gt;
| Beginning of coding activity&lt;br /&gt;
| Roodi &lt;br /&gt;
| Roodi warns against bad design and we would prefer being warned about design problems early into the development rather than later.&lt;br /&gt;
|- &lt;br /&gt;
| When first few classes or modules are being fleshed out &lt;br /&gt;
| Rubocop&lt;br /&gt;
| To get familiarized with the stylistic conventions. Typically best for new developers.&lt;br /&gt;
|- &lt;br /&gt;
| Quick analysis of code after basic functionality implemented and tested &lt;br /&gt;
| Metric fu &lt;br /&gt;
| So that we can code, test and analyze. Then depending on the tool that returned most warnings, we could focus our attention on that particular aspect of the code.&lt;br /&gt;
|-&lt;br /&gt;
| Continuous code improvement / refactoring &lt;br /&gt;
| Reek, Rufus &lt;br /&gt;
| To check for code smells and potential bugs.&lt;br /&gt;
|- &lt;br /&gt;
| When code is large and/or you find yourself logically repeating yourself &lt;br /&gt;
| Flay &lt;br /&gt;
| When code base becomes large enough and you want to keep your code DRY, Flay can help detect repetition.&lt;br /&gt;
|- &lt;br /&gt;
| Improve readability &lt;br /&gt;
| Saikuro, Flog &lt;br /&gt;
| To reduce code complexity and to make code readable and ease support, especially legacy code.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;br /&gt;
https://www.ruby-toolbox.com/categories/code_metrics&lt;br /&gt;
&lt;br /&gt;
http://www.infoq.com/news/2008/11/static-analysis-tool-roundup&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/09/23/reek-a-code-smells-detector-for-ruby/?referer=sphere_related_content/&lt;br /&gt;
&lt;br /&gt;
https://github.com/YorickPeterse/ruby-lint&lt;br /&gt;
&lt;br /&gt;
http://www.neevtech.com/blog/2011/07/04/static-code-analysis-in-ruby/&lt;br /&gt;
&lt;br /&gt;
http://asciicasts.com/episodes/166-metric-fu&lt;br /&gt;
&lt;br /&gt;
https://github.com/troessner/reek&lt;br /&gt;
&lt;br /&gt;
http://ruby.sadi.st/Flay.html&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/10/19/reek-and-feature-envy/&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83018</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83018"/>
		<updated>2014-02-08T06:29:01Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Features */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses ''[http://rubyforge.org/forum/forum.php?forum_id=27971 sexp_processor]'' and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
'''To Install Flay''': gem install flay&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
'''Example:''' Report from Flog looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Total score = 211.720690020501&lt;br /&gt;
   &lt;br /&gt;
  WatchR#analyze_entry: (34.2)&lt;br /&gt;
     9.8: assignment&lt;br /&gt;
     7.0: branch&lt;br /&gt;
     4.5: mark_host_last_seen&lt;br /&gt;
     3.2: pattern&lt;br /&gt;
     2.8: []&lt;br /&gt;
     2.8: is_event?&lt;br /&gt;
     2.0: alert_type&lt;br /&gt;
     2.0: alert_target&lt;br /&gt;
     1.8: alert_msg&lt;br /&gt;
     1.8: notify&lt;br /&gt;
     1.6: event_notify?&lt;br /&gt;
     1.3: notify_log&lt;br /&gt;
     1.3: join&lt;br /&gt;
     1.3: split&lt;br /&gt;
     1.3: each&lt;br /&gt;
     1.3: now&lt;br /&gt;
     1.3: each_value&lt;br /&gt;
     1.3: record_host_if_unknown&lt;br /&gt;
     0.4: lit_fixnum&lt;br /&gt;
  WatchR#event_threshold_reached?: (31.6)&lt;br /&gt;
    21.3: []&lt;br /&gt;
     2.6: branch&lt;br /&gt;
     1.8: tv_sec&lt;br /&gt;
     1.6: -&lt;br /&gt;
     1.5: length&lt;br /&gt;
     1.4: &amp;gt;&lt;br /&gt;
     1.4: assignment&lt;br /&gt;
     1.3: &amp;gt;=&lt;br /&gt;
     1.3: mark_alert_last_seen&lt;br /&gt;
     1.3: delete_if&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''To install Flog''': gem install flog.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Metric_fu[https://github.com/metricfu/metric_fu] is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Metric_fu ====&lt;br /&gt;
Metric_fu combines several different tools that provide reports that show which parts of your code might need extra work. So, if you are looking to find out which part of your code requires refactoring running metric_fu would be of great use. Metric_fu also provides individual results generated by each of these tools and looking at these results the user could decide which tool to run in detail to identify the problem areas in the code.&lt;br /&gt;
&lt;br /&gt;
=== Reek ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Reek [https://github.com/troessner/reek]is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* '''Control Coupling''' - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
&lt;br /&gt;
Given a source file demo.rb containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;class Dirty&lt;br /&gt;
  # This method smells of :reek:NestedIterators but ignores them&lt;br /&gt;
  def awful(x, y, offset = 0, log = false)&lt;br /&gt;
    puts @screen.title&lt;br /&gt;
    @screen = widgets.map {|w| w.each {|key| key += 3}}&lt;br /&gt;
    puts @screen.contents&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reek will report the following code smells in this file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ reek demo.rb&lt;br /&gt;
  spec/samples/demo/demo.rb -- 6 warnings:&lt;br /&gt;
  Dirty has no descriptive comment (IrresponsibleModule)&lt;br /&gt;
  Dirty#awful has 4 parameters (LongParameterList)&lt;br /&gt;
  Dirty#awful has boolean parameter 'log' (ControlCouple)&lt;br /&gt;
  Dirty#awful has the parameter name 'x' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the parameter name 'y' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the variable name 'w' (UncommunicativeName)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
&lt;br /&gt;
'''Example:'''Roodi's output looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:152 - Block cyclomatic complexity is 11.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/rake/verify_rcov.rb:37 - Block cyclomatic complexity is 6.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/be.rb:57 - Method name &amp;quot;match_or_compare&amp;quot; has a cyclomatic complexity is 12.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:12 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 9.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/have.rb:28 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 11.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/expectations/errors.rb:6 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:186 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/expectations/differs/default.rb:20 - Method name &amp;quot;diff_as_string&amp;quot; has 21 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:35 - Method name &amp;quot;failure_message&amp;quot; has 24 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:31 - Method name &amp;quot;_message&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:35 - Method name &amp;quot;_pretty_print&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation. It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code. Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
=== User scenarios and tools ===&lt;br /&gt;
From our study of the tools, we think that each tool has its own usability. Under different circumstances, one would find a different tool useful. Thus, it would be useful to have a mapping of scenarios and the appropriate tool to use in that case. We would like to suggest the following mapping:&lt;br /&gt;
{| class=”wikitable” border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario&lt;br /&gt;
! Tool &lt;br /&gt;
! Explanation&lt;br /&gt;
|- &lt;br /&gt;
| Beginning of coding activity&lt;br /&gt;
| Roodi &lt;br /&gt;
| Roodi warns against bad design and we would prefer being warned about design problems early into the development rather than later.&lt;br /&gt;
|- &lt;br /&gt;
| When first few classes or modules are being fleshed out &lt;br /&gt;
| Rubocop&lt;br /&gt;
| To get familiarized with the stylistic conventions. Typically best for new developers.&lt;br /&gt;
|- &lt;br /&gt;
| Quick analysis of code after basic functionality implemented and tested &lt;br /&gt;
| Metric fu &lt;br /&gt;
| So that we can code, test and analyze. Then depending on the tool that returned most warnings, we could focus our attention on that particular aspect of the code.&lt;br /&gt;
|-&lt;br /&gt;
| Continuous code improvement / refactoring &lt;br /&gt;
| Reek, Rufus &lt;br /&gt;
| To check for code smells and potential bugs.&lt;br /&gt;
|- &lt;br /&gt;
| When code is large and/or you find yourself logically repeating yourself &lt;br /&gt;
| Flay &lt;br /&gt;
| When code base becomes large enough and you want to keep your code DRY, Flay can help detect repetition.&lt;br /&gt;
|- &lt;br /&gt;
| Improve readability &lt;br /&gt;
| Saikuro, Flog &lt;br /&gt;
| To reduce code complexity and to make code readable and ease support, especially legacy code.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;br /&gt;
https://www.ruby-toolbox.com/categories/code_metrics&lt;br /&gt;
&lt;br /&gt;
http://www.infoq.com/news/2008/11/static-analysis-tool-roundup&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/09/23/reek-a-code-smells-detector-for-ruby/?referer=sphere_related_content/&lt;br /&gt;
&lt;br /&gt;
https://github.com/YorickPeterse/ruby-lint&lt;br /&gt;
&lt;br /&gt;
http://www.neevtech.com/blog/2011/07/04/static-code-analysis-in-ruby/&lt;br /&gt;
&lt;br /&gt;
http://asciicasts.com/episodes/166-metric-fu&lt;br /&gt;
&lt;br /&gt;
https://github.com/troessner/reek&lt;br /&gt;
&lt;br /&gt;
http://ruby.sadi.st/Flay.html&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/10/19/reek-and-feature-envy/&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83017</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83017"/>
		<updated>2014-02-08T06:17:45Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses ''[http://rubyforge.org/forum/forum.php?forum_id=27971 sexp_processor]'' and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
'''Example:''' Report from Flog looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Total score = 211.720690020501&lt;br /&gt;
   &lt;br /&gt;
  WatchR#analyze_entry: (34.2)&lt;br /&gt;
     9.8: assignment&lt;br /&gt;
     7.0: branch&lt;br /&gt;
     4.5: mark_host_last_seen&lt;br /&gt;
     3.2: pattern&lt;br /&gt;
     2.8: []&lt;br /&gt;
     2.8: is_event?&lt;br /&gt;
     2.0: alert_type&lt;br /&gt;
     2.0: alert_target&lt;br /&gt;
     1.8: alert_msg&lt;br /&gt;
     1.8: notify&lt;br /&gt;
     1.6: event_notify?&lt;br /&gt;
     1.3: notify_log&lt;br /&gt;
     1.3: join&lt;br /&gt;
     1.3: split&lt;br /&gt;
     1.3: each&lt;br /&gt;
     1.3: now&lt;br /&gt;
     1.3: each_value&lt;br /&gt;
     1.3: record_host_if_unknown&lt;br /&gt;
     0.4: lit_fixnum&lt;br /&gt;
  WatchR#event_threshold_reached?: (31.6)&lt;br /&gt;
    21.3: []&lt;br /&gt;
     2.6: branch&lt;br /&gt;
     1.8: tv_sec&lt;br /&gt;
     1.6: -&lt;br /&gt;
     1.5: length&lt;br /&gt;
     1.4: &amp;gt;&lt;br /&gt;
     1.4: assignment&lt;br /&gt;
     1.3: &amp;gt;=&lt;br /&gt;
     1.3: mark_alert_last_seen&lt;br /&gt;
     1.3: delete_if&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''To install Flog''': gem install flog.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Metric_fu[https://github.com/metricfu/metric_fu] is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Metric_fu ====&lt;br /&gt;
Metric_fu combines several different tools that provide reports that show which parts of your code might need extra work. So, if you are looking to find out which part of your code requires refactoring running metric_fu would be of great use. Metric_fu also provides individual results generated by each of these tools and looking at these results the user could decide which tool to run in detail to identify the problem areas in the code.&lt;br /&gt;
&lt;br /&gt;
=== Reek ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Reek [https://github.com/troessner/reek]is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* '''Control Coupling''' - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
&lt;br /&gt;
Given a source file demo.rb containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;class Dirty&lt;br /&gt;
  # This method smells of :reek:NestedIterators but ignores them&lt;br /&gt;
  def awful(x, y, offset = 0, log = false)&lt;br /&gt;
    puts @screen.title&lt;br /&gt;
    @screen = widgets.map {|w| w.each {|key| key += 3}}&lt;br /&gt;
    puts @screen.contents&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reek will report the following code smells in this file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ reek demo.rb&lt;br /&gt;
  spec/samples/demo/demo.rb -- 6 warnings:&lt;br /&gt;
  Dirty has no descriptive comment (IrresponsibleModule)&lt;br /&gt;
  Dirty#awful has 4 parameters (LongParameterList)&lt;br /&gt;
  Dirty#awful has boolean parameter 'log' (ControlCouple)&lt;br /&gt;
  Dirty#awful has the parameter name 'x' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the parameter name 'y' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the variable name 'w' (UncommunicativeName)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
&lt;br /&gt;
'''Example:'''Roodi's output looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:152 - Block cyclomatic complexity is 11.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/rake/verify_rcov.rb:37 - Block cyclomatic complexity is 6.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/be.rb:57 - Method name &amp;quot;match_or_compare&amp;quot; has a cyclomatic complexity is 12.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:12 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 9.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/have.rb:28 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 11.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/expectations/errors.rb:6 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:186 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/expectations/differs/default.rb:20 - Method name &amp;quot;diff_as_string&amp;quot; has 21 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:35 - Method name &amp;quot;failure_message&amp;quot; has 24 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:31 - Method name &amp;quot;_message&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:35 - Method name &amp;quot;_pretty_print&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation. It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code. Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
=== User scenarios and tools ===&lt;br /&gt;
From our study of the tools, we think that each tool has its own usability. Under different circumstances, one would find a different tool useful. Thus, it would be useful to have a mapping of scenarios and the appropriate tool to use in that case. We would like to suggest the following mapping:&lt;br /&gt;
{| class=”wikitable” border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario&lt;br /&gt;
! Tool &lt;br /&gt;
! Explanation&lt;br /&gt;
|- &lt;br /&gt;
| Beginning of coding activity&lt;br /&gt;
| Roodi &lt;br /&gt;
| Roodi warns against bad design and we would prefer being warned about design problems early into the development rather than later.&lt;br /&gt;
|- &lt;br /&gt;
| When first few classes or modules are being fleshed out &lt;br /&gt;
| Rubocop&lt;br /&gt;
| To get familiarized with the stylistic conventions. Typically best for new developers.&lt;br /&gt;
|- &lt;br /&gt;
| Quick analysis of code after basic functionality implemented and tested &lt;br /&gt;
| Metric fu &lt;br /&gt;
| So that we can code, test and analyze. Then depending on the tool that returned most warnings, we could focus our attention on that particular aspect of the code.&lt;br /&gt;
|-&lt;br /&gt;
| Continuous code improvement / refactoring &lt;br /&gt;
| Reek, Rufus &lt;br /&gt;
| To check for code smells and potential bugs.&lt;br /&gt;
|- &lt;br /&gt;
| When code is large and/or you find yourself logically repeating yourself &lt;br /&gt;
| Flay &lt;br /&gt;
| When code base becomes large enough and you want to keep your code DRY, Flay can help detect repetition.&lt;br /&gt;
|- &lt;br /&gt;
| Improve readability &lt;br /&gt;
| Saikuro, Flog &lt;br /&gt;
| To reduce code complexity and to make code readable and ease support, especially legacy code.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;br /&gt;
https://www.ruby-toolbox.com/categories/code_metrics&lt;br /&gt;
&lt;br /&gt;
http://www.infoq.com/news/2008/11/static-analysis-tool-roundup&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/09/23/reek-a-code-smells-detector-for-ruby/?referer=sphere_related_content/&lt;br /&gt;
&lt;br /&gt;
https://github.com/YorickPeterse/ruby-lint&lt;br /&gt;
&lt;br /&gt;
http://www.neevtech.com/blog/2011/07/04/static-code-analysis-in-ruby/&lt;br /&gt;
&lt;br /&gt;
http://asciicasts.com/episodes/166-metric-fu&lt;br /&gt;
&lt;br /&gt;
https://github.com/troessner/reek&lt;br /&gt;
&lt;br /&gt;
http://ruby.sadi.st/Flay.html&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/10/19/reek-and-feature-envy/&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83015</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83015"/>
		<updated>2014-02-08T06:16:33Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses ''[[http://rubyforge.org/forum/forum.php?forum_id=27971|sexp_processor]]'' and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
'''Example:''' Report from Flog looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Total score = 211.720690020501&lt;br /&gt;
   &lt;br /&gt;
  WatchR#analyze_entry: (34.2)&lt;br /&gt;
     9.8: assignment&lt;br /&gt;
     7.0: branch&lt;br /&gt;
     4.5: mark_host_last_seen&lt;br /&gt;
     3.2: pattern&lt;br /&gt;
     2.8: []&lt;br /&gt;
     2.8: is_event?&lt;br /&gt;
     2.0: alert_type&lt;br /&gt;
     2.0: alert_target&lt;br /&gt;
     1.8: alert_msg&lt;br /&gt;
     1.8: notify&lt;br /&gt;
     1.6: event_notify?&lt;br /&gt;
     1.3: notify_log&lt;br /&gt;
     1.3: join&lt;br /&gt;
     1.3: split&lt;br /&gt;
     1.3: each&lt;br /&gt;
     1.3: now&lt;br /&gt;
     1.3: each_value&lt;br /&gt;
     1.3: record_host_if_unknown&lt;br /&gt;
     0.4: lit_fixnum&lt;br /&gt;
  WatchR#event_threshold_reached?: (31.6)&lt;br /&gt;
    21.3: []&lt;br /&gt;
     2.6: branch&lt;br /&gt;
     1.8: tv_sec&lt;br /&gt;
     1.6: -&lt;br /&gt;
     1.5: length&lt;br /&gt;
     1.4: &amp;gt;&lt;br /&gt;
     1.4: assignment&lt;br /&gt;
     1.3: &amp;gt;=&lt;br /&gt;
     1.3: mark_alert_last_seen&lt;br /&gt;
     1.3: delete_if&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''To install Flog''': gem install flog.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Metric_fu[https://github.com/metricfu/metric_fu] is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Metric_fu ====&lt;br /&gt;
Metric_fu combines several different tools that provide reports that show which parts of your code might need extra work. So, if you are looking to find out which part of your code requires refactoring running metric_fu would be of great use. Metric_fu also provides individual results generated by each of these tools and looking at these results the user could decide which tool to run in detail to identify the problem areas in the code.&lt;br /&gt;
&lt;br /&gt;
=== Reek ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Reek [https://github.com/troessner/reek]is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* '''Control Coupling''' - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
&lt;br /&gt;
Given a source file demo.rb containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;class Dirty&lt;br /&gt;
  # This method smells of :reek:NestedIterators but ignores them&lt;br /&gt;
  def awful(x, y, offset = 0, log = false)&lt;br /&gt;
    puts @screen.title&lt;br /&gt;
    @screen = widgets.map {|w| w.each {|key| key += 3}}&lt;br /&gt;
    puts @screen.contents&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reek will report the following code smells in this file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ reek demo.rb&lt;br /&gt;
  spec/samples/demo/demo.rb -- 6 warnings:&lt;br /&gt;
  Dirty has no descriptive comment (IrresponsibleModule)&lt;br /&gt;
  Dirty#awful has 4 parameters (LongParameterList)&lt;br /&gt;
  Dirty#awful has boolean parameter 'log' (ControlCouple)&lt;br /&gt;
  Dirty#awful has the parameter name 'x' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the parameter name 'y' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the variable name 'w' (UncommunicativeName)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
&lt;br /&gt;
'''Example:'''Roodi's output looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:152 - Block cyclomatic complexity is 11.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/rake/verify_rcov.rb:37 - Block cyclomatic complexity is 6.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/be.rb:57 - Method name &amp;quot;match_or_compare&amp;quot; has a cyclomatic complexity is 12.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:12 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 9.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/have.rb:28 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 11.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/expectations/errors.rb:6 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:186 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/expectations/differs/default.rb:20 - Method name &amp;quot;diff_as_string&amp;quot; has 21 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:35 - Method name &amp;quot;failure_message&amp;quot; has 24 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:31 - Method name &amp;quot;_message&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:35 - Method name &amp;quot;_pretty_print&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation. It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code. Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
=== User scenarios and tools ===&lt;br /&gt;
From our study of the tools, we think that each tool has its own usability. Under different circumstances, one would find a different tool useful. Thus, it would be useful to have a mapping of scenarios and the appropriate tool to use in that case. We would like to suggest the following mapping:&lt;br /&gt;
{| class=”wikitable” border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario&lt;br /&gt;
! Tool &lt;br /&gt;
! Explanation&lt;br /&gt;
|- &lt;br /&gt;
| Beginning of coding activity&lt;br /&gt;
| Roodi &lt;br /&gt;
| Roodi warns against bad design and we would prefer being warned about design problems early into the development rather than later.&lt;br /&gt;
|- &lt;br /&gt;
| When first few classes or modules are being fleshed out &lt;br /&gt;
| Rubocop&lt;br /&gt;
| To get familiarized with the stylistic conventions. Typically best for new developers.&lt;br /&gt;
|- &lt;br /&gt;
| Quick analysis of code after basic functionality implemented and tested &lt;br /&gt;
| Metric fu &lt;br /&gt;
| So that we can code, test and analyze. Then depending on the tool that returned most warnings, we could focus our attention on that particular aspect of the code.&lt;br /&gt;
|-&lt;br /&gt;
| Continuous code improvement / refactoring &lt;br /&gt;
| Reek, Rufus &lt;br /&gt;
| To check for code smells and potential bugs.&lt;br /&gt;
|- &lt;br /&gt;
| When code is large and/or you find yourself logically repeating yourself &lt;br /&gt;
| Flay &lt;br /&gt;
| When code base becomes large enough and you want to keep your code DRY, Flay can help detect repetition.&lt;br /&gt;
|- &lt;br /&gt;
| Improve readability &lt;br /&gt;
| Saikuro, Flog &lt;br /&gt;
| To reduce code complexity and to make code readable and ease support, especially legacy code.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;br /&gt;
https://www.ruby-toolbox.com/categories/code_metrics&lt;br /&gt;
&lt;br /&gt;
http://www.infoq.com/news/2008/11/static-analysis-tool-roundup&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/09/23/reek-a-code-smells-detector-for-ruby/?referer=sphere_related_content/&lt;br /&gt;
&lt;br /&gt;
https://github.com/YorickPeterse/ruby-lint&lt;br /&gt;
&lt;br /&gt;
http://www.neevtech.com/blog/2011/07/04/static-code-analysis-in-ruby/&lt;br /&gt;
&lt;br /&gt;
http://asciicasts.com/episodes/166-metric-fu&lt;br /&gt;
&lt;br /&gt;
https://github.com/troessner/reek&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/10/19/reek-and-feature-envy/&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83013</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83013"/>
		<updated>2014-02-08T06:13:52Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
'''To install Flog''': gem install flog.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Metric_fu[https://github.com/metricfu/metric_fu] is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Metric_fu ====&lt;br /&gt;
Metric_fu combines several different tools that provide reports that show which parts of your code might need extra work. So, if you are looking to find out which part of your code requires refactoring running metric_fu would be of great use. Metric_fu also provides individual results generated by each of these tools and looking at these results the user could decide which tool to run in detail to identify the problem areas in the code.&lt;br /&gt;
&lt;br /&gt;
=== Reek ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Reek [https://github.com/troessner/reek]is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* '''Control Coupling''' - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
&lt;br /&gt;
Given a source file demo.rb containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;class Dirty&lt;br /&gt;
  # This method smells of :reek:NestedIterators but ignores them&lt;br /&gt;
  def awful(x, y, offset = 0, log = false)&lt;br /&gt;
    puts @screen.title&lt;br /&gt;
    @screen = widgets.map {|w| w.each {|key| key += 3}}&lt;br /&gt;
    puts @screen.contents&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reek will report the following code smells in this file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ reek demo.rb&lt;br /&gt;
  spec/samples/demo/demo.rb -- 6 warnings:&lt;br /&gt;
  Dirty has no descriptive comment (IrresponsibleModule)&lt;br /&gt;
  Dirty#awful has 4 parameters (LongParameterList)&lt;br /&gt;
  Dirty#awful has boolean parameter 'log' (ControlCouple)&lt;br /&gt;
  Dirty#awful has the parameter name 'x' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the parameter name 'y' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the variable name 'w' (UncommunicativeName)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
&lt;br /&gt;
'''Example:'''Roodi's output looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:152 - Block cyclomatic complexity is 11.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/rake/verify_rcov.rb:37 - Block cyclomatic complexity is 6.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/be.rb:57 - Method name &amp;quot;match_or_compare&amp;quot; has a cyclomatic complexity is 12.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:12 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 9.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/have.rb:28 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 11.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/expectations/errors.rb:6 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:186 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/expectations/differs/default.rb:20 - Method name &amp;quot;diff_as_string&amp;quot; has 21 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:35 - Method name &amp;quot;failure_message&amp;quot; has 24 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:31 - Method name &amp;quot;_message&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:35 - Method name &amp;quot;_pretty_print&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation. It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code. Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
=== User scenarios and tools ===&lt;br /&gt;
From our study of the tools, we think that each tool has its own usability. Under different circumstances, one would find a different tool useful. Thus, it would be useful to have a mapping of scenarios and the appropriate tool to use in that case. We would like to suggest the following mapping:&lt;br /&gt;
{| class=”wikitable” border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario&lt;br /&gt;
! Tool &lt;br /&gt;
! Explanation&lt;br /&gt;
|- &lt;br /&gt;
| Beginning of coding activity&lt;br /&gt;
| Roodi &lt;br /&gt;
| Roodi warns against bad design and we would prefer being warned about design problems early into the development rather than later.&lt;br /&gt;
|- &lt;br /&gt;
| When first few classes or modules are being fleshed out &lt;br /&gt;
| Rubocop&lt;br /&gt;
| To get familiarized with the stylistic conventions. Typically best for new developers.&lt;br /&gt;
|- &lt;br /&gt;
| Quick analysis of code after basic functionality implemented and tested &lt;br /&gt;
| Metric fu &lt;br /&gt;
| So that we can code, test and analyze. Then depending on the tool that returned most warnings, we could focus our attention on that particular aspect of the code.&lt;br /&gt;
|-&lt;br /&gt;
| Continuous code improvement / refactoring &lt;br /&gt;
| Reek, Rufus &lt;br /&gt;
| To check for code smells and potential bugs.&lt;br /&gt;
|- &lt;br /&gt;
| When code is large and/or you find yourself logically repeating yourself &lt;br /&gt;
| Flay &lt;br /&gt;
| When code base becomes large enough and you want to keep your code DRY, Flay can help detect repetition.&lt;br /&gt;
|- &lt;br /&gt;
| Improve readability &lt;br /&gt;
| Saikuro, Flog &lt;br /&gt;
| To reduce code complexity and to make code readable and ease support, especially legacy code.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;br /&gt;
https://www.ruby-toolbox.com/categories/code_metrics&lt;br /&gt;
&lt;br /&gt;
http://www.infoq.com/news/2008/11/static-analysis-tool-roundup&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/09/23/reek-a-code-smells-detector-for-ruby/?referer=sphere_related_content/&lt;br /&gt;
&lt;br /&gt;
https://github.com/YorickPeterse/ruby-lint&lt;br /&gt;
&lt;br /&gt;
http://www.neevtech.com/blog/2011/07/04/static-code-analysis-in-ruby/&lt;br /&gt;
&lt;br /&gt;
http://asciicasts.com/episodes/166-metric-fu&lt;br /&gt;
&lt;br /&gt;
https://github.com/troessner/reek&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/10/19/reek-and-feature-envy/&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83012</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83012"/>
		<updated>2014-02-08T06:12:06Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
'''To install Flog''': gem install flog.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Metric_fu[https://github.com/metricfu/metric_fu] is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Metric_fu ====&lt;br /&gt;
Metric_fu combines several different tools that provide reports that show which parts of your code might need extra work. So, if you are looking to find out which part of your code requires refactoring running metric_fu would be of great use. Metric_fu also provides individual results generated by each of these tools and looking at these results the user could decide which tool to run in detail to identify the problem areas in the code.&lt;br /&gt;
&lt;br /&gt;
=== Reek ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Reek [https://github.com/troessner/reek]is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* '''Control Coupling''' - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
&lt;br /&gt;
Given a source file demo.rb containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;class Dirty&lt;br /&gt;
  # This method smells of :reek:NestedIterators but ignores them&lt;br /&gt;
  def awful(x, y, offset = 0, log = false)&lt;br /&gt;
    puts @screen.title&lt;br /&gt;
    @screen = widgets.map {|w| w.each {|key| key += 3}}&lt;br /&gt;
    puts @screen.contents&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reek will report the following code smells in this file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ reek demo.rb&lt;br /&gt;
  spec/samples/demo/demo.rb -- 6 warnings:&lt;br /&gt;
  Dirty has no descriptive comment (IrresponsibleModule)&lt;br /&gt;
  Dirty#awful has 4 parameters (LongParameterList)&lt;br /&gt;
  Dirty#awful has boolean parameter 'log' (ControlCouple)&lt;br /&gt;
  Dirty#awful has the parameter name 'x' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the parameter name 'y' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the variable name 'w' (UncommunicativeName)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation. It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code. Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
=== User scenarios and tools ===&lt;br /&gt;
From our study of the tools, we think that each tool has its own usability. Under different circumstances, one would find a different tool useful. Thus, it would be useful to have a mapping of scenarios and the appropriate tool to use in that case. We would like to suggest the following mapping:&lt;br /&gt;
{| class=”wikitable” border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario&lt;br /&gt;
! Tool &lt;br /&gt;
! Explanation&lt;br /&gt;
|- &lt;br /&gt;
| Beginning of coding activity&lt;br /&gt;
| Roodi &lt;br /&gt;
| Roodi warns against bad design and we would prefer being warned about design problems early into the development rather than later.&lt;br /&gt;
|- &lt;br /&gt;
| When first few classes or modules are being fleshed out &lt;br /&gt;
| Rubocop&lt;br /&gt;
| To get familiarized with the stylistic conventions. Typically best for new developers.&lt;br /&gt;
|- &lt;br /&gt;
| Quick analysis of code after basic functionality implemented and tested &lt;br /&gt;
| Metric fu &lt;br /&gt;
| So that we can code, test and analyze. Then depending on the tool that returned most warnings, we could focus our attention on that particular aspect of the code.&lt;br /&gt;
|-&lt;br /&gt;
| Continuous code improvement / refactoring &lt;br /&gt;
| Reek, Rufus &lt;br /&gt;
| To check for code smells and potential bugs.&lt;br /&gt;
|- &lt;br /&gt;
| When code is large and/or you find yourself logically repeating yourself &lt;br /&gt;
| Flay &lt;br /&gt;
| When code base becomes large enough and you want to keep your code DRY, Flay can help detect repetition.&lt;br /&gt;
|- &lt;br /&gt;
| Improve readability &lt;br /&gt;
| Saikuro, Flog &lt;br /&gt;
| To reduce code complexity and to make code readable and ease support, especially legacy code.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;br /&gt;
https://www.ruby-toolbox.com/categories/code_metrics&lt;br /&gt;
&lt;br /&gt;
http://www.infoq.com/news/2008/11/static-analysis-tool-roundup&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/09/23/reek-a-code-smells-detector-for-ruby/?referer=sphere_related_content/&lt;br /&gt;
&lt;br /&gt;
https://github.com/YorickPeterse/ruby-lint&lt;br /&gt;
&lt;br /&gt;
http://www.neevtech.com/blog/2011/07/04/static-code-analysis-in-ruby/&lt;br /&gt;
&lt;br /&gt;
http://asciicasts.com/episodes/166-metric-fu&lt;br /&gt;
&lt;br /&gt;
https://github.com/troessner/reek&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/10/19/reek-and-feature-envy/&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83011</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83011"/>
		<updated>2014-02-08T06:08:56Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
'''To install Flog''': gem install flog.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Metric_fu[https://github.com/metricfu/metric_fu] is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Metric_fu ====&lt;br /&gt;
Metric_fu combines several different tools that provide reports that show which parts of your code might need extra work. So, if you are looking to find out which part of your code requires refactoring running metric_fu would be of great use. Metric_fu also provides individual results generated by each of these tools and looking at these results the user could decide which tool to run in detail to identify the problem areas in the code.&lt;br /&gt;
&lt;br /&gt;
=== Reek ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Reek [https://github.com/troessner/reek]is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* '''Control Coupling''' - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
&lt;br /&gt;
Given a source file demo.rb containing:&lt;br /&gt;
&lt;br /&gt;
class Dirty&lt;br /&gt;
  # This method smells of :reek:NestedIterators but ignores them&lt;br /&gt;
  def awful(x, y, offset = 0, log = false)&lt;br /&gt;
    puts @screen.title&lt;br /&gt;
    @screen = widgets.map {|w| w.each {|key| key += 3}}&lt;br /&gt;
    puts @screen.contents&lt;br /&gt;
  end&lt;br /&gt;
end &lt;br /&gt;
&lt;br /&gt;
Reek will report the following code smells in this file:&lt;br /&gt;
&lt;br /&gt;
$ reek demo.rb&lt;br /&gt;
spec/samples/demo/demo.rb -- 6 warnings:&lt;br /&gt;
  Dirty has no descriptive comment (IrresponsibleModule)&lt;br /&gt;
  Dirty#awful has 4 parameters (LongParameterList)&lt;br /&gt;
  Dirty#awful has boolean parameter 'log' (ControlCouple)&lt;br /&gt;
  Dirty#awful has the parameter name 'x' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the parameter name 'y' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the variable name 'w' (UncommunicativeName)&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation. It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code. Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
=== User scenarios and tools ===&lt;br /&gt;
From our study of the tools, we think that each tool has its own usability. Under different circumstances, one would find a different tool useful. Thus, it would be useful to have a mapping of scenarios and the appropriate tool to use in that case. We would like to suggest the following mapping:&lt;br /&gt;
{| class=”wikitable” border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario&lt;br /&gt;
! Tool &lt;br /&gt;
! Explanation&lt;br /&gt;
|- &lt;br /&gt;
| Beginning of coding activity&lt;br /&gt;
| Roodi &lt;br /&gt;
| Roodi warns against bad design and we would prefer being warned about design problems early into the development rather than later.&lt;br /&gt;
|- &lt;br /&gt;
| When first few classes or modules are being fleshed out &lt;br /&gt;
| Rubocop&lt;br /&gt;
| To get familiarized with the stylistic conventions. Typically best for new developers.&lt;br /&gt;
|- &lt;br /&gt;
| Quick analysis of code after basic functionality implemented and tested &lt;br /&gt;
| Metric fu &lt;br /&gt;
| So that we can code, test and analyze. Then depending on the tool that returned most warnings, we could focus our attention on that particular aspect of the code.&lt;br /&gt;
|-&lt;br /&gt;
| Continuous code improvement / refactoring &lt;br /&gt;
| Reek, Rufus &lt;br /&gt;
| To check for code smells and potential bugs.&lt;br /&gt;
|- &lt;br /&gt;
| When code is large and/or you find yourself logically repeating yourself &lt;br /&gt;
| Flay &lt;br /&gt;
| When code base becomes large enough and you want to keep your code DRY, Flay can help detect repetition.&lt;br /&gt;
|- &lt;br /&gt;
| Improve readability &lt;br /&gt;
| Saikuro, Flog &lt;br /&gt;
| To reduce code complexity and to make code readable and ease support, especially legacy code.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;br /&gt;
https://www.ruby-toolbox.com/categories/code_metrics&lt;br /&gt;
&lt;br /&gt;
http://www.infoq.com/news/2008/11/static-analysis-tool-roundup&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/09/23/reek-a-code-smells-detector-for-ruby/?referer=sphere_related_content/&lt;br /&gt;
&lt;br /&gt;
https://github.com/YorickPeterse/ruby-lint&lt;br /&gt;
&lt;br /&gt;
http://www.neevtech.com/blog/2011/07/04/static-code-analysis-in-ruby/&lt;br /&gt;
&lt;br /&gt;
http://asciicasts.com/episodes/166-metric-fu&lt;br /&gt;
&lt;br /&gt;
https://github.com/troessner/reek&lt;br /&gt;
&lt;br /&gt;
http://silkandspinach.net/2008/10/19/reek-and-feature-envy/&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83010</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83010"/>
		<updated>2014-02-08T06:06:10Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Roodi */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
'''To install Flog''': gem install flog.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Metric_fu[https://github.com/metricfu/metric_fu] is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Metric_fu ====&lt;br /&gt;
Metric_fu combines several different tools that provide reports that show which parts of your code might need extra work. So, if you are looking to find out which part of your code requires refactoring running metric_fu would be of great use. Metric_fu also provides individual results generated by each of these tools and looking at these results the user could decide which tool to run in detail to identify the problem areas in the code.&lt;br /&gt;
&lt;br /&gt;
=== Reek ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Reek [https://github.com/troessner/reek]is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* '''Control Coupling''' - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
&lt;br /&gt;
Given a source file demo.rb containing:&lt;br /&gt;
&lt;br /&gt;
class Dirty&lt;br /&gt;
  # This method smells of :reek:NestedIterators but ignores them&lt;br /&gt;
  def awful(x, y, offset = 0, log = false)&lt;br /&gt;
    puts @screen.title&lt;br /&gt;
    @screen = widgets.map {|w| w.each {|key| key += 3}}&lt;br /&gt;
    puts @screen.contents&lt;br /&gt;
  end&lt;br /&gt;
end &lt;br /&gt;
&lt;br /&gt;
Reek will report the following code smells in this file:&lt;br /&gt;
&lt;br /&gt;
$ reek demo.rb&lt;br /&gt;
spec/samples/demo/demo.rb -- 6 warnings:&lt;br /&gt;
  Dirty has no descriptive comment (IrresponsibleModule)&lt;br /&gt;
  Dirty#awful has 4 parameters (LongParameterList)&lt;br /&gt;
  Dirty#awful has boolean parameter 'log' (ControlCouple)&lt;br /&gt;
  Dirty#awful has the parameter name 'x' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the parameter name 'y' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the variable name 'w' (UncommunicativeName)&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation. It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
==== Introduction ====&lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code. Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
==== Introduction ====&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
=== User scenarios and tools ===&lt;br /&gt;
From our study of the tools, we think that each tool has its own usability. Under different circumstances, one would find a different tool useful. Thus, it would be useful to have a mapping of scenarios and the appropriate tool to use in that case. We would like to suggest the following mapping:&lt;br /&gt;
{| class=”wikitable” border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Scenario&lt;br /&gt;
! Tool &lt;br /&gt;
! Explanation&lt;br /&gt;
|- &lt;br /&gt;
| Beginning of coding activity&lt;br /&gt;
| Roodi &lt;br /&gt;
| Roodi warns against bad design and we would prefer being warned about design problems early into the development rather than later.&lt;br /&gt;
|- &lt;br /&gt;
| When first few classes or modules are being fleshed out &lt;br /&gt;
| Rubocop&lt;br /&gt;
| To get familiarized with the stylistic conventions. Typically best for new developers.&lt;br /&gt;
|- &lt;br /&gt;
| Quick analysis of code after basic functionality implemented and tested &lt;br /&gt;
| Metric fu &lt;br /&gt;
| So that we can code, test and analyze. Then depending on the tool that returned most warnings, we could focus our attention on that particular aspect of the code.&lt;br /&gt;
|-&lt;br /&gt;
| Continuous code improvement / refactoring &lt;br /&gt;
| Reek, Rufus &lt;br /&gt;
| To check for code smells and potential bugs.&lt;br /&gt;
|- &lt;br /&gt;
| When code is large and/or you find yourself logically repeating yourself &lt;br /&gt;
| Flay &lt;br /&gt;
| When code base becomes large enough and you want to keep your code DRY, Flay can help detect repetition.&lt;br /&gt;
|- &lt;br /&gt;
| Improve readability &lt;br /&gt;
| Saikuro, Flog &lt;br /&gt;
| To reduce code complexity and to make code readable and ease support, especially legacy code.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83005</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83005"/>
		<updated>2014-02-08T05:38:26Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Roodi */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
'''To install Flog''': gem install flog.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
Metric_fu[https://github.com/metricfu/metric_fu] is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Metric_fu ====&lt;br /&gt;
Metric_fu combines several different tools that provide reports that show which parts of your code might need extra work. So, if you are looking to find out which part of your code requires refactoring running metric_fu would be of great use. Metric_fu also provides individual results generated by each of these tools and looking at these results the user could decide which tool to run in detail to identify the problem areas in the code.&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
Reek [https://github.com/troessner/reek]is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* '''Control Coupling''' - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
&lt;br /&gt;
Given a source file demo.rb containing:&lt;br /&gt;
&lt;br /&gt;
class Dirty&lt;br /&gt;
  # This method smells of :reek:NestedIterators but ignores them&lt;br /&gt;
  def awful(x, y, offset = 0, log = false)&lt;br /&gt;
    puts @screen.title&lt;br /&gt;
    @screen = widgets.map {|w| w.each {|key| key += 3}}&lt;br /&gt;
    puts @screen.contents&lt;br /&gt;
  end&lt;br /&gt;
end &lt;br /&gt;
&lt;br /&gt;
Reek will report the following code smells in this file:&lt;br /&gt;
&lt;br /&gt;
$ reek demo.rb&lt;br /&gt;
spec/samples/demo/demo.rb -- 6 warnings:&lt;br /&gt;
  Dirty has no descriptive comment (IrresponsibleModule)&lt;br /&gt;
  Dirty#awful has 4 parameters (LongParameterList)&lt;br /&gt;
  Dirty#awful has boolean parameter 'log' (ControlCouple)&lt;br /&gt;
  Dirty#awful has the parameter name 'x' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the parameter name 'y' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the variable name 'w' (UncommunicativeName)&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
An example of Roodi's output looks like this:&lt;br /&gt;
&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:152 - Block cyclomatic complexity is 11.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/rake/verify_rcov.rb:37 - Block cyclomatic complexity is 6.  It should be 4 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/be.rb:57 - Method name &amp;quot;match_or_compare&amp;quot; has a cyclomatic complexity is 12.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:12 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 9.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/have.rb:28 - Method name &amp;quot;matches?&amp;quot; has a cyclomatic complexity is 11.  It should be 8 or less.&lt;br /&gt;
:rspec/lib/spec/expectations/errors.rb:6 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/rake/spectask.rb:186 - Rescue block should not be empty.&lt;br /&gt;
:rspec/lib/spec/expectations/differs/default.rb:20 - Method name &amp;quot;diff_as_string&amp;quot; has 21 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/change.rb:35 - Method name &amp;quot;failure_message&amp;quot; has 24 lines.  It should have 20 or less.&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:31 - Method name &amp;quot;_message&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&lt;br /&gt;
:rspec/lib/spec/matchers/include.rb:35 - Method name &amp;quot;_pretty_print&amp;quot; should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\?]?$).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation.It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code.  Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83004</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83004"/>
		<updated>2014-02-08T05:31:42Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Metric_fu */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
'''To install Flog''': gem install flog.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
Metric_fu[https://github.com/metricfu/metric_fu] is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Metric_fu ====&lt;br /&gt;
Metric_fu combines several different tools that provide reports that show which parts of your code might need extra work. So, if you are looking to find out which part of your code requires refactoring running metric_fu would be of great use. Metric_fu also provides individual results generated by each of these tools and looking at these results the user could decide which tool to run in detail to identify the problem areas in the code.&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
Reek [https://github.com/troessner/reek]is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* '''Control Coupling''' - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
&lt;br /&gt;
Given a source file demo.rb containing:&lt;br /&gt;
&lt;br /&gt;
class Dirty&lt;br /&gt;
  # This method smells of :reek:NestedIterators but ignores them&lt;br /&gt;
  def awful(x, y, offset = 0, log = false)&lt;br /&gt;
    puts @screen.title&lt;br /&gt;
    @screen = widgets.map {|w| w.each {|key| key += 3}}&lt;br /&gt;
    puts @screen.contents&lt;br /&gt;
  end&lt;br /&gt;
end &lt;br /&gt;
&lt;br /&gt;
Reek will report the following code smells in this file:&lt;br /&gt;
&lt;br /&gt;
$ reek demo.rb&lt;br /&gt;
spec/samples/demo/demo.rb -- 6 warnings:&lt;br /&gt;
  Dirty has no descriptive comment (IrresponsibleModule)&lt;br /&gt;
  Dirty#awful has 4 parameters (LongParameterList)&lt;br /&gt;
  Dirty#awful has boolean parameter 'log' (ControlCouple)&lt;br /&gt;
  Dirty#awful has the parameter name 'x' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the parameter name 'y' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the variable name 'w' (UncommunicativeName)&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation.It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code.  Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83003</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83003"/>
		<updated>2014-02-08T05:19:43Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Flog */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
'''To install Flog''': gem install flog.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
Metric_fu[https://github.com/metricfu/metric_fu] is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
Reek [https://github.com/troessner/reek]is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* '''Control Coupling''' - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
&lt;br /&gt;
Given a source file demo.rb containing:&lt;br /&gt;
&lt;br /&gt;
class Dirty&lt;br /&gt;
  # This method smells of :reek:NestedIterators but ignores them&lt;br /&gt;
  def awful(x, y, offset = 0, log = false)&lt;br /&gt;
    puts @screen.title&lt;br /&gt;
    @screen = widgets.map {|w| w.each {|key| key += 3}}&lt;br /&gt;
    puts @screen.contents&lt;br /&gt;
  end&lt;br /&gt;
end &lt;br /&gt;
&lt;br /&gt;
Reek will report the following code smells in this file:&lt;br /&gt;
&lt;br /&gt;
$ reek demo.rb&lt;br /&gt;
spec/samples/demo/demo.rb -- 6 warnings:&lt;br /&gt;
  Dirty has no descriptive comment (IrresponsibleModule)&lt;br /&gt;
  Dirty#awful has 4 parameters (LongParameterList)&lt;br /&gt;
  Dirty#awful has boolean parameter 'log' (ControlCouple)&lt;br /&gt;
  Dirty#awful has the parameter name 'x' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the parameter name 'y' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the variable name 'w' (UncommunicativeName)&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation.It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code.  Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83002</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83002"/>
		<updated>2014-02-08T05:19:10Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Suggestions for  using Flog */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
Metric_fu[https://github.com/metricfu/metric_fu] is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
Reek [https://github.com/troessner/reek]is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* '''Control Coupling''' - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
&lt;br /&gt;
Given a source file demo.rb containing:&lt;br /&gt;
&lt;br /&gt;
class Dirty&lt;br /&gt;
  # This method smells of :reek:NestedIterators but ignores them&lt;br /&gt;
  def awful(x, y, offset = 0, log = false)&lt;br /&gt;
    puts @screen.title&lt;br /&gt;
    @screen = widgets.map {|w| w.each {|key| key += 3}}&lt;br /&gt;
    puts @screen.contents&lt;br /&gt;
  end&lt;br /&gt;
end &lt;br /&gt;
&lt;br /&gt;
Reek will report the following code smells in this file:&lt;br /&gt;
&lt;br /&gt;
$ reek demo.rb&lt;br /&gt;
spec/samples/demo/demo.rb -- 6 warnings:&lt;br /&gt;
  Dirty has no descriptive comment (IrresponsibleModule)&lt;br /&gt;
  Dirty#awful has 4 parameters (LongParameterList)&lt;br /&gt;
  Dirty#awful has boolean parameter 'log' (ControlCouple)&lt;br /&gt;
  Dirty#awful has the parameter name 'x' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the parameter name 'y' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the variable name 'w' (UncommunicativeName)&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation.It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code.  Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83001</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83001"/>
		<updated>2014-02-08T05:13:54Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Reek */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
Flog can be installed using sudo gem install flog.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
Metric_fu[https://github.com/metricfu/metric_fu] is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
Reek [https://github.com/troessner/reek]is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* '''Control Coupling''' - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
&lt;br /&gt;
Given a source file demo.rb containing:&lt;br /&gt;
&lt;br /&gt;
class Dirty&lt;br /&gt;
  # This method smells of :reek:NestedIterators but ignores them&lt;br /&gt;
  def awful(x, y, offset = 0, log = false)&lt;br /&gt;
    puts @screen.title&lt;br /&gt;
    @screen = widgets.map {|w| w.each {|key| key += 3}}&lt;br /&gt;
    puts @screen.contents&lt;br /&gt;
  end&lt;br /&gt;
end &lt;br /&gt;
&lt;br /&gt;
Reek will report the following code smells in this file:&lt;br /&gt;
&lt;br /&gt;
$ reek demo.rb&lt;br /&gt;
spec/samples/demo/demo.rb -- 6 warnings:&lt;br /&gt;
  Dirty has no descriptive comment (IrresponsibleModule)&lt;br /&gt;
  Dirty#awful has 4 parameters (LongParameterList)&lt;br /&gt;
  Dirty#awful has boolean parameter 'log' (ControlCouple)&lt;br /&gt;
  Dirty#awful has the parameter name 'x' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the parameter name 'y' (UncommunicativeName)&lt;br /&gt;
  Dirty#awful has the variable name 'w' (UncommunicativeName)&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation.It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code.  Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83000</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=83000"/>
		<updated>2014-02-08T04:49:03Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Reek */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
Flog can be installed using sudo gem install flog.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
Metric_fu[https://github.com/metricfu/metric_fu] is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
It is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* '''Control Coupling''' - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation.It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code.  Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82999</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82999"/>
		<updated>2014-02-08T02:42:37Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Metric_fu */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
Flog can be installed using sudo gem install flog.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
Metric_fu[https://github.com/metricfu/metric_fu] is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
It is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation.It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code.  Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices and standard conventions to follow while coding Ruby. Adhering to coding standards has several benefits since code is readable and if everybody follows conventions, other Ruby programmers can easily understand the code and extend it. Code that follows conventions is easy to support.&lt;br /&gt;
Rubocop checks that check for stylistics problems in your code are called style cops. Most of them are based on the Ruby Style Guide. Style cops also provide configuration option that allow them to support different support different popular coding conventions.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files. Specific files can also be checked by passing them as arguments while calling Rubocop.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions on using RuboCop ====&lt;br /&gt;
* Since RuboCop only checks for stylistic problems, we should use and configure RuboCop only if it works for the coding conventions decided upon for that project or company.&lt;br /&gt;
* To avoid seeing too many warnings, it is advisable to use RuboCop on individual files only.&lt;br /&gt;
* RuboCop focuses on the readability aspect of code and should be done after other major parts of refactoring are done.&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82997</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82997"/>
		<updated>2014-02-08T02:39:19Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Metric_fu */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
Flog can be installed using sudo gem install flog.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
Metric_fu[https://github.com/metricfu/metric_fu] is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generally useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
* '''churn''': It will shows which files change the most.&lt;br /&gt;
* '''coverage''': It will show which parts of your code are tested&lt;br /&gt;
* '''flay''': It will shows which parts of your code are duplicated&lt;br /&gt;
* '''flog''': It will show if your code is unnecessarily complex&lt;br /&gt;
* '''reek''': It will show if  your code suffer from well-known bad practices&lt;br /&gt;
* '''saikuro''': It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
'''To Install Metric_fu''': gem install metric_fu&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
It is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation.It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code.  Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices so that real-world Ruby programmers can write code that can be maintained by other real-world Ruby programmers. &lt;br /&gt;
Its purpose is to force you to write code that follows the style guide dictated by the Ruby community.&lt;br /&gt;
It warns that the class doesn’t have a top-level documentation comment, the parenthesis in the method declaration are unnecessary, and double-quote strings aren’t needed when there is no string interpolation.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files.&lt;br /&gt;
If you want Rubocop to scan only a few directories then you can pass those as arguments.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82996</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82996"/>
		<updated>2014-02-08T02:32:38Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Roodi */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
Flog can be installed using sudo gem install flog.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
It is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
'''To install Roodi:''' gem install roodi&lt;br /&gt;
&lt;br /&gt;
'''To run Roodi:''' $ roodi&lt;br /&gt;
&lt;br /&gt;
This will check all ruby files recursively under the current directory.&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation.It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code.  Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices so that real-world Ruby programmers can write code that can be maintained by other real-world Ruby programmers. &lt;br /&gt;
Its purpose is to force you to write code that follows the style guide dictated by the Ruby community.&lt;br /&gt;
It warns that the class doesn’t have a top-level documentation comment, the parenthesis in the method declaration are unnecessary, and double-quote strings aren’t needed when there is no string interpolation.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files.&lt;br /&gt;
If you want Rubocop to scan only a few directories then you can pass those as arguments.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82995</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82995"/>
		<updated>2014-02-08T02:30:37Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Roodi */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
Flog can be installed using sudo gem install flog.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
It is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Roodi ====&lt;br /&gt;
Similar to Reek, Roodi can be used for refactoring the code and improving the design. The user can configure Roodi based on project requirements, like add a maximum limit to the number of parameters a method can have, threshold for cyclomatic complexity etc.&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation.It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code.  Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices so that real-world Ruby programmers can write code that can be maintained by other real-world Ruby programmers. &lt;br /&gt;
Its purpose is to force you to write code that follows the style guide dictated by the Ruby community.&lt;br /&gt;
It warns that the class doesn’t have a top-level documentation comment, the parenthesis in the method declaration are unnecessary, and double-quote strings aren’t needed when there is no string interpolation.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files.&lt;br /&gt;
If you want Rubocop to scan only a few directories then you can pass those as arguments.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82994</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82994"/>
		<updated>2014-02-08T02:25:24Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Roodi */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
Flog can be installed using sudo gem install flog.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
It is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
Roodi[https://github.com/roodi/roodi] stands for Ruby Object Oriented Design Inferometer. It is similar to reek in which it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
* '''AssignmentInConditionalCheck''' - Warns if there is an assignment inside a conditional&lt;br /&gt;
* '''CaseMissingElseCheck''' - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
* '''ClassLineCountCheck''' - Warns if the count of lines in a class is below threshold&lt;br /&gt;
* '''ClassNameCheck''' - Warns if class names do not match convention&lt;br /&gt;
* '''CyclomaticComplexityBlockCheck''' - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
* '''CyclomaticComplexityMethodChec'''k - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
* '''EmptyRescueBodyCheck''' - Warns if there are empty rescue blocks.&lt;br /&gt;
* '''ForLoopCheck''' - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
* '''MethodLineCountCheck''' - Warns if the number of lines in a method is above threshold&lt;br /&gt;
* '''MethodNameCheck''' - Warns if method names do not match convention.&lt;br /&gt;
* '''ModuleLineCountCheck''' - Warns if the number of lines in a module is above threshold&lt;br /&gt;
* '''ModuleNameCheck''' - Warns if module names do not match convention&lt;br /&gt;
* '''ParameterNumberCheck''' - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
&lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation.It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the route open source workflow. These Gems include:&lt;br /&gt;
* rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
* rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
* rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
* rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
* rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
* rufus-rtm – A Remember The Milk gem&lt;br /&gt;
* rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
* rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
* rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
* rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
* rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
* rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Rufus ====&lt;br /&gt;
Use Rufus when you are concerned about the safety of the code for e.g. to check whether it's safe before calling eval().&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity [http://en.wikipedia.org/wiki/Cyclomatic_complexity] is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program.&lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikuro each method has a complexity of 1 by default. For each of the following, Saikuro adds 1 to the cyclometic complexity:&lt;br /&gt;
* conditional and looping operator&lt;br /&gt;
* each when in a case&lt;br /&gt;
* rescue statements&lt;br /&gt;
* blocks like each&lt;br /&gt;
Saikuro counts the number of independent paths through the code.  Saikuro can also count the number of lines per method and the number of tokens per line. Higher numbers returned indicate more complex code. Complex code is less readable, more prone to bugs, harder to maintain and hard to test for all conditions.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Saikuro ====&lt;br /&gt;
* Code complexity doesn't always relate to bad code but code definitely can be refactored to be less complex.&lt;br /&gt;
* Allow multiple returns from a method, if it improves the readability and cyclomatic complexity.&lt;br /&gt;
* Try to reduce branches.&lt;br /&gt;
* If necesarry perform input validation using separate helper functions.&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices so that real-world Ruby programmers can write code that can be maintained by other real-world Ruby programmers. &lt;br /&gt;
Its purpose is to force you to write code that follows the style guide dictated by the Ruby community.&lt;br /&gt;
It warns that the class doesn’t have a top-level documentation comment, the parenthesis in the method declaration are unnecessary, and double-quote strings aren’t needed when there is no string interpolation.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files.&lt;br /&gt;
If you want Rubocop to scan only a few directories then you can pass those as arguments.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82989</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82989"/>
		<updated>2014-02-08T01:56:08Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Suggestions for  using Reek */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
Flog can be installed using sudo gem install flog.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
It is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you write the code for a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation.It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one.Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices so that real-world Ruby programmers can write code that can be maintained by other real-world Ruby programmers. &lt;br /&gt;
Its purpose is to force you to write code that follows the style guide dictated by the Ruby community.&lt;br /&gt;
It warns that the class doesn’t have a top-level documentation comment, the parenthesis in the method declaration are unnecessary, and double-quote strings aren’t needed when there is no string interpolation.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files.&lt;br /&gt;
If you want Rubocop to scan only a few directories then you can pass those as arguments.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82988</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82988"/>
		<updated>2014-02-08T01:55:34Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Reek */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
Flog can be installed using sudo gem install flog.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
It is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Reek ====&lt;br /&gt;
Reek warns about different design issues. Once you are done coding a feature, you can use Reek to refactor your code to improve your design without affecting the functionality of your program.&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus is written by John Mettraux. Ruby uses the standard ruby parse tree. Rufus uses this parse tree to convert code into SexpProcessor classes for evaluation.It checks for unsafe or potentially buggy code. The Rufus treechecker enable the developer to select what patterns to check errors for. The Rufus library allows to check some Ruby source code before loading it. The library can be configured to exclude code that matches some custom pattern.&lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one.Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices so that real-world Ruby programmers can write code that can be maintained by other real-world Ruby programmers. &lt;br /&gt;
Its purpose is to force you to write code that follows the style guide dictated by the Ruby community.&lt;br /&gt;
It warns that the class doesn’t have a top-level documentation comment, the parenthesis in the method declaration are unnecessary, and double-quote strings aren’t needed when there is no string interpolation.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files.&lt;br /&gt;
If you want Rubocop to scan only a few directories then you can pass those as arguments.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82976</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82976"/>
		<updated>2014-02-08T01:28:00Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Reek */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
Flog can be installed using sudo gem install flog.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
It is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
'''To install Reek:'''&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
'''To run it:'''&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus written by John Mettraux and uses the standard ruby parse tree. It allows to check Ruby for unwanted or unsafe code It uses this parse tree to convert this code into SexpProcessor classes that can then be evaluated. By using the Rufus treechecker the developer can dictate what patterns to generate errors for: The Rufus library allows to check some Ruby source code before loading it. Eg. loading a Ruby file that consists of a single line like exit is probably a bad idea. The library can be configured with custom patterns of code to be excluded. &lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one.Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices so that real-world Ruby programmers can write code that can be maintained by other real-world Ruby programmers. &lt;br /&gt;
Its purpose is to force you to write code that follows the style guide dictated by the Ruby community.&lt;br /&gt;
It warns that the class doesn’t have a top-level documentation comment, the parenthesis in the method declaration are unnecessary, and double-quote strings aren’t needed when there is no string interpolation.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files.&lt;br /&gt;
If you want Rubocop to scan only a few directories then you can pass those as arguments.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82975</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82975"/>
		<updated>2014-02-08T01:27:37Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Reek */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
Flog can be installed using sudo gem install flog.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
It is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
To install Reek:&lt;br /&gt;
&lt;br /&gt;
gem install reek&lt;br /&gt;
&lt;br /&gt;
To run it:&lt;br /&gt;
&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus written by John Mettraux and uses the standard ruby parse tree. It allows to check Ruby for unwanted or unsafe code It uses this parse tree to convert this code into SexpProcessor classes that can then be evaluated. By using the Rufus treechecker the developer can dictate what patterns to generate errors for: The Rufus library allows to check some Ruby source code before loading it. Eg. loading a Ruby file that consists of a single line like exit is probably a bad idea. The library can be configured with custom patterns of code to be excluded. &lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one.Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices so that real-world Ruby programmers can write code that can be maintained by other real-world Ruby programmers. &lt;br /&gt;
Its purpose is to force you to write code that follows the style guide dictated by the Ruby community.&lt;br /&gt;
It warns that the class doesn’t have a top-level documentation comment, the parenthesis in the method declaration are unnecessary, and double-quote strings aren’t needed when there is no string interpolation.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files.&lt;br /&gt;
If you want Rubocop to scan only a few directories then you can pass those as arguments.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82974</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82974"/>
		<updated>2014-02-08T01:26:58Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Reek */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
Flog can be installed using sudo gem install flog.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
It is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* '''Attribute''' - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* '''Class Variable'''s - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* '''Data Clump''' - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* '''Duplication''' - Warns when two fragments of code look nearly identical&lt;br /&gt;
* '''Irresponsible Module''' - Warns if classes or modules are not properly annotated&lt;br /&gt;
* '''Long Method''' - Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* '''Large Class''' - Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* '''Feature Envy''' - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* '''Uncommunicative Name''' - Warns if a name does not represent its intent well enough&lt;br /&gt;
* '''Long Parameter List''' - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* '''Utility Function''' - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* '''Nested Iterators''' - Warns if a block contains another block&lt;br /&gt;
* '''Simulated Polymorphism''' - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
To install Reek:&lt;br /&gt;
gem install reek&lt;br /&gt;
To run it:&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus written by John Mettraux and uses the standard ruby parse tree. It allows to check Ruby for unwanted or unsafe code It uses this parse tree to convert this code into SexpProcessor classes that can then be evaluated. By using the Rufus treechecker the developer can dictate what patterns to generate errors for: The Rufus library allows to check some Ruby source code before loading it. Eg. loading a Ruby file that consists of a single line like exit is probably a bad idea. The library can be configured with custom patterns of code to be excluded. &lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one.Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices so that real-world Ruby programmers can write code that can be maintained by other real-world Ruby programmers. &lt;br /&gt;
Its purpose is to force you to write code that follows the style guide dictated by the Ruby community.&lt;br /&gt;
It warns that the class doesn’t have a top-level documentation comment, the parenthesis in the method declaration are unnecessary, and double-quote strings aren’t needed when there is no string interpolation.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files.&lt;br /&gt;
If you want Rubocop to scan only a few directories then you can pass those as arguments.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82972</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82972"/>
		<updated>2014-02-08T01:23:45Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Reek */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for using Flay ====&lt;br /&gt;
* When working with large pieces of code.&lt;br /&gt;
* When trying to merge a branch into central trunk of code/product.&lt;br /&gt;
* When we suspect that we are writing code that looks to be doing the same thing logically.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
Flog can be installed using sudo gem install flog.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
It is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* Attribute - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* Class Variables - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* Data Clump - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* Duplication - Warns when two fragments of code look nearly identical&lt;br /&gt;
* Irresponsible Module - Warns if classes or modules are not properly annotated&lt;br /&gt;
* Long Method -Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* Large Class -Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* Feature Envy - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* Uncommunicative Name - Warns if a name does not represent its intent well enough&lt;br /&gt;
* Long Parameter List - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* Utility Function - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* Nested Iterators - Warns if a block contains another block&lt;br /&gt;
* Simulated Polymorphism - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
To install Reek:&lt;br /&gt;
gem install reek&lt;br /&gt;
To run it:&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus written by John Mettraux and uses the standard ruby parse tree. It allows to check Ruby for unwanted or unsafe code It uses this parse tree to convert this code into SexpProcessor classes that can then be evaluated. By using the Rufus treechecker the developer can dictate what patterns to generate errors for: The Rufus library allows to check some Ruby source code before loading it. Eg. loading a Ruby file that consists of a single line like exit is probably a bad idea. The library can be configured with custom patterns of code to be excluded. &lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one.Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices so that real-world Ruby programmers can write code that can be maintained by other real-world Ruby programmers. &lt;br /&gt;
Its purpose is to force you to write code that follows the style guide dictated by the Ruby community.&lt;br /&gt;
It warns that the class doesn’t have a top-level documentation comment, the parenthesis in the method declaration are unnecessary, and double-quote strings aren’t needed when there is no string interpolation.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files.&lt;br /&gt;
If you want Rubocop to scan only a few directories then you can pass those as arguments.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82969</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82969"/>
		<updated>2014-02-08T01:22:12Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Reek */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls)[http://www.google.com/url?q=http%3A%2F%2Fwww.c2.com%2Fcgi%2Fwiki%3FAbcMetric&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFQjCNFXjBtkgDdueuhiniIgXzNNykamPw] metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused. Excessive use signifies code is too complex and could be refactored.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
Flog Scoring&lt;br /&gt;
Flog parses Ruby code and builds up a structure of the code using RubyParser. A complete listing of the scores assigned can be found in the source code [https://github.com/seattlerb/flog/blob/master/lib/flog.rb#L13-67]. A sub-list of the typical code segments and corresponding flog scores is:&lt;br /&gt;
* method call - 0.2&lt;br /&gt;
* assignments - 1&lt;br /&gt;
* branching (and, case, else, if, or, rescue, until, when, while) - 1&lt;br /&gt;
* block - 1&lt;br /&gt;
* class_eval - 5&lt;br /&gt;
* define_method - 5&lt;br /&gt;
* eval - 5&lt;br /&gt;
* extend - 2&lt;br /&gt;
* include - 2&lt;br /&gt;
* inject - 2&lt;br /&gt;
&lt;br /&gt;
Flog goes through every class and method and scores everything. In the end we get a complete breakdown of the scores of each class and method. These scores can give us an idea of the complexity and quality of code. We can also use this to compare different pieces of code with each other.&lt;br /&gt;
&lt;br /&gt;
==== Suggestions for  using Flog ====&lt;br /&gt;
* Use Flog when refactoring legacy code or code under development when continuous refactoring is to be done.&lt;br /&gt;
* You can focus your refactoring efforts the parts of code which have the highest scores. &lt;br /&gt;
* A rule of thumb for Flog scores is that any code with a score of 40 or above should be refactored.&lt;br /&gt;
* Flog scores are related to the sum of ABCs. One way to reduce the Flog score is to split the methods and make the code more cohesive.&lt;br /&gt;
* To learn more about how to refactor code that recieved high flog score, refer to this page [http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+RailsInside+%28Rails+Inside%29].&lt;br /&gt;
&lt;br /&gt;
Flog can be installed using sudo gem install flog.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
Is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code, either source files or in-memory Class objects, looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
* Attribute - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
* Class Variables - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
* Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
* Data Clump - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
* Duplication - Warns when two fragments of code look nearly identical&lt;br /&gt;
* Irresponsible Module - Warns if classes or modules are not properly annotated&lt;br /&gt;
* Long Method -Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
* Large Class -Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
* Feature Envy - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
* Uncommunicative Name - Warns if a name does not represent its intent well enough&lt;br /&gt;
* Long Parameter List - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
* Utility Function - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
* Nested Iterators - Warns if a block contains another block&lt;br /&gt;
* Simulated Polymorphism - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
To install Reek:&lt;br /&gt;
gem install reek&lt;br /&gt;
To run it:&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus written by John Mettraux and uses the standard ruby parse tree. It allows to check Ruby for unwanted or unsafe code It uses this parse tree to convert this code into SexpProcessor classes that can then be evaluated. By using the Rufus treechecker the developer can dictate what patterns to generate errors for: The Rufus library allows to check some Ruby source code before loading it. Eg. loading a Ruby file that consists of a single line like exit is probably a bad idea. The library can be configured with custom patterns of code to be excluded. &lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one.Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices so that real-world Ruby programmers can write code that can be maintained by other real-world Ruby programmers. &lt;br /&gt;
Its purpose is to force you to write code that follows the style guide dictated by the Ruby community.&lt;br /&gt;
It warns that the class doesn’t have a top-level documentation comment, the parenthesis in the method declaration are unnecessary, and double-quote strings aren’t needed when there is no string interpolation.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files.&lt;br /&gt;
If you want Rubocop to scan only a few directories then you can pass those as arguments.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82966</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82966"/>
		<updated>2014-02-08T01:10:13Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Ruby-lint */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
INSTALL:&lt;br /&gt;
sudo gem install flog&lt;br /&gt;
Flog Scoring&lt;br /&gt;
When flog is given Ruby code, flog parses it and builds up a structure of the code internally using RubyParser. A complete listing of all the scores assigned can be found in the source code. When it goes through every class and method until everything is scored. What you end up with is a breakdown of how each class and method scored.&lt;br /&gt;
&lt;br /&gt;
Using the scoring, you can get an idea of how complex or poorly written a piece of code is compared to other code. You can focus your refactoring efforts the parts of code which have the highest scores. A good rule of thumb for Flog scores is that you will want to eventually refactor or at least think about refactoring any method when it has a score of 40 or more.&lt;br /&gt;
Since flog scores are totals of all of the assignments, branches, and calls; using a refactoring method that splits a section of code in two is usually a good first refactoring to perform. To learn more about how to refactor code that recieved high flog score, refer to this page.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
Is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code — either source files or in-memory Class objects — looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
Attribute - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
Class Variables - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
Data Clump - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
Duplication - Warns when two fragments of code look nearly identical&lt;br /&gt;
Irresponsible Module - Warns if classes or modules are not properly annotated&lt;br /&gt;
&lt;br /&gt;
Long Method -Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
Large Class -Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
Feature Envy - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
Uncommunicative Name - Warns if a name does not represent its intent well enough&lt;br /&gt;
Long Parameter List - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
Utility Function - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
Nested Iterators - Warns if a block contains another block&lt;br /&gt;
Simulated Polymorphism - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
To install Reek:&lt;br /&gt;
gem install reek&lt;br /&gt;
To run it:&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus written by John Mettraux and uses the standard ruby parse tree. It allows to check Ruby for unwanted or unsafe code It uses this parse tree to convert this code into SexpProcessor classes that can then be evaluated. By using the Rufus treechecker the developer can dictate what patterns to generate errors for: The Rufus library allows to check some Ruby source code before loading it. Eg. loading a Ruby file that consists of a single line like exit is probably a bad idea. The library can be configured with custom patterns of code to be excluded. &lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one.Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices so that real-world Ruby programmers can write code that can be maintained by other real-world Ruby programmers. &lt;br /&gt;
Its purpose is to force you to write code that follows the style guide dictated by the Ruby community.&lt;br /&gt;
It warns that the class doesn’t have a top-level documentation comment, the parenthesis in the method declaration are unnecessary, and double-quote strings aren’t needed when there is no string interpolation.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files.&lt;br /&gt;
If you want Rubocop to scan only a few directories then you can pass those as arguments.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82965</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82965"/>
		<updated>2014-02-08T01:07:47Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Rubocop */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
INSTALL:&lt;br /&gt;
sudo gem install flog&lt;br /&gt;
Flog Scoring&lt;br /&gt;
When flog is given Ruby code, flog parses it and builds up a structure of the code internally using RubyParser. A complete listing of all the scores assigned can be found in the source code. When it goes through every class and method until everything is scored. What you end up with is a breakdown of how each class and method scored.&lt;br /&gt;
&lt;br /&gt;
Using the scoring, you can get an idea of how complex or poorly written a piece of code is compared to other code. You can focus your refactoring efforts the parts of code which have the highest scores. A good rule of thumb for Flog scores is that you will want to eventually refactor or at least think about refactoring any method when it has a score of 40 or more.&lt;br /&gt;
Since flog scores are totals of all of the assignments, branches, and calls; using a refactoring method that splits a section of code in two is usually a good first refactoring to perform. To learn more about how to refactor code that recieved high flog score, refer to this page.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
Is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code — either source files or in-memory Class objects — looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
Attribute - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
Class Variables - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
Data Clump - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
Duplication - Warns when two fragments of code look nearly identical&lt;br /&gt;
Irresponsible Module - Warns if classes or modules are not properly annotated&lt;br /&gt;
&lt;br /&gt;
Long Method -Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
Large Class -Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
Feature Envy - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
Uncommunicative Name - Warns if a name does not represent its intent well enough&lt;br /&gt;
Long Parameter List - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
Utility Function - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
Nested Iterators - Warns if a block contains another block&lt;br /&gt;
Simulated Polymorphism - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
To install Reek:&lt;br /&gt;
gem install reek&lt;br /&gt;
To run it:&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus written by John Mettraux and uses the standard ruby parse tree. It allows to check Ruby for unwanted or unsafe code It uses this parse tree to convert this code into SexpProcessor classes that can then be evaluated. By using the Rufus treechecker the developer can dictate what patterns to generate errors for: The Rufus library allows to check some Ruby source code before loading it. Eg. loading a Ruby file that consists of a single line like exit is probably a bad idea. The library can be configured with custom patterns of code to be excluded. &lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one.Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Ruby-lint === &lt;br /&gt;
Ruby-lint is a linter and static code analysis tool for Ruby. [http://www.omniref.com/ruby/gems/ruby-lint].ruby-lint primarily focuses on logic related errors such as the use of non existing variables instead of focusing on semantics&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer based on the Ruby Style Guide. This Ruby style[https://github.com/bbatsov/ruby-style-guide] guide recommends best practices so that real-world Ruby programmers can write code that can be maintained by other real-world Ruby programmers. &lt;br /&gt;
Its purpose is to force you to write code that follows the style guide dictated by the Ruby community.&lt;br /&gt;
It warns that the class doesn’t have a top-level documentation comment, the parenthesis in the method declaration are unnecessary, and double-quote strings aren’t needed when there is no string interpolation.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
&lt;br /&gt;
cd your_app&lt;br /&gt;
&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files.&lt;br /&gt;
If you want Rubocop to scan only a few directories then you can pass those as arguments.&lt;br /&gt;
&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82964</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82964"/>
		<updated>2014-02-08T00:53:59Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Rubocop */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. Thus we could replace this with a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
* Code at all levels is checked.&lt;br /&gt;
* Identical nodes are counted.&lt;br /&gt;
* Ignores differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc.&lt;br /&gt;
* Works across files.&lt;br /&gt;
* You can view a diff of code acroos versions.&lt;br /&gt;
* Option to do conservative and libreal pruning.&lt;br /&gt;
* Fuzzy duplication detection.&lt;br /&gt;
* Language independent.&lt;br /&gt;
* Ships with .rb and .erb.&lt;br /&gt;
* Checks for Rakefiles also.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
INSTALL:&lt;br /&gt;
sudo gem install flog&lt;br /&gt;
Flog Scoring&lt;br /&gt;
When flog is given Ruby code, flog parses it and builds up a structure of the code internally using RubyParser. A complete listing of all the scores assigned can be found in the source code. When it goes through every class and method until everything is scored. What you end up with is a breakdown of how each class and method scored.&lt;br /&gt;
&lt;br /&gt;
Using the scoring, you can get an idea of how complex or poorly written a piece of code is compared to other code. You can focus your refactoring efforts the parts of code which have the highest scores. A good rule of thumb for Flog scores is that you will want to eventually refactor or at least think about refactoring any method when it has a score of 40 or more.&lt;br /&gt;
Since flog scores are totals of all of the assignments, branches, and calls; using a refactoring method that splits a section of code in two is usually a good first refactoring to perform. To learn more about how to refactor code that recieved high flog score, refer to this page.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
Is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code — either source files or in-memory Class objects — looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
Attribute - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
Class Variables - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
Data Clump - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
Duplication - Warns when two fragments of code look nearly identical&lt;br /&gt;
Irresponsible Module - Warns if classes or modules are not properly annotated&lt;br /&gt;
&lt;br /&gt;
Long Method -Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
Large Class -Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
Feature Envy - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
Uncommunicative Name - Warns if a name does not represent its intent well enough&lt;br /&gt;
Long Parameter List - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
Utility Function - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
Nested Iterators - Warns if a block contains another block&lt;br /&gt;
Simulated Polymorphism - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
To install Reek:&lt;br /&gt;
gem install reek&lt;br /&gt;
To run it:&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus written by John Mettraux and uses the standard ruby parse tree. It allows to check Ruby for unwanted or unsafe code It uses this parse tree to convert this code into SexpProcessor classes that can then be evaluated. By using the Rufus treechecker the developer can dictate what patterns to generate errors for: The Rufus library allows to check some Ruby source code before loading it. Eg. loading a Ruby file that consists of a single line like exit is probably a bad idea. The library can be configured with custom patterns of code to be excluded. &lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one.Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Ruby-lint === &lt;br /&gt;
Ruby-lint is a linter and static code analysis tool for Ruby. [http://www.omniref.com/ruby/gems/ruby-lint].ruby-lint primarily focuses on logic related errors such as the use of non existing variables instead of focusing on semantics&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer.Its purpose is to force you to write code that follows the style guide dictated by the Ruby community.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
You can run Rubocop directly in your app directory.&lt;br /&gt;
cd your_app&lt;br /&gt;
rubocop&lt;br /&gt;
&lt;br /&gt;
Rubocop will review All your Ruby files in your application, including your gem files.&lt;br /&gt;
If you want Rubocop to scan only a few directories then you can pass those as arguments.&lt;br /&gt;
rubocop app spec config/application.rb&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82962</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82962"/>
		<updated>2014-02-08T00:48:20Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Rubocop */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. This means that we could have written a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [[http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]]&lt;br /&gt;
FEATURES/PROBLEMS:&lt;br /&gt;
Reports differences at any level of code.&lt;br /&gt;
Adds a score multiplier to identical nodes.&lt;br /&gt;
Differences in literal values, variable, class, and method names are ignored.&lt;br /&gt;
Differences in whitespace, programming style, braces vs do/end, etc are ignored.&lt;br /&gt;
Works across files.&lt;br /&gt;
Add the flay-persistent plugin to work across large/many projects.&lt;br /&gt;
Run –diff to see an N-way diff of the code.&lt;br /&gt;
Provides conservative (default) and –liberal pruning options.&lt;br /&gt;
Provides –fuzzy duplication detection.&lt;br /&gt;
Language independent: Plugin system allows other languages to be flayed.&lt;br /&gt;
Ships with .rb and .erb.&lt;br /&gt;
javascript and others will be available separately.&lt;br /&gt;
Includes FlayTask for Rakefiles.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
INSTALL:&lt;br /&gt;
sudo gem install flog&lt;br /&gt;
Flog Scoring&lt;br /&gt;
When flog is given Ruby code, flog parses it and builds up a structure of the code internally using RubyParser. A complete listing of all the scores assigned can be found in the source code. When it goes through every class and method until everything is scored. What you end up with is a breakdown of how each class and method scored.&lt;br /&gt;
&lt;br /&gt;
Using the scoring, you can get an idea of how complex or poorly written a piece of code is compared to other code. You can focus your refactoring efforts the parts of code which have the highest scores. A good rule of thumb for Flog scores is that you will want to eventually refactor or at least think about refactoring any method when it has a score of 40 or more.&lt;br /&gt;
Since flog scores are totals of all of the assignments, branches, and calls; using a refactoring method that splits a section of code in two is usually a good first refactoring to perform. To learn more about how to refactor code that recieved high flog score, refer to this page.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
Is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code — either source files or in-memory Class objects — looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
Attribute - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
Class Variables - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
Data Clump - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
Duplication - Warns when two fragments of code look nearly identical&lt;br /&gt;
Irresponsible Module - Warns if classes or modules are not properly annotated&lt;br /&gt;
&lt;br /&gt;
Long Method -Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
Large Class -Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
Feature Envy - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
Uncommunicative Name - Warns if a name does not represent its intent well enough&lt;br /&gt;
Long Parameter List - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
Utility Function - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
Nested Iterators - Warns if a block contains another block&lt;br /&gt;
Simulated Polymorphism - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
To install Reek:&lt;br /&gt;
gem install reek&lt;br /&gt;
To run it:&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus written by John Mettraux and uses the standard ruby parse tree. It allows to check Ruby for unwanted or unsafe code It uses this parse tree to convert this code into SexpProcessor classes that can then be evaluated. By using the Rufus treechecker the developer can dictate what patterns to generate errors for: The Rufus library allows to check some Ruby source code before loading it. Eg. loading a Ruby file that consists of a single line like exit is probably a bad idea. The library can be configured with custom patterns of code to be excluded. &lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one.Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Ruby-lint === &lt;br /&gt;
Ruby-lint is a linter and static code analysis tool for Ruby. [http://www.omniref.com/ruby/gems/ruby-lint].ruby-lint primarily focuses on logic related errors such as the use of non existing variables instead of focusing on semantics&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide.&lt;br /&gt;
&lt;br /&gt;
'''To Install Rubocop''': gem install rubocop&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82961</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82961"/>
		<updated>2014-02-08T00:47:04Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Rubocop */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated with the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
There are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool if clearly superior or does everything that another tool does. Hence, it is important to evaluate their effectiveness, know their features and use the one most suited for our needs.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that is not relevant in the context of the current code or project.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
&lt;br /&gt;
There are other related metrics too such as:&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
Static analysis tools analyze the tools without any knowledge of the constraints and assumptions of the programmer. Hence, generally static analysis tools may have the following problems:&lt;br /&gt;
* The tool may show true positives, but less important defects.&lt;br /&gt;
* The bugs shown may be known issues.&lt;br /&gt;
* Bug warnings may be related to error conditions that will never occur.&lt;br /&gt;
* Less impact bugs.&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. This means that we could have written a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [[Flay]]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [[http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]]&lt;br /&gt;
FEATURES/PROBLEMS:&lt;br /&gt;
Reports differences at any level of code.&lt;br /&gt;
Adds a score multiplier to identical nodes.&lt;br /&gt;
Differences in literal values, variable, class, and method names are ignored.&lt;br /&gt;
Differences in whitespace, programming style, braces vs do/end, etc are ignored.&lt;br /&gt;
Works across files.&lt;br /&gt;
Add the flay-persistent plugin to work across large/many projects.&lt;br /&gt;
Run –diff to see an N-way diff of the code.&lt;br /&gt;
Provides conservative (default) and –liberal pruning options.&lt;br /&gt;
Provides –fuzzy duplication detection.&lt;br /&gt;
Language independent: Plugin system allows other languages to be flayed.&lt;br /&gt;
Ships with .rb and .erb.&lt;br /&gt;
javascript and others will be available separately.&lt;br /&gt;
Includes FlayTask for Rakefiles.&lt;br /&gt;
&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
INSTALL:&lt;br /&gt;
sudo gem install flog&lt;br /&gt;
Flog Scoring&lt;br /&gt;
When flog is given Ruby code, flog parses it and builds up a structure of the code internally using RubyParser. A complete listing of all the scores assigned can be found in the source code. When it goes through every class and method until everything is scored. What you end up with is a breakdown of how each class and method scored.&lt;br /&gt;
&lt;br /&gt;
Using the scoring, you can get an idea of how complex or poorly written a piece of code is compared to other code. You can focus your refactoring efforts the parts of code which have the highest scores. A good rule of thumb for Flog scores is that you will want to eventually refactor or at least think about refactoring any method when it has a score of 40 or more.&lt;br /&gt;
Since flog scores are totals of all of the assignments, branches, and calls; using a refactoring method that splits a section of code in two is usually a good first refactoring to perform. To learn more about how to refactor code that recieved high flog score, refer to this page.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
Is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code — either source files or in-memory Class objects — looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
Attribute - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
Class Variables - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
Data Clump - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
Duplication - Warns when two fragments of code look nearly identical&lt;br /&gt;
Irresponsible Module - Warns if classes or modules are not properly annotated&lt;br /&gt;
&lt;br /&gt;
Long Method -Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
Large Class -Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
Feature Envy - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
Uncommunicative Name - Warns if a name does not represent its intent well enough&lt;br /&gt;
Long Parameter List - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
Utility Function - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
Nested Iterators - Warns if a block contains another block&lt;br /&gt;
Simulated Polymorphism - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
To install Reek:&lt;br /&gt;
gem install reek&lt;br /&gt;
To run it:&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus written by John Mettraux and uses the standard ruby parse tree. It allows to check Ruby for unwanted or unsafe code It uses this parse tree to convert this code into SexpProcessor classes that can then be evaluated. By using the Rufus treechecker the developer can dictate what patterns to generate errors for: The Rufus library allows to check some Ruby source code before loading it. Eg. loading a Ruby file that consists of a single line like exit is probably a bad idea. The library can be configured with custom patterns of code to be excluded. &lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one.Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Ruby-lint === &lt;br /&gt;
Ruby-lint is a linter and static code analysis tool for Ruby. [http://www.omniref.com/ruby/gems/ruby-lint].ruby-lint primarily focuses on logic related errors such as the use of non existing variables instead of focusing on semantics&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide.&lt;br /&gt;
&lt;br /&gt;
=== Problems one might want to attack and how to solve them ===&lt;br /&gt;
=== Recommendations about tools ===&lt;br /&gt;
=== Hyperlink to terms and references ===&lt;br /&gt;
=== References ===&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82958</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82958"/>
		<updated>2014-02-08T00:30:44Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Rufus */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated by the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
&lt;br /&gt;
Now, there are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool completely subsumes all the other and hence there is no clear winner. In such a situation, it becomes necessary to evaluate the effectiveness of these tools.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that isn't really a bug.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug and leads to a fix.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
This leads to the definition of other related metrics such as :&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. This means that we could have written a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [Flay]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
FEATURES/PROBLEMS:&lt;br /&gt;
Reports differences at any level of code.&lt;br /&gt;
Adds a score multiplier to identical nodes.&lt;br /&gt;
Differences in literal values, variable, class, and method names are ignored.&lt;br /&gt;
Differences in whitespace, programming style, braces vs do/end, etc are ignored.&lt;br /&gt;
Works across files.&lt;br /&gt;
Add the flay-persistent plugin to work across large/many projects.&lt;br /&gt;
Run –diff to see an N-way diff of the code.&lt;br /&gt;
Provides conservative (default) and –liberal pruning options.&lt;br /&gt;
Provides –fuzzy duplication detection.&lt;br /&gt;
Language independent: Plugin system allows other languages to be flayed.&lt;br /&gt;
Ships with .rb and .erb.&lt;br /&gt;
javascript and others will be available separately.&lt;br /&gt;
Includes FlayTask for Rakefiles.&lt;br /&gt;
		&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
INSTALL:&lt;br /&gt;
sudo gem install flog&lt;br /&gt;
Flog Scoring&lt;br /&gt;
When flog is given Ruby code, flog parses it and builds up a structure of the code internally using RubyParser. A complete listing of all the scores assigned can be found in the source code. When it goes through every class and method until everything is scored. What you end up with is a breakdown of how each class and method scored.&lt;br /&gt;
&lt;br /&gt;
Using the scoring, you can get an idea of how complex or poorly written a piece of code is compared to other code. You can focus your refactoring efforts the parts of code which have the highest scores. A good rule of thumb for Flog scores is that you will want to eventually refactor or at least think about refactoring any method when it has a score of 40 or more.&lt;br /&gt;
Since flog scores are totals of all of the assignments, branches, and calls; using a refactoring method that splits a section of code in two is usually a good first refactoring to perform. To learn more about how to refactor code that recieved high flog score, refer to this page.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
Is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code — either source files or in-memory Class objects — looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
Attribute - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
Class Variables - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
Data Clump - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
Duplication - Warns when two fragments of code look nearly identical&lt;br /&gt;
Irresponsible Module - Warns if classes or modules are not properly annotated&lt;br /&gt;
&lt;br /&gt;
Long Method -Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
Large Class -Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
Feature Envy - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
Uncommunicative Name - Warns if a name does not represent its intent well enough&lt;br /&gt;
Long Parameter List - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
Utility Function - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
Nested Iterators - Warns if a block contains another block&lt;br /&gt;
Simulated Polymorphism - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
To install Reek:&lt;br /&gt;
gem install reek&lt;br /&gt;
To run it:&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus written by John Mettraux and uses the standard ruby parse tree. It allows to check Ruby for unwanted or unsafe code It uses this parse tree to convert this code into SexpProcessor classes that can then be evaluated. By using the Rufus treechecker the developer can dictate what patterns to generate errors for: The Rufus library allows to check some Ruby source code before loading it. Eg. loading a Ruby file that consists of a single line like exit is probably a bad idea. The library can be configured with custom patterns of code to be excluded. &lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro[http://saikuro.rubyforge.org/] is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one.Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Ruby-lint === &lt;br /&gt;
Ruby-lint is a linter and static code analysis tool for Ruby. [http://www.omniref.com/ruby/gems/ruby-lint].ruby-lint primarily focuses on logic related errors such as the use of non existing variables instead of focusing on semantics&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide.&lt;br /&gt;
&lt;br /&gt;
Problems one might want to attack and how to solve them&lt;br /&gt;
Recommendations about tools&lt;br /&gt;
Hyperlink to terms and references&lt;br /&gt;
References&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82957</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82957"/>
		<updated>2014-02-08T00:27:22Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Saikuro */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated by the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
&lt;br /&gt;
Now, there are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool completely subsumes all the other and hence there is no clear winner. In such a situation, it becomes necessary to evaluate the effectiveness of these tools.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that isn't really a bug.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug and leads to a fix.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
This leads to the definition of other related metrics such as :&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. This means that we could have written a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [Flay]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
FEATURES/PROBLEMS:&lt;br /&gt;
Reports differences at any level of code.&lt;br /&gt;
Adds a score multiplier to identical nodes.&lt;br /&gt;
Differences in literal values, variable, class, and method names are ignored.&lt;br /&gt;
Differences in whitespace, programming style, braces vs do/end, etc are ignored.&lt;br /&gt;
Works across files.&lt;br /&gt;
Add the flay-persistent plugin to work across large/many projects.&lt;br /&gt;
Run –diff to see an N-way diff of the code.&lt;br /&gt;
Provides conservative (default) and –liberal pruning options.&lt;br /&gt;
Provides –fuzzy duplication detection.&lt;br /&gt;
Language independent: Plugin system allows other languages to be flayed.&lt;br /&gt;
Ships with .rb and .erb.&lt;br /&gt;
javascript and others will be available separately.&lt;br /&gt;
Includes FlayTask for Rakefiles.&lt;br /&gt;
		&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
INSTALL:&lt;br /&gt;
sudo gem install flog&lt;br /&gt;
Flog Scoring&lt;br /&gt;
When flog is given Ruby code, flog parses it and builds up a structure of the code internally using RubyParser. A complete listing of all the scores assigned can be found in the source code. When it goes through every class and method until everything is scored. What you end up with is a breakdown of how each class and method scored.&lt;br /&gt;
&lt;br /&gt;
Using the scoring, you can get an idea of how complex or poorly written a piece of code is compared to other code. You can focus your refactoring efforts the parts of code which have the highest scores. A good rule of thumb for Flog scores is that you will want to eventually refactor or at least think about refactoring any method when it has a score of 40 or more.&lt;br /&gt;
Since flog scores are totals of all of the assignments, branches, and calls; using a refactoring method that splits a section of code in two is usually a good first refactoring to perform. To learn more about how to refactor code that recieved high flog score, refer to this page.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
Is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code — either source files or in-memory Class objects — looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
Attribute - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
Class Variables - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
Data Clump - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
Duplication - Warns when two fragments of code look nearly identical&lt;br /&gt;
Irresponsible Module - Warns if classes or modules are not properly annotated&lt;br /&gt;
&lt;br /&gt;
Long Method -Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
Large Class -Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
Feature Envy - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
Uncommunicative Name - Warns if a name does not represent its intent well enough&lt;br /&gt;
Long Parameter List - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
Utility Function - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
Nested Iterators - Warns if a block contains another block&lt;br /&gt;
Simulated Polymorphism - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
To install Reek:&lt;br /&gt;
gem install reek&lt;br /&gt;
To run it:&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus written by John Mettraux and uses the standard ruby parse tree. It allows to check Ruby for unwanted or unsafe code It uses this parse tree to convert this code into SexpProcessor classes that can then be evaluated. By using the Rufus treechecker the developer can dictate what patterns to generate errors for: The Rufus library allows to check some Ruby source code before loading it. Eg. loading a Ruby file that consists of a single line like exit is probably a bad idea. The library can be configured with custom patterns of code to be excluded. &lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === [http://saikuro.rubyforge.org/]&lt;br /&gt;
Saikuro is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one.Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Ruby-lint === &lt;br /&gt;
Ruby-lint is a linter and static code analysis tool for Ruby. [http://www.omniref.com/ruby/gems/ruby-lint].ruby-lint primarily focuses on logic related errors such as the use of non existing variables instead of focusing on semantics&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide.&lt;br /&gt;
&lt;br /&gt;
Problems one might want to attack and how to solve them&lt;br /&gt;
Recommendations about tools&lt;br /&gt;
Hyperlink to terms and references&lt;br /&gt;
References&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82956</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82956"/>
		<updated>2014-02-08T00:27:08Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Rufus */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated by the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
&lt;br /&gt;
Now, there are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool completely subsumes all the other and hence there is no clear winner. In such a situation, it becomes necessary to evaluate the effectiveness of these tools.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that isn't really a bug.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug and leads to a fix.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
This leads to the definition of other related metrics such as :&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. This means that we could have written a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [Flay]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
FEATURES/PROBLEMS:&lt;br /&gt;
Reports differences at any level of code.&lt;br /&gt;
Adds a score multiplier to identical nodes.&lt;br /&gt;
Differences in literal values, variable, class, and method names are ignored.&lt;br /&gt;
Differences in whitespace, programming style, braces vs do/end, etc are ignored.&lt;br /&gt;
Works across files.&lt;br /&gt;
Add the flay-persistent plugin to work across large/many projects.&lt;br /&gt;
Run –diff to see an N-way diff of the code.&lt;br /&gt;
Provides conservative (default) and –liberal pruning options.&lt;br /&gt;
Provides –fuzzy duplication detection.&lt;br /&gt;
Language independent: Plugin system allows other languages to be flayed.&lt;br /&gt;
Ships with .rb and .erb.&lt;br /&gt;
javascript and others will be available separately.&lt;br /&gt;
Includes FlayTask for Rakefiles.&lt;br /&gt;
		&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
INSTALL:&lt;br /&gt;
sudo gem install flog&lt;br /&gt;
Flog Scoring&lt;br /&gt;
When flog is given Ruby code, flog parses it and builds up a structure of the code internally using RubyParser. A complete listing of all the scores assigned can be found in the source code. When it goes through every class and method until everything is scored. What you end up with is a breakdown of how each class and method scored.&lt;br /&gt;
&lt;br /&gt;
Using the scoring, you can get an idea of how complex or poorly written a piece of code is compared to other code. You can focus your refactoring efforts the parts of code which have the highest scores. A good rule of thumb for Flog scores is that you will want to eventually refactor or at least think about refactoring any method when it has a score of 40 or more.&lt;br /&gt;
Since flog scores are totals of all of the assignments, branches, and calls; using a refactoring method that splits a section of code in two is usually a good first refactoring to perform. To learn more about how to refactor code that recieved high flog score, refer to this page.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
Is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code — either source files or in-memory Class objects — looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
Attribute - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
Class Variables - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
Data Clump - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
Duplication - Warns when two fragments of code look nearly identical&lt;br /&gt;
Irresponsible Module - Warns if classes or modules are not properly annotated&lt;br /&gt;
&lt;br /&gt;
Long Method -Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
Large Class -Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
Feature Envy - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
Uncommunicative Name - Warns if a name does not represent its intent well enough&lt;br /&gt;
Long Parameter List - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
Utility Function - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
Nested Iterators - Warns if a block contains another block&lt;br /&gt;
Simulated Polymorphism - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
To install Reek:&lt;br /&gt;
gem install reek&lt;br /&gt;
To run it:&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus written by John Mettraux and uses the standard ruby parse tree. It allows to check Ruby for unwanted or unsafe code It uses this parse tree to convert this code into SexpProcessor classes that can then be evaluated. By using the Rufus treechecker the developer can dictate what patterns to generate errors for: The Rufus library allows to check some Ruby source code before loading it. Eg. loading a Ruby file that consists of a single line like exit is probably a bad idea. The library can be configured with custom patterns of code to be excluded. &lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one.Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Ruby-lint === &lt;br /&gt;
Ruby-lint is a linter and static code analysis tool for Ruby. [http://www.omniref.com/ruby/gems/ruby-lint].ruby-lint primarily focuses on logic related errors such as the use of non existing variables instead of focusing on semantics&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide.&lt;br /&gt;
&lt;br /&gt;
Problems one might want to attack and how to solve them&lt;br /&gt;
Recommendations about tools&lt;br /&gt;
Hyperlink to terms and references&lt;br /&gt;
References&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82955</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82955"/>
		<updated>2014-02-08T00:26:23Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* [Saikuro] */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated by the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
&lt;br /&gt;
Now, there are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool completely subsumes all the other and hence there is no clear winner. In such a situation, it becomes necessary to evaluate the effectiveness of these tools.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that isn't really a bug.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug and leads to a fix.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
This leads to the definition of other related metrics such as :&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. This means that we could have written a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [Flay]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
FEATURES/PROBLEMS:&lt;br /&gt;
Reports differences at any level of code.&lt;br /&gt;
Adds a score multiplier to identical nodes.&lt;br /&gt;
Differences in literal values, variable, class, and method names are ignored.&lt;br /&gt;
Differences in whitespace, programming style, braces vs do/end, etc are ignored.&lt;br /&gt;
Works across files.&lt;br /&gt;
Add the flay-persistent plugin to work across large/many projects.&lt;br /&gt;
Run –diff to see an N-way diff of the code.&lt;br /&gt;
Provides conservative (default) and –liberal pruning options.&lt;br /&gt;
Provides –fuzzy duplication detection.&lt;br /&gt;
Language independent: Plugin system allows other languages to be flayed.&lt;br /&gt;
Ships with .rb and .erb.&lt;br /&gt;
javascript and others will be available separately.&lt;br /&gt;
Includes FlayTask for Rakefiles.&lt;br /&gt;
		&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
INSTALL:&lt;br /&gt;
sudo gem install flog&lt;br /&gt;
Flog Scoring&lt;br /&gt;
When flog is given Ruby code, flog parses it and builds up a structure of the code internally using RubyParser. A complete listing of all the scores assigned can be found in the source code. When it goes through every class and method until everything is scored. What you end up with is a breakdown of how each class and method scored.&lt;br /&gt;
&lt;br /&gt;
Using the scoring, you can get an idea of how complex or poorly written a piece of code is compared to other code. You can focus your refactoring efforts the parts of code which have the highest scores. A good rule of thumb for Flog scores is that you will want to eventually refactor or at least think about refactoring any method when it has a score of 40 or more.&lt;br /&gt;
Since flog scores are totals of all of the assignments, branches, and calls; using a refactoring method that splits a section of code in two is usually a good first refactoring to perform. To learn more about how to refactor code that recieved high flog score, refer to this page.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
Is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code — either source files or in-memory Class objects — looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
Attribute - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
Class Variables - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
Data Clump - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
Duplication - Warns when two fragments of code look nearly identical&lt;br /&gt;
Irresponsible Module - Warns if classes or modules are not properly annotated&lt;br /&gt;
&lt;br /&gt;
Long Method -Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
Large Class -Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
Feature Envy - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
Uncommunicative Name - Warns if a name does not represent its intent well enough&lt;br /&gt;
Long Parameter List - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
Utility Function - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
Nested Iterators - Warns if a block contains another block&lt;br /&gt;
Simulated Polymorphism - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
To install Reek:&lt;br /&gt;
gem install reek&lt;br /&gt;
To run it:&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus written by John Mettraux and uses the standard ruby parse tree. It allows to check Ruby for unwanted or unsafe code It uses this parse tree to convert this code into SexpProcessor classes that can then be evaluated. By using the Rufus treechecker the developer can dictate what patterns to generate errors for: The Rufus library allows to check some Ruby source code before loading it. Eg. loading a Ruby file that consists of a single line like exit is probably a bad idea. The library can be configured with custom patterns of code to be excluded. &lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
[http://saikuro.rubyforge.org/]=== Saikuro === &lt;br /&gt;
Saikuro is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one.Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Ruby-lint === &lt;br /&gt;
Ruby-lint is a linter and static code analysis tool for Ruby. [http://www.omniref.com/ruby/gems/ruby-lint].ruby-lint primarily focuses on logic related errors such as the use of non existing variables instead of focusing on semantics&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide.&lt;br /&gt;
&lt;br /&gt;
Problems one might want to attack and how to solve them&lt;br /&gt;
Recommendations about tools&lt;br /&gt;
Hyperlink to terms and references&lt;br /&gt;
References&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82954</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82954"/>
		<updated>2014-02-08T00:25:45Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Saikuro */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated by the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
&lt;br /&gt;
Now, there are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool completely subsumes all the other and hence there is no clear winner. In such a situation, it becomes necessary to evaluate the effectiveness of these tools.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that isn't really a bug.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug and leads to a fix.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
This leads to the definition of other related metrics such as :&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. This means that we could have written a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [Flay]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
FEATURES/PROBLEMS:&lt;br /&gt;
Reports differences at any level of code.&lt;br /&gt;
Adds a score multiplier to identical nodes.&lt;br /&gt;
Differences in literal values, variable, class, and method names are ignored.&lt;br /&gt;
Differences in whitespace, programming style, braces vs do/end, etc are ignored.&lt;br /&gt;
Works across files.&lt;br /&gt;
Add the flay-persistent plugin to work across large/many projects.&lt;br /&gt;
Run –diff to see an N-way diff of the code.&lt;br /&gt;
Provides conservative (default) and –liberal pruning options.&lt;br /&gt;
Provides –fuzzy duplication detection.&lt;br /&gt;
Language independent: Plugin system allows other languages to be flayed.&lt;br /&gt;
Ships with .rb and .erb.&lt;br /&gt;
javascript and others will be available separately.&lt;br /&gt;
Includes FlayTask for Rakefiles.&lt;br /&gt;
		&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
INSTALL:&lt;br /&gt;
sudo gem install flog&lt;br /&gt;
Flog Scoring&lt;br /&gt;
When flog is given Ruby code, flog parses it and builds up a structure of the code internally using RubyParser. A complete listing of all the scores assigned can be found in the source code. When it goes through every class and method until everything is scored. What you end up with is a breakdown of how each class and method scored.&lt;br /&gt;
&lt;br /&gt;
Using the scoring, you can get an idea of how complex or poorly written a piece of code is compared to other code. You can focus your refactoring efforts the parts of code which have the highest scores. A good rule of thumb for Flog scores is that you will want to eventually refactor or at least think about refactoring any method when it has a score of 40 or more.&lt;br /&gt;
Since flog scores are totals of all of the assignments, branches, and calls; using a refactoring method that splits a section of code in two is usually a good first refactoring to perform. To learn more about how to refactor code that recieved high flog score, refer to this page.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
Is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code — either source files or in-memory Class objects — looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
Attribute - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
Class Variables - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
Data Clump - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
Duplication - Warns when two fragments of code look nearly identical&lt;br /&gt;
Irresponsible Module - Warns if classes or modules are not properly annotated&lt;br /&gt;
&lt;br /&gt;
Long Method -Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
Large Class -Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
Feature Envy - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
Uncommunicative Name - Warns if a name does not represent its intent well enough&lt;br /&gt;
Long Parameter List - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
Utility Function - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
Nested Iterators - Warns if a block contains another block&lt;br /&gt;
Simulated Polymorphism - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
To install Reek:&lt;br /&gt;
gem install reek&lt;br /&gt;
To run it:&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus written by John Mettraux and uses the standard ruby parse tree. It allows to check Ruby for unwanted or unsafe code It uses this parse tree to convert this code into SexpProcessor classes that can then be evaluated. By using the Rufus treechecker the developer can dictate what patterns to generate errors for: The Rufus library allows to check some Ruby source code before loading it. Eg. loading a Ruby file that consists of a single line like exit is probably a bad idea. The library can be configured with custom patterns of code to be excluded. &lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
=== [Saikuro] === &lt;br /&gt;
Saikuro is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one.Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Ruby-lint === &lt;br /&gt;
Ruby-lint is a linter and static code analysis tool for Ruby. [http://www.omniref.com/ruby/gems/ruby-lint].ruby-lint primarily focuses on logic related errors such as the use of non existing variables instead of focusing on semantics&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide.&lt;br /&gt;
&lt;br /&gt;
Problems one might want to attack and how to solve them&lt;br /&gt;
Recommendations about tools&lt;br /&gt;
Hyperlink to terms and references&lt;br /&gt;
References&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82953</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82953"/>
		<updated>2014-02-08T00:23:32Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Saikuro */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated by the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
&lt;br /&gt;
Now, there are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool completely subsumes all the other and hence there is no clear winner. In such a situation, it becomes necessary to evaluate the effectiveness of these tools.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that isn't really a bug.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug and leads to a fix.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
This leads to the definition of other related metrics such as :&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. This means that we could have written a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [Flay]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
FEATURES/PROBLEMS:&lt;br /&gt;
Reports differences at any level of code.&lt;br /&gt;
Adds a score multiplier to identical nodes.&lt;br /&gt;
Differences in literal values, variable, class, and method names are ignored.&lt;br /&gt;
Differences in whitespace, programming style, braces vs do/end, etc are ignored.&lt;br /&gt;
Works across files.&lt;br /&gt;
Add the flay-persistent plugin to work across large/many projects.&lt;br /&gt;
Run –diff to see an N-way diff of the code.&lt;br /&gt;
Provides conservative (default) and –liberal pruning options.&lt;br /&gt;
Provides –fuzzy duplication detection.&lt;br /&gt;
Language independent: Plugin system allows other languages to be flayed.&lt;br /&gt;
Ships with .rb and .erb.&lt;br /&gt;
javascript and others will be available separately.&lt;br /&gt;
Includes FlayTask for Rakefiles.&lt;br /&gt;
		&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
INSTALL:&lt;br /&gt;
sudo gem install flog&lt;br /&gt;
Flog Scoring&lt;br /&gt;
When flog is given Ruby code, flog parses it and builds up a structure of the code internally using RubyParser. A complete listing of all the scores assigned can be found in the source code. When it goes through every class and method until everything is scored. What you end up with is a breakdown of how each class and method scored.&lt;br /&gt;
&lt;br /&gt;
Using the scoring, you can get an idea of how complex or poorly written a piece of code is compared to other code. You can focus your refactoring efforts the parts of code which have the highest scores. A good rule of thumb for Flog scores is that you will want to eventually refactor or at least think about refactoring any method when it has a score of 40 or more.&lt;br /&gt;
Since flog scores are totals of all of the assignments, branches, and calls; using a refactoring method that splits a section of code in two is usually a good first refactoring to perform. To learn more about how to refactor code that recieved high flog score, refer to this page.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
Is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code — either source files or in-memory Class objects — looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
Attribute - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
Class Variables - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
Data Clump - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
Duplication - Warns when two fragments of code look nearly identical&lt;br /&gt;
Irresponsible Module - Warns if classes or modules are not properly annotated&lt;br /&gt;
&lt;br /&gt;
Long Method -Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
Large Class -Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
Feature Envy - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
Uncommunicative Name - Warns if a name does not represent its intent well enough&lt;br /&gt;
Long Parameter List - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
Utility Function - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
Nested Iterators - Warns if a block contains another block&lt;br /&gt;
Simulated Polymorphism - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
To install Reek:&lt;br /&gt;
gem install reek&lt;br /&gt;
To run it:&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus written by John Mettraux and uses the standard ruby parse tree. It allows to check Ruby for unwanted or unsafe code It uses this parse tree to convert this code into SexpProcessor classes that can then be evaluated. By using the Rufus treechecker the developer can dictate what patterns to generate errors for: The Rufus library allows to check some Ruby source code before loading it. Eg. loading a Ruby file that consists of a single line like exit is probably a bad idea. The library can be configured with custom patterns of code to be excluded. &lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one.Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
'''To install Saikuro:'''&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Ruby-lint === &lt;br /&gt;
Ruby-lint is a linter and static code analysis tool for Ruby. [http://www.omniref.com/ruby/gems/ruby-lint].ruby-lint primarily focuses on logic related errors such as the use of non existing variables instead of focusing on semantics&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide.&lt;br /&gt;
&lt;br /&gt;
Problems one might want to attack and how to solve them&lt;br /&gt;
Recommendations about tools&lt;br /&gt;
Hyperlink to terms and references&lt;br /&gt;
References&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82952</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82952"/>
		<updated>2014-02-08T00:23:08Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Saikuro */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated by the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
&lt;br /&gt;
Now, there are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool completely subsumes all the other and hence there is no clear winner. In such a situation, it becomes necessary to evaluate the effectiveness of these tools.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that isn't really a bug.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug and leads to a fix.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
This leads to the definition of other related metrics such as :&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. This means that we could have written a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [Flay]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
FEATURES/PROBLEMS:&lt;br /&gt;
Reports differences at any level of code.&lt;br /&gt;
Adds a score multiplier to identical nodes.&lt;br /&gt;
Differences in literal values, variable, class, and method names are ignored.&lt;br /&gt;
Differences in whitespace, programming style, braces vs do/end, etc are ignored.&lt;br /&gt;
Works across files.&lt;br /&gt;
Add the flay-persistent plugin to work across large/many projects.&lt;br /&gt;
Run –diff to see an N-way diff of the code.&lt;br /&gt;
Provides conservative (default) and –liberal pruning options.&lt;br /&gt;
Provides –fuzzy duplication detection.&lt;br /&gt;
Language independent: Plugin system allows other languages to be flayed.&lt;br /&gt;
Ships with .rb and .erb.&lt;br /&gt;
javascript and others will be available separately.&lt;br /&gt;
Includes FlayTask for Rakefiles.&lt;br /&gt;
		&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
INSTALL:&lt;br /&gt;
sudo gem install flog&lt;br /&gt;
Flog Scoring&lt;br /&gt;
When flog is given Ruby code, flog parses it and builds up a structure of the code internally using RubyParser. A complete listing of all the scores assigned can be found in the source code. When it goes through every class and method until everything is scored. What you end up with is a breakdown of how each class and method scored.&lt;br /&gt;
&lt;br /&gt;
Using the scoring, you can get an idea of how complex or poorly written a piece of code is compared to other code. You can focus your refactoring efforts the parts of code which have the highest scores. A good rule of thumb for Flog scores is that you will want to eventually refactor or at least think about refactoring any method when it has a score of 40 or more.&lt;br /&gt;
Since flog scores are totals of all of the assignments, branches, and calls; using a refactoring method that splits a section of code in two is usually a good first refactoring to perform. To learn more about how to refactor code that recieved high flog score, refer to this page.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
Is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code — either source files or in-memory Class objects — looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
Attribute - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
Class Variables - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
Data Clump - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
Duplication - Warns when two fragments of code look nearly identical&lt;br /&gt;
Irresponsible Module - Warns if classes or modules are not properly annotated&lt;br /&gt;
&lt;br /&gt;
Long Method -Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
Large Class -Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
Feature Envy - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
Uncommunicative Name - Warns if a name does not represent its intent well enough&lt;br /&gt;
Long Parameter List - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
Utility Function - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
Nested Iterators - Warns if a block contains another block&lt;br /&gt;
Simulated Polymorphism - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
To install Reek:&lt;br /&gt;
gem install reek&lt;br /&gt;
To run it:&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus written by John Mettraux and uses the standard ruby parse tree. It allows to check Ruby for unwanted or unsafe code It uses this parse tree to convert this code into SexpProcessor classes that can then be evaluated. By using the Rufus treechecker the developer can dictate what patterns to generate errors for: The Rufus library allows to check some Ruby source code before loading it. Eg. loading a Ruby file that consists of a single line like exit is probably a bad idea. The library can be configured with custom patterns of code to be excluded. &lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one.Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
To install Saikuro:&lt;br /&gt;
&lt;br /&gt;
gem install saikuro&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Ruby-lint === &lt;br /&gt;
Ruby-lint is a linter and static code analysis tool for Ruby. [http://www.omniref.com/ruby/gems/ruby-lint].ruby-lint primarily focuses on logic related errors such as the use of non existing variables instead of focusing on semantics&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide.&lt;br /&gt;
&lt;br /&gt;
Problems one might want to attack and how to solve them&lt;br /&gt;
Recommendations about tools&lt;br /&gt;
Hyperlink to terms and references&lt;br /&gt;
References&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82951</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82951"/>
		<updated>2014-02-08T00:22:48Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Saikuro */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated by the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
&lt;br /&gt;
Now, there are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool completely subsumes all the other and hence there is no clear winner. In such a situation, it becomes necessary to evaluate the effectiveness of these tools.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that isn't really a bug.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug and leads to a fix.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
This leads to the definition of other related metrics such as :&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. This means that we could have written a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [Flay]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
FEATURES/PROBLEMS:&lt;br /&gt;
Reports differences at any level of code.&lt;br /&gt;
Adds a score multiplier to identical nodes.&lt;br /&gt;
Differences in literal values, variable, class, and method names are ignored.&lt;br /&gt;
Differences in whitespace, programming style, braces vs do/end, etc are ignored.&lt;br /&gt;
Works across files.&lt;br /&gt;
Add the flay-persistent plugin to work across large/many projects.&lt;br /&gt;
Run –diff to see an N-way diff of the code.&lt;br /&gt;
Provides conservative (default) and –liberal pruning options.&lt;br /&gt;
Provides –fuzzy duplication detection.&lt;br /&gt;
Language independent: Plugin system allows other languages to be flayed.&lt;br /&gt;
Ships with .rb and .erb.&lt;br /&gt;
javascript and others will be available separately.&lt;br /&gt;
Includes FlayTask for Rakefiles.&lt;br /&gt;
		&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
INSTALL:&lt;br /&gt;
sudo gem install flog&lt;br /&gt;
Flog Scoring&lt;br /&gt;
When flog is given Ruby code, flog parses it and builds up a structure of the code internally using RubyParser. A complete listing of all the scores assigned can be found in the source code. When it goes through every class and method until everything is scored. What you end up with is a breakdown of how each class and method scored.&lt;br /&gt;
&lt;br /&gt;
Using the scoring, you can get an idea of how complex or poorly written a piece of code is compared to other code. You can focus your refactoring efforts the parts of code which have the highest scores. A good rule of thumb for Flog scores is that you will want to eventually refactor or at least think about refactoring any method when it has a score of 40 or more.&lt;br /&gt;
Since flog scores are totals of all of the assignments, branches, and calls; using a refactoring method that splits a section of code in two is usually a good first refactoring to perform. To learn more about how to refactor code that recieved high flog score, refer to this page.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
Is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code — either source files or in-memory Class objects — looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
Attribute - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
Class Variables - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
Data Clump - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
Duplication - Warns when two fragments of code look nearly identical&lt;br /&gt;
Irresponsible Module - Warns if classes or modules are not properly annotated&lt;br /&gt;
&lt;br /&gt;
Long Method -Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
Large Class -Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
Feature Envy - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
Uncommunicative Name - Warns if a name does not represent its intent well enough&lt;br /&gt;
Long Parameter List - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
Utility Function - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
Nested Iterators - Warns if a block contains another block&lt;br /&gt;
Simulated Polymorphism - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
To install Reek:&lt;br /&gt;
gem install reek&lt;br /&gt;
To run it:&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus written by John Mettraux and uses the standard ruby parse tree. It allows to check Ruby for unwanted or unsafe code It uses this parse tree to convert this code into SexpProcessor classes that can then be evaluated. By using the Rufus treechecker the developer can dictate what patterns to generate errors for: The Rufus library allows to check some Ruby source code before loading it. Eg. loading a Ruby file that consists of a single line like exit is probably a bad idea. The library can be configured with custom patterns of code to be excluded. &lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro is a cyclomatic complexity analyzer. It analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one.Control flow graphs are used to measure the cyclomatic complexity of a method. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
To install Saikuro:&lt;br /&gt;
gem install saikuro&lt;br /&gt;
Example:&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Ruby-lint === &lt;br /&gt;
Ruby-lint is a linter and static code analysis tool for Ruby. [http://www.omniref.com/ruby/gems/ruby-lint].ruby-lint primarily focuses on logic related errors such as the use of non existing variables instead of focusing on semantics&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide.&lt;br /&gt;
&lt;br /&gt;
Problems one might want to attack and how to solve them&lt;br /&gt;
Recommendations about tools&lt;br /&gt;
Hyperlink to terms and references&lt;br /&gt;
References&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82950</id>
		<title>CSC/ECE 517 Spring 2014/ch1 1w1b np</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1_1w1b_np&amp;diff=82950"/>
		<updated>2014-02-08T00:19:43Z</updated>

		<summary type="html">&lt;p&gt;Pysatosk: /* Saikuro */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Background ==&lt;br /&gt;
=== What is static analysis? ===&lt;br /&gt;
An important aspect of software code is to be bug free. Most code that passes tests still contains bugs in them. Once a software passes the required tests, it is necessary to check for bugs in the code and check for quality of the code. This checking of code to improve quality is called code analysis. There are two main categories of code analysis, static code analysis and dynamic code analysis. Static code analysis is the checking of code, without actually executing it. Static code analysis is performed on either the source code or in some cases the compiled object code or some representation of the source code. Static code analysis can be done entirely by code review by a human or the static code analysis process can be automated by the help of tools.&lt;br /&gt;
&lt;br /&gt;
=== Why is static analysis important? ===&lt;br /&gt;
Software is prone to contain implicit or explicit bugs. Bugs can be faults in the code that could lead to failure of the software. Bugs could also be problems in code that make it less readable, less maintainable, inconsistent to conventions, etc. The problems with code may be more or less apparent and are not always discovered by testing. Without any form of static analysis, there is a risk that the code may reach production and cause problems in the future. Also, there is no guarantee that the code performs well, in all cases, is maintainable and of high quality without any form of static analysis. Hence, static analysis is an important part of software development.&lt;br /&gt;
&lt;br /&gt;
=== Why static analysis tools? ===&lt;br /&gt;
Static analysis tools automate the tasks of checking for problems in code. Generally code, especially industry software code tends to have a large number of lines of code. Manually reviewing all of this code is tedious and subject to human shortcoming of overlooking problems, fatigue and shortcomings in knowledge of the code. On the other hand, if this process can be automated using tools, we can expect that all or most of the problems are caught and brought to the notice of the developer. We can expect tools to be repeatable and work on large volumes of code.&lt;br /&gt;
Metrics for evaluating effectiveness of static analysis tools&lt;br /&gt;
&lt;br /&gt;
=== Why to evaluate static analysis tools? ===&lt;br /&gt;
&lt;br /&gt;
Now, there are quite a few static analysis tools available for each language. Each of these tools finds a subset of all the bugs and there is some overlap in the bugs found. No one tool completely subsumes all the other and hence there is no clear winner. In such a situation, it becomes necessary to evaluate the effectiveness of these tools.&lt;br /&gt;
A number of metrics have been discussed for evaluating the effectiveness of bug finding tools:&lt;br /&gt;
False Positives (FP): A false positive is a bug warning that isn't really a bug.&lt;br /&gt;
True Positives (TP): A true positive is a bug warning that correctly finds a bug and leads to a fix.&lt;br /&gt;
True Negative (TN): A true negative is any line of code where no bug warning was reported and that line was found to be bug free.&lt;br /&gt;
False Negative (FN): A false negative is a line of code for which no bug warning was reported but bugs were later found.&lt;br /&gt;
This leads to the definition of other related metrics such as :&lt;br /&gt;
False Positive Rate (FPR) = FP/ (FP+TP) OR FP/(FP+TN)&lt;br /&gt;
Precision = TP/ (FP+TP) OR Precision = 1 - FPR &lt;br /&gt;
&lt;br /&gt;
=== Problems with static analysis tools ===&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools in dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Narration&lt;br /&gt;
Static code analysis in Ruby&lt;br /&gt;
How static analysis tools work&lt;br /&gt;
How they identify problems quickly&lt;br /&gt;
Examples&lt;br /&gt;
&lt;br /&gt;
== Static analysis tools for Ruby ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Flay ===&lt;br /&gt;
Flay checks for parts of code that do the same thing, but on different variables/literals/constants. This means that we could have written a generic code that could have been used for both instances. Thus, flay is good for checking whether your code adheres to DRY principle.  Flay uses sexp_processor and ruby_parser to examine the structure of Ruby code. The sexp_processor works on the parse tree (an abstract syntax tree representation) and helps you to focus on specific parts you are interested in and ignores the rest. Thus, . Flay is able to ignore differences in literal values, names, whitespace, and programming style when comparing subtrees to identify duplicate sections of code [Flay]. It is capable of detecting both exact and close matches. Flay's output is very primitive: a list of repeated code nodes, together with a weight to rank them by and line numbers and file names where they show up. Just gem install flay, and then flay *.rb to get playing with Flay. [http://www.rubyinside.com/3-tools-for-drying-your-ruby-code-1305.html]&lt;br /&gt;
FEATURES/PROBLEMS:&lt;br /&gt;
Reports differences at any level of code.&lt;br /&gt;
Adds a score multiplier to identical nodes.&lt;br /&gt;
Differences in literal values, variable, class, and method names are ignored.&lt;br /&gt;
Differences in whitespace, programming style, braces vs do/end, etc are ignored.&lt;br /&gt;
Works across files.&lt;br /&gt;
Add the flay-persistent plugin to work across large/many projects.&lt;br /&gt;
Run –diff to see an N-way diff of the code.&lt;br /&gt;
Provides conservative (default) and –liberal pruning options.&lt;br /&gt;
Provides –fuzzy duplication detection.&lt;br /&gt;
Language independent: Plugin system allows other languages to be flayed.&lt;br /&gt;
Ships with .rb and .erb.&lt;br /&gt;
javascript and others will be available separately.&lt;br /&gt;
Includes FlayTask for Rakefiles.&lt;br /&gt;
		&lt;br /&gt;
=== Flog ===&lt;br /&gt;
Flog is a tool by Ryan Davis and Eric Hodel that scores your Ruby code based on common patterns. It works based on counting your code's ABC (Assignment, Branches and Calls) metric.&lt;br /&gt;
All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused.&lt;br /&gt;
Each of the ABCs have different metrics associated with them.&lt;br /&gt;
INSTALL:&lt;br /&gt;
sudo gem install flog&lt;br /&gt;
Flog Scoring&lt;br /&gt;
When flog is given Ruby code, flog parses it and builds up a structure of the code internally using RubyParser. A complete listing of all the scores assigned can be found in the source code. When it goes through every class and method until everything is scored. What you end up with is a breakdown of how each class and method scored.&lt;br /&gt;
&lt;br /&gt;
Using the scoring, you can get an idea of how complex or poorly written a piece of code is compared to other code. You can focus your refactoring efforts the parts of code which have the highest scores. A good rule of thumb for Flog scores is that you will want to eventually refactor or at least think about refactoring any method when it has a score of 40 or more.&lt;br /&gt;
Since flog scores are totals of all of the assignments, branches, and calls; using a refactoring method that splits a section of code in two is usually a good first refactoring to perform. To learn more about how to refactor code that recieved high flog score, refer to this page.&lt;br /&gt;
&lt;br /&gt;
=== Metric_fu ===&lt;br /&gt;
metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek,Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.&lt;br /&gt;
Running metric:all will include:&lt;br /&gt;
churn: It will shows which files change the most.&lt;br /&gt;
coverage: It will show which parts of your code are tested&lt;br /&gt;
flay: It will shows which parts of your code are duplicated&lt;br /&gt;
flog: It will show if your code is unnecessarily complex&lt;br /&gt;
reek: It will show if  your code suffer from well-known bad practices&lt;br /&gt;
saikuro: It will also show how complex is your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Reek === &lt;br /&gt;
Is a code smell detector for Ruby developed by Kevin Rutherford. Reek scans ruby code — either source files or in-memory Class objects — looking for some of the code smells.[http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm]&lt;br /&gt;
The different code smells which Reek can detect are:&lt;br /&gt;
Attribute - Warns if a class publishes a getter or setter for an instance variable caused the client to become too intimate with the inner workings of the class&lt;br /&gt;
Class Variables - Warns that class variables are a part of the runtime state. Different parts of the system can inadvertently depend on other parts of the system causing unintended consequences&lt;br /&gt;
Control Coupling - Warns when a parameter is used to determine the execution path. This is duplication since the caller know what path should be taken&lt;br /&gt;
Data Clump - Warns when several items appear frequently together in classes or parameter lists&lt;br /&gt;
Duplication - Warns when two fragments of code look nearly identical&lt;br /&gt;
Irresponsible Module - Warns if classes or modules are not properly annotated&lt;br /&gt;
&lt;br /&gt;
Long Method -Warns if a method has more that 5 statements. Every statement within a control structure (if, case, for, etc) is considered 1&lt;br /&gt;
Large Class -Warns if a class has more than a configurable number of methods or instance variables. These max values default to 25 for methods, and 9 for instance variables&lt;br /&gt;
Feature Envy - Warns if any method refers to self less often that it refers to another object&lt;br /&gt;
Uncommunicative Name - Warns if a name does not represent its intent well enough&lt;br /&gt;
Long Parameter List - Warns if a method has more than two parameters or if a method yields more than two objects to a block&lt;br /&gt;
Utility Function - Warns if a function has no dependency on the state of the instance&lt;br /&gt;
Nested Iterators - Warns if a block contains another block&lt;br /&gt;
Simulated Polymorphism - Warns if multiple conditionals test the same value throughout a class&lt;br /&gt;
To install Reek:&lt;br /&gt;
gem install reek&lt;br /&gt;
To run it:&lt;br /&gt;
reek file1.rb file2.rb ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Roodi ===&lt;br /&gt;
 It is similar to reek in that it allows to run a list of checks over a codebase. Roodi comes with checks that ensure methods or modules comply with a naming convention, max parameter count, etc. Other checks include advice such as avoiding for loops, etc. The shipped checks can also be easily configured with a YAML file. New checks can be easily written as well. A checker class registers the types of AST nodes it's interested in and can then handle the matched subtrees.&lt;br /&gt;
The checks that Roodi performs are:&lt;br /&gt;
AssignmentInConditionalCheck - Warns if there is an assignment inside a conditional&lt;br /&gt;
CaseMissingElseCheck - Warns if a case statement does not have an else statement, thus not covering all possibilities&lt;br /&gt;
ClassLineCountCheck - Warns if the count of lines in a class is below threshold&lt;br /&gt;
ClassNameCheck - Warns if class names do not match convention&lt;br /&gt;
CyclomaticComplexityBlockCheck - Warns if the cyclomatic complexity of all blocks is below threshold&lt;br /&gt;
CyclomaticComplexityMethodCheck - Warns if the cyclomatic complexity of all methods is below the threshold.&lt;br /&gt;
EmptyRescueBodyCheck - Warns if there are empty rescue blocks.&lt;br /&gt;
ForLoopCheck - Warns if for loops are used instead of Enumerable.each&lt;br /&gt;
MethodLineCountCheck - Warns if the number of lines in a method is above threshold&lt;br /&gt;
MethodNameCheck - Warns if method names do not match convention.&lt;br /&gt;
ModuleLineCountCheck - Warns if the number of lines in a module is above threshold&lt;br /&gt;
ModuleNameCheck - Warns if module names do not match convention&lt;br /&gt;
ParameterNumberCheck - Warns if the number of parameters for a method is above threshold&lt;br /&gt;
  &lt;br /&gt;
=== Rufus ===&lt;br /&gt;
Rufus written by John Mettraux and uses the standard ruby parse tree. It allows to check Ruby for unwanted or unsafe code It uses this parse tree to convert this code into SexpProcessor classes that can then be evaluated. By using the Rufus treechecker the developer can dictate what patterns to generate errors for: The Rufus library allows to check some Ruby source code before loading it. Eg. loading a Ruby file that consists of a single line like exit is probably a bad idea. The library can be configured with custom patterns of code to be excluded. &lt;br /&gt;
Rufus is actually made of several Gems that make up the ruote open source workflow. These Gems include:&lt;br /&gt;
rufus-decision – CSV decision tables, in Ruby&lt;br /&gt;
rufus-dollar – substituting ${stuff} in text strings&lt;br /&gt;
rufus-lru – small LRU implementation (max size based)&lt;br /&gt;
rufus-lua – Lua embedded in Ruby, via ruby FFI&lt;br /&gt;
rufus-mnemo – turning integers into easier to remember ‘words’ and vice-et-versa&lt;br /&gt;
rufus-rtm – A Remember The Milk gem&lt;br /&gt;
rufus-scheduler – the gem formerly known as openwferu-scheduler, cron, at and every job scheduler&lt;br /&gt;
rufus-sixjo – a Rack application, RESTfully serving&lt;br /&gt;
rufus-sqs – a gem for interacting with Amazon SQS&lt;br /&gt;
rufus-tokyo – a ruby-ffi based lib for handling Tokyo Cabinet hashes (or trees)&lt;br /&gt;
rufus-treechecker – for checking untrusted code before an eval&lt;br /&gt;
rufus-verbs – the verbs of HTTP, get, post, put, delete wrapped in a Ruby gem&lt;br /&gt;
&lt;br /&gt;
=== Saikuro === &lt;br /&gt;
Saikuro analyzes code and reports cyclomatic complexity of each method in the analyzed code. Cyclomatic complexity is a graphical measurement of the number of possible paths through the normal flow of a program.&lt;br /&gt;
For example, a program with no branching statements has a score of one. Calculation of the cyclomatic complexity of a method is done through the use of a control flow graph. These graphs consist of nodes and edges. Each node in a program represents a basic statement and each edge represents the changes in control flow of the program. &lt;br /&gt;
It is better to keep the cyclomatic complexity low so that the code is simple and easy to follow and debug.&lt;br /&gt;
In Saikaro each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :&lt;br /&gt;
*conditional and looping operator&lt;br /&gt;
*each when in a case&lt;br /&gt;
*rescue statements&lt;br /&gt;
*blocks like each&lt;br /&gt;
It will counts the number of independent paths through the code.[3] The higher the number that is returned the more complex the code. This means complex code &amp;quot;is more prone to error, harder to understand, harder to test, and harder to modify.&amp;quot;[3] In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.&lt;br /&gt;
&lt;br /&gt;
To install Saikuro:&lt;br /&gt;
gem install saikuro&lt;br /&gt;
Example:&lt;br /&gt;
~$ saikuro -c -o saikuro_output  -p test.rb&lt;br /&gt;
&lt;br /&gt;
=== Ruby-lint === &lt;br /&gt;
Ruby-lint is a linter and static code analysis tool for Ruby. [http://www.omniref.com/ruby/gems/ruby-lint].ruby-lint primarily focuses on logic related errors such as the use of non existing variables instead of focusing on semantics&lt;br /&gt;
&lt;br /&gt;
=== Rubocop ===&lt;br /&gt;
RuboCop is a Ruby static code analyzer. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide.&lt;br /&gt;
&lt;br /&gt;
Problems one might want to attack and how to solve them&lt;br /&gt;
Recommendations about tools&lt;br /&gt;
Hyperlink to terms and references&lt;br /&gt;
References&lt;/div&gt;</summary>
		<author><name>Pysatosk</name></author>
	</entry>
</feed>