<?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=Pyadla</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=Pyadla"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Pyadla"/>
	<updated>2026-06-09T09:56:27Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81290</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81290"/>
		<updated>2013-10-30T20:27:46Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* Appendix: setup issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.JPG|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.JPG|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
:Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_loc = @participant.get_path &lt;br /&gt;
    new_loc+= &amp;quot;/&amp;quot; &lt;br /&gt;
    new_loc+= params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_loc)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_location = @participant.get_path + &amp;quot;/&amp;quot; + params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_location)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Many more minor code changes are made following the Ruby Coding guidelines. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We should prefer to use 'unless' for such conditions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== List of Code Smells identified and removed ==&lt;br /&gt;
*'''Duplicated code''': Identical or very similar code exists in more than one location. Code duplication frequently creates long, repeated sections of code that differ in only a few lines or characters. The length of such routines can make it difficult to quickly understand them. The repetition of largely identical code sections can conceal how they differ from one another, and therefore, what the specific purpose of each code section is. Often, the only difference is in a parameter value. The best practice in such cases is a reusable subroutine.&lt;br /&gt;
*'''Long method''': A method, function, or procedure that has grown too large. Since the early days of programming people have realized that the longer a procedure is, the more difficult it is to understand. Older languages carried an overhead in subroutine calls, which deterred people from small methods. Modern OO languages have pretty much eliminated that overhead for in-process calls.&lt;br /&gt;
*'''Too many parameters''': A long list of parameters in a procedure or function make readability and code quality worse. The more parameters a method has, the more complex it is. Limit the number of parameters you need in a given method, or use an object to combine the parameters.&lt;br /&gt;
*'''Excessively long identifiers''': In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
*'''Excessively short identifiers''': The name of a variable should reflect its function unless the function is obvious. Pick a set of standard terminology and stick to it throughout your methods. For example, if you have Open(), you should probably have Close().&lt;br /&gt;
*'''Excessive use of literals''': These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
*'''Complex conditionals''': Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code. Large conditional logic blocks, particularly blocks that tend to grow larger or change significantly over time have to be eliminated. Consider alternative object-oriented approaches such as decorator, strategy, or state.&lt;br /&gt;
*'''Dead Code''': Ruthlessly delete code that isn't being used. Unused code will result in Long classes or long methods.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
*Polymorphism can be implemented by pushing some methods to relevant classes. Following section of code contains certain method calls which are implemented in the same class. These can be abstracted into a different class for file operations:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def file_folder_action&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
    if params[:faction][:delete]        #call method to delete selected files&lt;br /&gt;
      delete_selected_files&lt;br /&gt;
    elsif params[:faction][:rename]     #call method to rename selected files&lt;br /&gt;
      rename_selected_file&lt;br /&gt;
    elsif params[:faction][:move]       #call method to move selected files&lt;br /&gt;
      move_selected_file&lt;br /&gt;
    elsif params[:faction][:copy]       #call method to copy selected files&lt;br /&gt;
      copy_selected_file&lt;br /&gt;
    elsif params[:faction][:create]     #call method to create new folder&lt;br /&gt;
      create_new_folder&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Submit file functionality currently breaks with the latest expertiza master branch code which can be fixed by further exploration.&lt;br /&gt;
*Design changes made in partial files can be extended such that code reuse can be maximized.&lt;br /&gt;
*Many more code smells can be identified and removed to improve elegance.&lt;br /&gt;
*RSpec test cases for the changes made can be added.&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
*Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
:(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
:(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
*Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
*Run bundle install &lt;br /&gt;
*Run - rake db:create:all&lt;br /&gt;
*Run - rake db:migrate&lt;br /&gt;
*From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
You should be able to view the test Database in MySQL.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: admin&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: sample&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81275</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81275"/>
		<updated>2013-10-30T20:16:10Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.JPG|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.JPG|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
:Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_loc = @participant.get_path &lt;br /&gt;
    new_loc+= &amp;quot;/&amp;quot; &lt;br /&gt;
    new_loc+= params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_loc)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_location = @participant.get_path + &amp;quot;/&amp;quot; + params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_location)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Many more minor code changes are made following the Ruby Coding guidelines. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We should prefer to use 'unless' for such conditions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== List of Code Smells identified and removed ==&lt;br /&gt;
*'''Duplicated code''': Identical or very similar code exists in more than one location. Code duplication frequently creates long, repeated sections of code that differ in only a few lines or characters. The length of such routines can make it difficult to quickly understand them. The repetition of largely identical code sections can conceal how they differ from one another, and therefore, what the specific purpose of each code section is. Often, the only difference is in a parameter value. The best practice in such cases is a reusable subroutine.&lt;br /&gt;
*'''Long method''': A method, function, or procedure that has grown too large. Since the early days of programming people have realized that the longer a procedure is, the more difficult it is to understand. Older languages carried an overhead in subroutine calls, which deterred people from small methods. Modern OO languages have pretty much eliminated that overhead for in-process calls.&lt;br /&gt;
*'''Too many parameters''': A long list of parameters in a procedure or function make readability and code quality worse. The more parameters a method has, the more complex it is. Limit the number of parameters you need in a given method, or use an object to combine the parameters.&lt;br /&gt;
*'''Excessively long identifiers''': In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
*'''Excessively short identifiers''': The name of a variable should reflect its function unless the function is obvious. Pick a set of standard terminology and stick to it throughout your methods. For example, if you have Open(), you should probably have Close().&lt;br /&gt;
*'''Excessive use of literals''': These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
*'''Complex conditionals''': Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code. Large conditional logic blocks, particularly blocks that tend to grow larger or change significantly over time have to be eliminated. Consider alternative object-oriented approaches such as decorator, strategy, or state.&lt;br /&gt;
*'''Dead Code''': Ruthlessly delete code that isn't being used. Unused code will result in Long classes or long methods.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
*Polymorphism can be implemented by pushing some methods to relevant classes. Following section of code contains certain method calls which are implemented in the same class. These can be abstracted into a different class for file operations:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def file_folder_action&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
    if params[:faction][:delete]        #call method to delete selected files&lt;br /&gt;
      delete_selected_files&lt;br /&gt;
    elsif params[:faction][:rename]     #call method to rename selected files&lt;br /&gt;
      rename_selected_file&lt;br /&gt;
    elsif params[:faction][:move]       #call method to move selected files&lt;br /&gt;
      move_selected_file&lt;br /&gt;
    elsif params[:faction][:copy]       #call method to copy selected files&lt;br /&gt;
      copy_selected_file&lt;br /&gt;
    elsif params[:faction][:create]     #call method to create new folder&lt;br /&gt;
      create_new_folder&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Submit file functionality currently breaks with the latest expertiza master branch code which can be fixed by further exploration.&lt;br /&gt;
*Design changes made in partial files can be extended such that code reuse can be maximized.&lt;br /&gt;
*Many more code smells can be identified and removed to improve elegance.&lt;br /&gt;
*RSpec test cases for the changes made can be added.&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
*Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
:(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
:(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
*Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
*Run bundle install &lt;br /&gt;
*Run - rake db:create:all&lt;br /&gt;
*Run - rake db:migrate&lt;br /&gt;
*From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
You should be able to view the test Database in MySQL.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: admin&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: sample&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81273</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81273"/>
		<updated>2013-10-30T20:15:55Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.JPG|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.JPG|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
:Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_loc = @participant.get_path &lt;br /&gt;
    new_loc+= &amp;quot;/&amp;quot; &lt;br /&gt;
    new_loc+= params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_loc)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_location = @participant.get_path + &amp;quot;/&amp;quot; + params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_location)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Many more minor code changes are made following the Ruby Coding guidelines. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We should prefer to use 'unless' for such conditions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== List of Code Smells identified and removed ==&lt;br /&gt;
*'''Duplicated code''': Identical or very similar code exists in more than one location. Code duplication frequently creates long, repeated sections of code that differ in only a few lines or characters. The length of such routines can make it difficult to quickly understand them. The repetition of largely identical code sections can conceal how they differ from one another, and therefore, what the specific purpose of each code section is. Often, the only difference is in a parameter value. The best practice in such cases is a reusable subroutine.&lt;br /&gt;
*'''Long method''': A method, function, or procedure that has grown too large. Since the early days of programming people have realized that the longer a procedure is, the more difficult it is to understand. Older languages carried an overhead in subroutine calls, which deterred people from small methods. Modern OO languages have pretty much eliminated that overhead for in-process calls.&lt;br /&gt;
*'''Too many parameters''': A long list of parameters in a procedure or function make readability and code quality worse. The more parameters a method has, the more complex it is. Limit the number of parameters you need in a given method, or use an object to combine the parameters.&lt;br /&gt;
*'''Excessively long identifiers''': In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
*'''Excessively short identifiers''': The name of a variable should reflect its function unless the function is obvious. Pick a set of standard terminology and stick to it throughout your methods. For example, if you have Open(), you should probably have Close().&lt;br /&gt;
*'''Excessive use of literals''': These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
*'''Complex conditionals''': Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code. Large conditional logic blocks, particularly blocks that tend to grow larger or change significantly over time have to be eliminated. Consider alternative object-oriented approaches such as decorator, strategy, or state.&lt;br /&gt;
*'''Dead Code''': Ruthlessly delete code that isn't being used. Unused code will result in Long classes or long methods.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
*Polymorphism can be implemented by pushing some methods to relevant classes. Following section of code contains certain method calls which are implemented in the same class. These can be abstracted into a different class for file operations:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def file_folder_action&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
    if params[:faction][:delete]        #call method to delete selected files&lt;br /&gt;
      delete_selected_files&lt;br /&gt;
    elsif params[:faction][:rename]     #call method to rename selected files&lt;br /&gt;
      rename_selected_file&lt;br /&gt;
    elsif params[:faction][:move]       #call method to move selected files&lt;br /&gt;
      move_selected_file&lt;br /&gt;
    elsif params[:faction][:copy]       #call method to copy selected files&lt;br /&gt;
      copy_selected_file&lt;br /&gt;
    elsif params[:faction][:create]     #call method to create new folder&lt;br /&gt;
      create_new_folder&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Submit file functionality currently breaks with the latest expertiza master branch code which can be fixed by further exploration.&lt;br /&gt;
*Design changes made in partial files can be extended such that code reuse can be maximized.&lt;br /&gt;
*Many more code smells can be identified and removed to improve elegance.&lt;br /&gt;
*RSpec test cases for the changes made can be added.&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
*Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
:(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
:(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
*Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
*Run bundle install &lt;br /&gt;
*Run - rake db:create:all&lt;br /&gt;
*Run - rake db:migrate&lt;br /&gt;
*From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
You should be able to view the test Database in MySQL.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: admin&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: sample&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81265</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81265"/>
		<updated>2013-10-30T20:13:52Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* Future Work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.JPG|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.JPG|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
:Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_loc = @participant.get_path &lt;br /&gt;
    new_loc+= &amp;quot;/&amp;quot; &lt;br /&gt;
    new_loc+= params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_loc)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_location = @participant.get_path + &amp;quot;/&amp;quot; + params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_location)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Many more minor code changes are made following the Ruby Coding guidelines. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We should prefer to use 'unless' for such conditions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== List of Code Smells identified and removed ==&lt;br /&gt;
*'''Duplicated code''': Identical or very similar code exists in more than one location. Code duplication frequently creates long, repeated sections of code that differ in only a few lines or characters. The length of such routines can make it difficult to quickly understand them. The repetition of largely identical code sections can conceal how they differ from one another, and therefore, what the specific purpose of each code section is. Often, the only difference is in a parameter value. The best practice in such cases is a reusable subroutine.&lt;br /&gt;
*'''Long method''': A method, function, or procedure that has grown too large. Since the early days of programming people have realized that the longer a procedure is, the more difficult it is to understand. Older languages carried an overhead in subroutine calls, which deterred people from small methods. Modern OO languages have pretty much eliminated that overhead for in-process calls.&lt;br /&gt;
*'''Too many parameters''': A long list of parameters in a procedure or function make readability and code quality worse. The more parameters a method has, the more complex it is. Limit the number of parameters you need in a given method, or use an object to combine the parameters.&lt;br /&gt;
*'''Excessively long identifiers''': In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
*'''Excessively short identifiers''': The name of a variable should reflect its function unless the function is obvious. Pick a set of standard terminology and stick to it throughout your methods. For example, if you have Open(), you should probably have Close().&lt;br /&gt;
*'''Excessive use of literals''': These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
*'''Complex conditionals''': Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code. Large conditional logic blocks, particularly blocks that tend to grow larger or change significantly over time have to be eliminated. Consider alternative object-oriented approaches such as decorator, strategy, or state.&lt;br /&gt;
*'''Dead Code''': Ruthlessly delete code that isn't being used. Unused code will result in Long classes or long methods.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
*Polymorphism can be implemented by pushing some methods to relevant classes. Following section of code contains certain method calls which are implemented in the same class. These can be abstracted into a different class for file operations:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def file_folder_action&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
    if params[:faction][:delete]        #call method to delete selected files&lt;br /&gt;
      delete_selected_files&lt;br /&gt;
    elsif params[:faction][:rename]     #call method to rename selected files&lt;br /&gt;
      rename_selected_file&lt;br /&gt;
    elsif params[:faction][:move]       #call method to move selected files&lt;br /&gt;
      move_selected_file&lt;br /&gt;
    elsif params[:faction][:copy]       #call method to copy selected files&lt;br /&gt;
      copy_selected_file&lt;br /&gt;
    elsif params[:faction][:create]     #call method to create new folder&lt;br /&gt;
      create_new_folder&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Submit file functionality currently breaks with the latest expertiza master branch code which can be fixed by further exploration.&lt;br /&gt;
*Design changes made in partial files can be extended such that code reuse can be maximized.&lt;br /&gt;
*Many more code smells can be identified and removed to improve elegance.&lt;br /&gt;
*RSpec test cases for the changes made can be added.&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
*Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
:(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
:(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
*Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
*Run bundle install &lt;br /&gt;
*Run - rake db:create:all&lt;br /&gt;
*Run - rake db:migrate&lt;br /&gt;
*From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
You should be able to view the test Database in MySQL.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: admin&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: sample&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81262</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81262"/>
		<updated>2013-10-30T20:11:13Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* Appendix: setup issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.JPG|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.JPG|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
:Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_loc = @participant.get_path &lt;br /&gt;
    new_loc+= &amp;quot;/&amp;quot; &lt;br /&gt;
    new_loc+= params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_loc)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_location = @participant.get_path + &amp;quot;/&amp;quot; + params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_location)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Many more minor code changes are made following the Ruby Coding guidelines. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We should prefer to use 'unless' for such conditions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== List of Code Smells identified and removed ==&lt;br /&gt;
*'''Duplicated code''': Identical or very similar code exists in more than one location. Code duplication frequently creates long, repeated sections of code that differ in only a few lines or characters. The length of such routines can make it difficult to quickly understand them. The repetition of largely identical code sections can conceal how they differ from one another, and therefore, what the specific purpose of each code section is. Often, the only difference is in a parameter value. The best practice in such cases is a reusable subroutine.&lt;br /&gt;
*'''Long method''': A method, function, or procedure that has grown too large. Since the early days of programming people have realized that the longer a procedure is, the more difficult it is to understand. Older languages carried an overhead in subroutine calls, which deterred people from small methods. Modern OO languages have pretty much eliminated that overhead for in-process calls.&lt;br /&gt;
*'''Too many parameters''': A long list of parameters in a procedure or function make readability and code quality worse. The more parameters a method has, the more complex it is. Limit the number of parameters you need in a given method, or use an object to combine the parameters.&lt;br /&gt;
*'''Excessively long identifiers''': In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
*'''Excessively short identifiers''': The name of a variable should reflect its function unless the function is obvious. Pick a set of standard terminology and stick to it throughout your methods. For example, if you have Open(), you should probably have Close().&lt;br /&gt;
*'''Excessive use of literals''': These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
*'''Complex conditionals''': Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code. Large conditional logic blocks, particularly blocks that tend to grow larger or change significantly over time have to be eliminated. Consider alternative object-oriented approaches such as decorator, strategy, or state.&lt;br /&gt;
*'''Dead Code''': Ruthlessly delete code that isn't being used. Unused code will result in Long classes or long methods.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
Polymorphism can be implemented by pushing some methods to relevant classes. Following section of code contains certain method calls which are implemented in the same class. These can be abstracted into a different class for file operations:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def file_folder_action&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
    if params[:faction][:delete]        #call method to delete selected files&lt;br /&gt;
      delete_selected_files&lt;br /&gt;
    elsif params[:faction][:rename]     #call method to rename selected files&lt;br /&gt;
      rename_selected_file&lt;br /&gt;
    elsif params[:faction][:move]       #call method to move selected files&lt;br /&gt;
      move_selected_file&lt;br /&gt;
    elsif params[:faction][:copy]       #call method to copy selected files&lt;br /&gt;
      copy_selected_file&lt;br /&gt;
    elsif params[:faction][:create]     #call method to create new folder&lt;br /&gt;
      create_new_folder&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Code clean up done besides the requirements of the project.&lt;br /&gt;
Design choice for the changes made in partial files such that code reuse can be maximised.&lt;br /&gt;
Cucumber testing scenarios for the changes made: Work In Progress&lt;br /&gt;
Further code smells need to be processed for more elegance.&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
*Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
:(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
:(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
*Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
*Run bundle install &lt;br /&gt;
*Run - rake db:create:all&lt;br /&gt;
*Run - rake db:migrate&lt;br /&gt;
*From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
You should be able to view the test Database in MySQL.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: admin&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: sample&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81259</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81259"/>
		<updated>2013-10-30T20:10:29Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* Future Work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.JPG|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.JPG|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
:Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_loc = @participant.get_path &lt;br /&gt;
    new_loc+= &amp;quot;/&amp;quot; &lt;br /&gt;
    new_loc+= params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_loc)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_location = @participant.get_path + &amp;quot;/&amp;quot; + params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_location)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Many more minor code changes are made following the Ruby Coding guidelines. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We should prefer to use 'unless' for such conditions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== List of Code Smells identified and removed ==&lt;br /&gt;
*'''Duplicated code''': Identical or very similar code exists in more than one location. Code duplication frequently creates long, repeated sections of code that differ in only a few lines or characters. The length of such routines can make it difficult to quickly understand them. The repetition of largely identical code sections can conceal how they differ from one another, and therefore, what the specific purpose of each code section is. Often, the only difference is in a parameter value. The best practice in such cases is a reusable subroutine.&lt;br /&gt;
*'''Long method''': A method, function, or procedure that has grown too large. Since the early days of programming people have realized that the longer a procedure is, the more difficult it is to understand. Older languages carried an overhead in subroutine calls, which deterred people from small methods. Modern OO languages have pretty much eliminated that overhead for in-process calls.&lt;br /&gt;
*'''Too many parameters''': A long list of parameters in a procedure or function make readability and code quality worse. The more parameters a method has, the more complex it is. Limit the number of parameters you need in a given method, or use an object to combine the parameters.&lt;br /&gt;
*'''Excessively long identifiers''': In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
*'''Excessively short identifiers''': The name of a variable should reflect its function unless the function is obvious. Pick a set of standard terminology and stick to it throughout your methods. For example, if you have Open(), you should probably have Close().&lt;br /&gt;
*'''Excessive use of literals''': These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
*'''Complex conditionals''': Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code. Large conditional logic blocks, particularly blocks that tend to grow larger or change significantly over time have to be eliminated. Consider alternative object-oriented approaches such as decorator, strategy, or state.&lt;br /&gt;
*'''Dead Code''': Ruthlessly delete code that isn't being used. Unused code will result in Long classes or long methods.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
Polymorphism can be implemented by pushing some methods to relevant classes. Following section of code contains certain method calls which are implemented in the same class. These can be abstracted into a different class for file operations:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def file_folder_action&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
    if params[:faction][:delete]        #call method to delete selected files&lt;br /&gt;
      delete_selected_files&lt;br /&gt;
    elsif params[:faction][:rename]     #call method to rename selected files&lt;br /&gt;
      rename_selected_file&lt;br /&gt;
    elsif params[:faction][:move]       #call method to move selected files&lt;br /&gt;
      move_selected_file&lt;br /&gt;
    elsif params[:faction][:copy]       #call method to copy selected files&lt;br /&gt;
      copy_selected_file&lt;br /&gt;
    elsif params[:faction][:create]     #call method to create new folder&lt;br /&gt;
      create_new_folder&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Code clean up done besides the requirements of the project.&lt;br /&gt;
Design choice for the changes made in partial files such that code reuse can be maximised.&lt;br /&gt;
Cucumber testing scenarios for the changes made: Work In Progress&lt;br /&gt;
Further code smells need to be processed for more elegance.&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
*Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
:(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
:(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
*Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
*Run bundle install &lt;br /&gt;
*Run - rake db:create:all&lt;br /&gt;
*Run - rake db:migrate&lt;br /&gt;
*From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
You should be able to view the test Database in MySQL.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: admin&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: sample&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81210</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81210"/>
		<updated>2013-10-30T19:42:54Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* List of Code Smells identified and removed */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.JPG|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.JPG|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
:Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_loc = @participant.get_path &lt;br /&gt;
    new_loc+= &amp;quot;/&amp;quot; &lt;br /&gt;
    new_loc+= params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_loc)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_location = @participant.get_path + &amp;quot;/&amp;quot; + params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_location)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Many more minor code changes are made following the Ruby Coding guidelines. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We should prefer to use 'unless' for such conditions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== List of Code Smells identified and removed ==&lt;br /&gt;
*'''Duplicated code''': Identical or very similar code exists in more than one location. Code duplication frequently creates long, repeated sections of code that differ in only a few lines or characters. The length of such routines can make it difficult to quickly understand them. The repetition of largely identical code sections can conceal how they differ from one another, and therefore, what the specific purpose of each code section is. Often, the only difference is in a parameter value. The best practice in such cases is a reusable subroutine.&lt;br /&gt;
*'''Long method''': A method, function, or procedure that has grown too large. Since the early days of programming people have realized that the longer a procedure is, the more difficult it is to understand. Older languages carried an overhead in subroutine calls, which deterred people from small methods. Modern OO languages have pretty much eliminated that overhead for in-process calls.&lt;br /&gt;
*'''Too many parameters''': A long list of parameters in a procedure or function make readability and code quality worse. The more parameters a method has, the more complex it is. Limit the number of parameters you need in a given method, or use an object to combine the parameters.&lt;br /&gt;
*'''Excessively long identifiers''': In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
*'''Excessively short identifiers''': The name of a variable should reflect its function unless the function is obvious. Pick a set of standard terminology and stick to it throughout your methods. For example, if you have Open(), you should probably have Close().&lt;br /&gt;
*'''Excessive use of literals''': These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
*'''Complex conditionals''': Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code. Large conditional logic blocks, particularly blocks that tend to grow larger or change significantly over time have to be eliminated. Consider alternative object-oriented approaches such as decorator, strategy, or state.&lt;br /&gt;
*'''Dead Code''': Ruthlessly delete code that isn't being used. Unused code will result in Long classes or long methods.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
*Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
:(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
:(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
*Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
*Run bundle install &lt;br /&gt;
*Run - rake db:create:all&lt;br /&gt;
*Run - rake db:migrate&lt;br /&gt;
*From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
You should be able to view the test Database in MySQL.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: admin&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: sample&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81209</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81209"/>
		<updated>2013-10-30T19:42:31Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* Appendix: setup issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.JPG|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.JPG|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
:Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_loc = @participant.get_path &lt;br /&gt;
    new_loc+= &amp;quot;/&amp;quot; &lt;br /&gt;
    new_loc+= params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_loc)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_location = @participant.get_path + &amp;quot;/&amp;quot; + params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_location)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Many more minor code changes are made following the Ruby Coding guidelines. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We should prefer to use 'unless' for such conditions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== List of Code Smells identified and removed ==&lt;br /&gt;
*'''Duplicated code: Identical or very similar code exists in more than one location. Code duplication frequently creates long, repeated sections of code that differ in only a few lines or characters. The length of such routines can make it difficult to quickly understand them. The repetition of largely identical code sections can conceal how they differ from one another, and therefore, what the specific purpose of each code section is. Often, the only difference is in a parameter value. The best practice in such cases is a reusable subroutine.&lt;br /&gt;
*'''Long method''': A method, function, or procedure that has grown too large. Since the early days of programming people have realized that the longer a procedure is, the more difficult it is to understand. Older languages carried an overhead in subroutine calls, which deterred people from small methods. Modern OO languages have pretty much eliminated that overhead for in-process calls.&lt;br /&gt;
*'''Too many parameters''': A long list of parameters in a procedure or function make readability and code quality worse. The more parameters a method has, the more complex it is. Limit the number of parameters you need in a given method, or use an object to combine the parameters.&lt;br /&gt;
*'''Excessively long identifiers''': In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
*'''Excessively short identifiers''': The name of a variable should reflect its function unless the function is obvious. Pick a set of standard terminology and stick to it throughout your methods. For example, if you have Open(), you should probably have Close().&lt;br /&gt;
*'''Excessive use of literals''': These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
*'''Complex conditionals''': Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code. Large conditional logic blocks, particularly blocks that tend to grow larger or change significantly over time have to be eliminated. Consider alternative object-oriented approaches such as decorator, strategy, or state.&lt;br /&gt;
*'''Dead Code''': Ruthlessly delete code that isn't being used. Unused code will result in Long classes or long methods.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
*Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
:(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
:(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
*Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
*Run bundle install &lt;br /&gt;
*Run - rake db:create:all&lt;br /&gt;
*Run - rake db:migrate&lt;br /&gt;
*From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
You should be able to view the test Database in MySQL.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: admin&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: sample&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81207</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81207"/>
		<updated>2013-10-30T19:41:48Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* Appendix: setup issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.JPG|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.JPG|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
:Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_loc = @participant.get_path &lt;br /&gt;
    new_loc+= &amp;quot;/&amp;quot; &lt;br /&gt;
    new_loc+= params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_loc)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_location = @participant.get_path + &amp;quot;/&amp;quot; + params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_location)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Many more minor code changes are made following the Ruby Coding guidelines. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We should prefer to use 'unless' for such conditions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== List of Code Smells identified and removed ==&lt;br /&gt;
*'''Duplicated code: Identical or very similar code exists in more than one location. Code duplication frequently creates long, repeated sections of code that differ in only a few lines or characters. The length of such routines can make it difficult to quickly understand them. The repetition of largely identical code sections can conceal how they differ from one another, and therefore, what the specific purpose of each code section is. Often, the only difference is in a parameter value. The best practice in such cases is a reusable subroutine.&lt;br /&gt;
*'''Long method''': A method, function, or procedure that has grown too large. Since the early days of programming people have realized that the longer a procedure is, the more difficult it is to understand. Older languages carried an overhead in subroutine calls, which deterred people from small methods. Modern OO languages have pretty much eliminated that overhead for in-process calls.&lt;br /&gt;
*'''Too many parameters''': A long list of parameters in a procedure or function make readability and code quality worse. The more parameters a method has, the more complex it is. Limit the number of parameters you need in a given method, or use an object to combine the parameters.&lt;br /&gt;
*'''Excessively long identifiers''': In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
*'''Excessively short identifiers''': The name of a variable should reflect its function unless the function is obvious. Pick a set of standard terminology and stick to it throughout your methods. For example, if you have Open(), you should probably have Close().&lt;br /&gt;
*'''Excessive use of literals''': These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
*'''Complex conditionals''': Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code. Large conditional logic blocks, particularly blocks that tend to grow larger or change significantly over time have to be eliminated. Consider alternative object-oriented approaches such as decorator, strategy, or state.&lt;br /&gt;
*'''Dead Code''': Ruthlessly delete code that isn't being used. Unused code will result in Long classes or long methods.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
*Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
	:(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
	:(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
*Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
*Run bundle install &lt;br /&gt;
*Run - rake db:create:all&lt;br /&gt;
*Run - rake db:migrate&lt;br /&gt;
*From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
You should be able to view the test Database in MySQL.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: admin&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: sample&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81203</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81203"/>
		<updated>2013-10-30T19:38:41Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* Appendix: setup issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.JPG|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.JPG|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
:Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_loc = @participant.get_path &lt;br /&gt;
    new_loc+= &amp;quot;/&amp;quot; &lt;br /&gt;
    new_loc+= params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_loc)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_location = @participant.get_path + &amp;quot;/&amp;quot; + params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_location)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Many more minor code changes are made following the Ruby Coding guidelines. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We should prefer to use 'unless' for such conditions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== List of Code Smells identified and removed ==&lt;br /&gt;
*'''Duplicated code: Identical or very similar code exists in more than one location. Code duplication frequently creates long, repeated sections of code that differ in only a few lines or characters. The length of such routines can make it difficult to quickly understand them. The repetition of largely identical code sections can conceal how they differ from one another, and therefore, what the specific purpose of each code section is. Often, the only difference is in a parameter value. The best practice in such cases is a reusable subroutine.&lt;br /&gt;
*'''Long method''': A method, function, or procedure that has grown too large. Since the early days of programming people have realized that the longer a procedure is, the more difficult it is to understand. Older languages carried an overhead in subroutine calls, which deterred people from small methods. Modern OO languages have pretty much eliminated that overhead for in-process calls.&lt;br /&gt;
*'''Too many parameters''': A long list of parameters in a procedure or function make readability and code quality worse. The more parameters a method has, the more complex it is. Limit the number of parameters you need in a given method, or use an object to combine the parameters.&lt;br /&gt;
*'''Excessively long identifiers''': In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
*'''Excessively short identifiers''': The name of a variable should reflect its function unless the function is obvious. Pick a set of standard terminology and stick to it throughout your methods. For example, if you have Open(), you should probably have Close().&lt;br /&gt;
*'''Excessive use of literals''': These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
*'''Complex conditionals''': Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code. Large conditional logic blocks, particularly blocks that tend to grow larger or change significantly over time have to be eliminated. Consider alternative object-oriented approaches such as decorator, strategy, or state.&lt;br /&gt;
*'''Dead Code''': Ruthlessly delete code that isn't being used. Unused code will result in Long classes or long methods.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
*Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
	(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
	(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
*Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
*Run bundle install &lt;br /&gt;
*Run - rake db:create:all&lt;br /&gt;
*Run - rake db:migrate&lt;br /&gt;
*From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
You should be able to view the test Database in MySQL.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: admin&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: sample&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81202</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81202"/>
		<updated>2013-10-30T19:37:57Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* Appendix: setup issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.JPG|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.JPG|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
:Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_loc = @participant.get_path &lt;br /&gt;
    new_loc+= &amp;quot;/&amp;quot; &lt;br /&gt;
    new_loc+= params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_loc)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_location = @participant.get_path + &amp;quot;/&amp;quot; + params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_location)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Many more minor code changes are made following the Ruby Coding guidelines. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We should prefer to use 'unless' for such conditions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== List of Code Smells identified and removed ==&lt;br /&gt;
*'''Duplicated code: Identical or very similar code exists in more than one location. Code duplication frequently creates long, repeated sections of code that differ in only a few lines or characters. The length of such routines can make it difficult to quickly understand them. The repetition of largely identical code sections can conceal how they differ from one another, and therefore, what the specific purpose of each code section is. Often, the only difference is in a parameter value. The best practice in such cases is a reusable subroutine.&lt;br /&gt;
*'''Long method''': A method, function, or procedure that has grown too large. Since the early days of programming people have realized that the longer a procedure is, the more difficult it is to understand. Older languages carried an overhead in subroutine calls, which deterred people from small methods. Modern OO languages have pretty much eliminated that overhead for in-process calls.&lt;br /&gt;
*'''Too many parameters''': A long list of parameters in a procedure or function make readability and code quality worse. The more parameters a method has, the more complex it is. Limit the number of parameters you need in a given method, or use an object to combine the parameters.&lt;br /&gt;
*'''Excessively long identifiers''': In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
*'''Excessively short identifiers''': The name of a variable should reflect its function unless the function is obvious. Pick a set of standard terminology and stick to it throughout your methods. For example, if you have Open(), you should probably have Close().&lt;br /&gt;
*'''Excessive use of literals''': These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
*'''Complex conditionals''': Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code. Large conditional logic blocks, particularly blocks that tend to grow larger or change significantly over time have to be eliminated. Consider alternative object-oriented approaches such as decorator, strategy, or state.&lt;br /&gt;
*'''Dead Code''': Ruthlessly delete code that isn't being used. Unused code will result in Long classes or long methods.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
*Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
	(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
	(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
*Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
*Run bundle install &lt;br /&gt;
*Run - rake db:create:all&lt;br /&gt;
*Run - rake db:migrate&lt;br /&gt;
*From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
You should be able to view the test Database in MySQL.&lt;br /&gt;
 &amp;lt;br&amp;gt;&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: admin&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: sample&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81199</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81199"/>
		<updated>2013-10-30T19:36:16Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.JPG|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.JPG|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
:Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_loc = @participant.get_path &lt;br /&gt;
    new_loc+= &amp;quot;/&amp;quot; &lt;br /&gt;
    new_loc+= params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_loc)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_location = @participant.get_path + &amp;quot;/&amp;quot; + params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_location)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Many more minor code changes are made following the Ruby Coding guidelines. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We should prefer to use 'unless' for such conditions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== List of Code Smells identified and removed ==&lt;br /&gt;
*'''Duplicated code: Identical or very similar code exists in more than one location. Code duplication frequently creates long, repeated sections of code that differ in only a few lines or characters. The length of such routines can make it difficult to quickly understand them. The repetition of largely identical code sections can conceal how they differ from one another, and therefore, what the specific purpose of each code section is. Often, the only difference is in a parameter value. The best practice in such cases is a reusable subroutine.&lt;br /&gt;
*'''Long method''': A method, function, or procedure that has grown too large. Since the early days of programming people have realized that the longer a procedure is, the more difficult it is to understand. Older languages carried an overhead in subroutine calls, which deterred people from small methods. Modern OO languages have pretty much eliminated that overhead for in-process calls.&lt;br /&gt;
*'''Too many parameters''': A long list of parameters in a procedure or function make readability and code quality worse. The more parameters a method has, the more complex it is. Limit the number of parameters you need in a given method, or use an object to combine the parameters.&lt;br /&gt;
*'''Excessively long identifiers''': In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
*'''Excessively short identifiers''': The name of a variable should reflect its function unless the function is obvious. Pick a set of standard terminology and stick to it throughout your methods. For example, if you have Open(), you should probably have Close().&lt;br /&gt;
*'''Excessive use of literals''': These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
*'''Complex conditionals''': Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code. Large conditional logic blocks, particularly blocks that tend to grow larger or change significantly over time have to be eliminated. Consider alternative object-oriented approaches such as decorator, strategy, or state.&lt;br /&gt;
*'''Dead Code''': Ruthlessly delete code that isn't being used. Unused code will result in Long classes or long methods.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
*Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
	(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
	(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
*Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
*Run bundle install &lt;br /&gt;
*Run - rake db:create:all&lt;br /&gt;
*Run - rake db:migrate&lt;br /&gt;
*From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
You should be able to view the test Database in MySQL.&lt;br /&gt;
 &amp;lt;br&amp;gt;&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: admin&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Password: sample&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81194</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81194"/>
		<updated>2013-10-30T19:33:09Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.JPG|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.JPG|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
:Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_loc = @participant.get_path &lt;br /&gt;
    new_loc+= &amp;quot;/&amp;quot; &lt;br /&gt;
    new_loc+= params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_loc)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_location = @participant.get_path + &amp;quot;/&amp;quot; + params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_location)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Many more minor code changes are made following the Ruby Coding guidelines. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We should prefer to use 'unless' for such conditions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== List of Code Smells identified and removed ==&lt;br /&gt;
*'''Duplicated code: Identical or very similar code exists in more than one location. Code duplication frequently creates long, repeated sections of code that differ in only a few lines or characters. The length of such routines can make it difficult to quickly understand them. The repetition of largely identical code sections can conceal how they differ from one another, and therefore, what the specific purpose of each code section is. Often, the only difference is in a parameter value. The best practice in such cases is a reusable subroutine.&lt;br /&gt;
*'''Long method''': A method, function, or procedure that has grown too large. Since the early days of programming people have realized that the longer a procedure is, the more difficult it is to understand. Older languages carried an overhead in subroutine calls, which deterred people from small methods. Modern OO languages have pretty much eliminated that overhead for in-process calls.&lt;br /&gt;
*'''Too many parameters''': A long list of parameters in a procedure or function make readability and code quality worse. The more parameters a method has, the more complex it is. Limit the number of parameters you need in a given method, or use an object to combine the parameters.&lt;br /&gt;
*'''Excessively long identifiers''': In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
*'''Excessively short identifiers''': The name of a variable should reflect its function unless the function is obvious. Pick a set of standard terminology and stick to it throughout your methods. For example, if you have Open(), you should probably have Close().&lt;br /&gt;
*'''Excessive use of literals''': These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
*'''Complex conditionals''': Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code. Large conditional logic blocks, particularly blocks that tend to grow larger or change significantly over time have to be eliminated. Consider alternative object-oriented approaches such as decorator, strategy, or state.&lt;br /&gt;
*'''Dead Code''': Ruthlessly delete code that isn't being used. Unused code will result in Long classes or long methods.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
1. Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
	(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
	(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
2. Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
3. Run bundle install &lt;br /&gt;
4. Run - rake db:create:all&lt;br /&gt;
5. Run - rake db:migrate&lt;br /&gt;
6. From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&lt;br /&gt;
You should be able to view the test Database in MySQL.&lt;br /&gt;
 &lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
Password: admin&lt;br /&gt;
&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
Password: sample&lt;br /&gt;
&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81169</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81169"/>
		<updated>2013-10-30T19:23:11Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.JPG|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.JPG|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
 &lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
:Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_loc = @participant.get_path &lt;br /&gt;
    new_loc+= &amp;quot;/&amp;quot; &lt;br /&gt;
    new_loc+= params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_loc)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_location = @participant.get_path + &amp;quot;/&amp;quot; + params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_location)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Many more minor code changes are made following the Ruby Coding guidelines. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We should prefer to use 'unless' for such conditions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== List of Code Smells identified and removed ==&lt;br /&gt;
*'''Duplicated code: Identical or very similar code exists in more than one location. Code duplication frequently creates long, repeated sections of code that differ in only a few lines or characters. The length of such routines can make it difficult to quickly understand them. The repetition of largely identical code sections can conceal how they differ from one another, and therefore, what the specific purpose of each code section is. Often, the only difference is in a parameter value. The best practice in such cases is a reusable subroutine.&lt;br /&gt;
*'''Long method''': A method, function, or procedure that has grown too large. Since the early days of programming people have realized that the longer a procedure is, the more difficult it is to understand. Older languages carried an overhead in subroutine calls, which deterred people from small methods. Modern OO languages have pretty much eliminated that overhead for in-process calls.&lt;br /&gt;
*'''Too many parameters''': A long list of parameters in a procedure or function make readability and code quality worse. The more parameters a method has, the more complex it is. Limit the number of parameters you need in a given method, or use an object to combine the parameters.&lt;br /&gt;
*'''Excessively long identifiers''': In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
*'''Excessively short identifiers''': The name of a variable should reflect its function unless the function is obvious. Pick a set of standard terminology and stick to it throughout your methods. For example, if you have Open(), you should probably have Close().&lt;br /&gt;
*'''Excessive use of literals''': These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
*'''Complex conditionals''': Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code. Large conditional logic blocks, particularly blocks that tend to grow larger or change significantly over time have to be eliminated. Consider alternative object-oriented approaches such as decorator, strategy, or state.&lt;br /&gt;
*'''Dead Code''': Ruthlessly delete code that isn't being used. Unused code will result in Long classes or long methods.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
1. Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
	(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
	(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
2. Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
3. Run bundle install &lt;br /&gt;
4. Run - rake db:create:all&lt;br /&gt;
5. Run - rake db:migrate&lt;br /&gt;
6. From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should be able to view the test Database in MySQL in the following way:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
Password: admin&lt;br /&gt;
&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
Password: sample&lt;br /&gt;
&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81121</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81121"/>
		<updated>2013-10-30T19:05:21Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.JPG|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.JPG|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
 &lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
:Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_loc = @participant.get_path &lt;br /&gt;
    new_loc+= &amp;quot;/&amp;quot; &lt;br /&gt;
    new_loc+= params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_loc)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_location = @participant.get_path + &amp;quot;/&amp;quot; + params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_location)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Many more minor code changes are made following the Ruby Coding guidelines. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We should prefer to use 'unless' for such conditions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== List of Code Smells identified and removed ==&lt;br /&gt;
*Duplicated code: Identical or very similar code exists in more than one location. Code duplication frequently creates long, repeated sections of code that differ in only a few lines or characters. The length of such routines can make it difficult to quickly understand them. The repetition of largely identical code sections can conceal how they differ from one another, and therefore, what the specific purpose of each code section is. Often, the only difference is in a parameter value. The best practice in such cases is a reusable subroutine.&lt;br /&gt;
*Long method: A method, function, or procedure that has grown too large.&lt;br /&gt;
*Too many parameters: A long list of parameters in a procedure or function make readability and code quality worse.&lt;br /&gt;
*Excessively long identifiers: In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
*Excessively short identifiers: The name of a variable should reflect its function unless the function is obvious.&lt;br /&gt;
*Excessive use of literals: These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
*Complex conditionals: Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
1. Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
	(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
	(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
2. Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
3. Run bundle install &lt;br /&gt;
4. Run - rake db:create:all&lt;br /&gt;
5. Run - rake db:migrate&lt;br /&gt;
6. From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should be able to view the test Database in MySQL in the following way:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
Password: admin&lt;br /&gt;
&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
Password: sample&lt;br /&gt;
&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81082</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81082"/>
		<updated>2013-10-30T18:53:36Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.JPG|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.JPG|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
 &lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
:Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_loc = @participant.get_path &lt;br /&gt;
    new_loc+= &amp;quot;/&amp;quot; &lt;br /&gt;
    new_loc+= params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_loc)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_location = @participant.get_path + &amp;quot;/&amp;quot; + params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_location)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Many more minor code changes are made following the Ruby Coding guidelines. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We should prefer to use 'unless' for such conditions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
1. Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
	(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
	(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
2. Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
3. Run bundle install &lt;br /&gt;
4. Run - rake db:create:all&lt;br /&gt;
5. Run - rake db:migrate&lt;br /&gt;
6. From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should be able to view the test Database in MySQL in the following way:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
Password: admin&lt;br /&gt;
&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
Password: sample&lt;br /&gt;
&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code Changes:&lt;br /&gt;
1.	&lt;br /&gt;
 &lt;br /&gt;
2.	&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Code Smells identified and removed:&lt;br /&gt;
•	Duplicated code: Identical or very similar code exists in more than one location.&lt;br /&gt;
•	Long method: A method, function, or procedure that has grown too large.&lt;br /&gt;
•	Too many parameters: A long list of parameters in a procedure or function make readability and code quality worse.&lt;br /&gt;
•	Excessively long identifiers: In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
•	Excessively short identifiers: The name of a variable should reflect its function unless the function is obvious.&lt;br /&gt;
•	Excessive use of literals: These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
•	Complex conditionals: Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81074</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81074"/>
		<updated>2013-10-30T18:51:05Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
 &lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.JPG|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.JPG|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
 &lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
:Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_loc = @participant.get_path &lt;br /&gt;
    new_loc+= &amp;quot;/&amp;quot; &lt;br /&gt;
    new_loc+= params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_loc)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_location = @participant.get_path + &amp;quot;/&amp;quot; + params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_location)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&lt;br /&gt;
*Many more minor code changes are made following the Ruby Coding guidelines. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We should prefer to use 'unless' for such conditions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless File.exist?(new_filename)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
1. Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
	(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
	(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
2. Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
3. Run bundle install &lt;br /&gt;
4. Run - rake db:create:all&lt;br /&gt;
5. Run - rake db:migrate&lt;br /&gt;
6. From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should be able to view the test Database in MySQL in the following way:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
Password: admin&lt;br /&gt;
&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
Password: sample&lt;br /&gt;
&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code Changes:&lt;br /&gt;
1.	&lt;br /&gt;
 &lt;br /&gt;
2.	&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Code Smells identified and removed:&lt;br /&gt;
•	Duplicated code: Identical or very similar code exists in more than one location.&lt;br /&gt;
•	Long method: A method, function, or procedure that has grown too large.&lt;br /&gt;
•	Too many parameters: A long list of parameters in a procedure or function make readability and code quality worse.&lt;br /&gt;
•	Excessively long identifiers: In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
•	Excessively short identifiers: The name of a variable should reflect its function unless the function is obvious.&lt;br /&gt;
•	Excessive use of literals: These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
•	Complex conditionals: Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81058</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81058"/>
		<updated>2013-10-30T18:47:04Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
 &lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.JPG|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.JPG|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
 &lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_loc = @participant.get_path &lt;br /&gt;
    new_loc+= &amp;quot;/&amp;quot; &lt;br /&gt;
    new_loc+= params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_loc)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def move_selected_file&lt;br /&gt;
    old_filename = params[:directories][params[:chk_files]] + &amp;quot;/&amp;quot; + params[:filenames][params[:chk_files]]&lt;br /&gt;
    new_location = @participant.get_path + &amp;quot;/&amp;quot; + params[:faction][:move]&lt;br /&gt;
    begin&lt;br /&gt;
      FileHelper::move_file(old_filename, new_location)&lt;br /&gt;
      flash[:note] = &amp;quot;The file was moved successfully from \&amp;quot;/#{params[:filenames][params[:chk_files]]}\&amp;quot; to \&amp;quot;/#{params[:faction][:move]}\&amp;quot;&amp;quot;&lt;br /&gt;
    rescue&lt;br /&gt;
      flash[:error] = &amp;quot;There was a problem moving the file: &amp;quot;+$!&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
1. Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
	(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
	(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
2. Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
3. Run bundle install &lt;br /&gt;
4. Run - rake db:create:all&lt;br /&gt;
5. Run - rake db:migrate&lt;br /&gt;
6. From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should be able to view the test Database in MySQL in the following way:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
Password: admin&lt;br /&gt;
&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
Password: sample&lt;br /&gt;
&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code Changes:&lt;br /&gt;
1.	&lt;br /&gt;
 &lt;br /&gt;
2.	&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Code Smells identified and removed:&lt;br /&gt;
•	Duplicated code: Identical or very similar code exists in more than one location.&lt;br /&gt;
•	Long method: A method, function, or procedure that has grown too large.&lt;br /&gt;
•	Too many parameters: A long list of parameters in a procedure or function make readability and code quality worse.&lt;br /&gt;
•	Excessively long identifiers: In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
•	Excessively short identifiers: The name of a variable should reflect its function unless the function is obvious.&lt;br /&gt;
•	Excessive use of literals: These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
•	Complex conditionals: Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81027</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81027"/>
		<updated>2013-10-30T18:37:45Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
 &lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.JPG|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.JPG|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
 &lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&lt;br /&gt;
5.	Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
1. Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
	(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
	(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
2. Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
3. Run bundle install &lt;br /&gt;
4. Run - rake db:create:all&lt;br /&gt;
5. Run - rake db:migrate&lt;br /&gt;
6. From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should be able to view the test Database in MySQL in the following way:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
Password: admin&lt;br /&gt;
&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
Password: sample&lt;br /&gt;
&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code Changes:&lt;br /&gt;
1.	&lt;br /&gt;
 &lt;br /&gt;
2.	&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Code Smells identified and removed:&lt;br /&gt;
•	Duplicated code: Identical or very similar code exists in more than one location.&lt;br /&gt;
•	Long method: A method, function, or procedure that has grown too large.&lt;br /&gt;
•	Too many parameters: A long list of parameters in a procedure or function make readability and code quality worse.&lt;br /&gt;
•	Excessively long identifiers: In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
•	Excessively short identifiers: The name of a variable should reflect its function unless the function is obvious.&lt;br /&gt;
•	Excessive use of literals: These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
•	Complex conditionals: Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81021</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81021"/>
		<updated>2013-10-30T18:35:25Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
 &lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.jpg|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.jpg|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
 &lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&lt;br /&gt;
5.	Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
1. Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
	(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
	(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
2. Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
3. Run bundle install &lt;br /&gt;
4. Run - rake db:create:all&lt;br /&gt;
5. Run - rake db:migrate&lt;br /&gt;
6. From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should be able to view the test Database in MySQL in the following way:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
Password: admin&lt;br /&gt;
&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
Password: sample&lt;br /&gt;
&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code Changes:&lt;br /&gt;
1.	&lt;br /&gt;
 &lt;br /&gt;
2.	&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Code Smells identified and removed:&lt;br /&gt;
•	Duplicated code: Identical or very similar code exists in more than one location.&lt;br /&gt;
•	Long method: A method, function, or procedure that has grown too large.&lt;br /&gt;
•	Too many parameters: A long list of parameters in a procedure or function make readability and code quality worse.&lt;br /&gt;
•	Excessively long identifiers: In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
•	Excessively short identifiers: The name of a variable should reflect its function unless the function is obvious.&lt;br /&gt;
•	Excessive use of literals: These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
•	Complex conditionals: Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Filepath.png&amp;diff=81016</id>
		<title>File:Filepath.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Filepath.png&amp;diff=81016"/>
		<updated>2013-10-30T18:34:43Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81010</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=81010"/>
		<updated>2013-10-30T18:33:41Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&lt;br /&gt;
== '''Introduction''' ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&lt;br /&gt;
== '''Project Description''' ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&lt;br /&gt;
== '''Design Changes''' ==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
 &lt;br /&gt;
*Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
&lt;br /&gt;
[[File:Unzip file mod.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
 &lt;br /&gt;
*Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
[[File:Fpath.png|frame|none|alt=Before Refactoring|Before Refactoring]] [[File:Filepath.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
&lt;br /&gt;
5.	Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
1. Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
	(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
	(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
2. Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
3. Run bundle install &lt;br /&gt;
4. Run - rake db:create:all&lt;br /&gt;
5. Run - rake db:migrate&lt;br /&gt;
6. From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should be able to view the test Database in MySQL in the following way:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
Password: admin&lt;br /&gt;
&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
Password: sample&lt;br /&gt;
&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code Changes:&lt;br /&gt;
1.	&lt;br /&gt;
 &lt;br /&gt;
2.	&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Code Smells identified and removed:&lt;br /&gt;
•	Duplicated code: Identical or very similar code exists in more than one location.&lt;br /&gt;
•	Long method: A method, function, or procedure that has grown too large.&lt;br /&gt;
•	Too many parameters: A long list of parameters in a procedure or function make readability and code quality worse.&lt;br /&gt;
•	Excessively long identifiers: In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
•	Excessively short identifiers: The name of a variable should reflect its function unless the function is obvious.&lt;br /&gt;
•	Excessive use of literals: These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
•	Complex conditionals: Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Fpath.png&amp;diff=81006</id>
		<title>File:Fpath.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Fpath.png&amp;diff=81006"/>
		<updated>2013-10-30T18:32:41Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Unzip_file_mod.JPG&amp;diff=80993</id>
		<title>File:Unzip file mod.JPG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Unzip_file_mod.JPG&amp;diff=80993"/>
		<updated>2013-10-30T18:26:13Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=80972</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=80972"/>
		<updated>2013-10-30T18:21:21Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
----&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
----&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&lt;br /&gt;
==Design Changes==&lt;br /&gt;
----&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
&lt;br /&gt;
[[File:Display change.png|frame|none|alt=After Refactoring|After Refactoring]]&lt;br /&gt;
 &lt;br /&gt;
3.	Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
 &lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
 &lt;br /&gt;
4.	Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
5.	Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
1. Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
	(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
	(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
2. Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
3. Run bundle install &lt;br /&gt;
4. Run - rake db:create:all&lt;br /&gt;
5. Run - rake db:migrate&lt;br /&gt;
6. From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should be able to view the test Database in MySQL in the following way:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
Password: admin&lt;br /&gt;
&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
Password: sample&lt;br /&gt;
&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code Changes:&lt;br /&gt;
1.	&lt;br /&gt;
 &lt;br /&gt;
2.	&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Code Smells identified and removed:&lt;br /&gt;
•	Duplicated code: Identical or very similar code exists in more than one location.&lt;br /&gt;
•	Long method: A method, function, or procedure that has grown too large.&lt;br /&gt;
•	Too many parameters: A long list of parameters in a procedure or function make readability and code quality worse.&lt;br /&gt;
•	Excessively long identifiers: In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
•	Excessively short identifiers: The name of a variable should reflect its function unless the function is obvious.&lt;br /&gt;
•	Excessive use of literals: These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
•	Complex conditionals: Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=80967</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=80967"/>
		<updated>2013-10-30T18:20:11Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ===&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
----&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
----&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&lt;br /&gt;
==Design Changes==&lt;br /&gt;
----&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
:We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
&lt;br /&gt;
[[File:Display variable.png|frame|none|alt=Before Refactoring|Before Refactoring]]&lt;br /&gt;
&lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
 &lt;br /&gt;
3.	Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
 &lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
 &lt;br /&gt;
4.	Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
5.	Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
1. Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
	(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
	(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
2. Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
3. Run bundle install &lt;br /&gt;
4. Run - rake db:create:all&lt;br /&gt;
5. Run - rake db:migrate&lt;br /&gt;
6. From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should be able to view the test Database in MySQL in the following way:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
Password: admin&lt;br /&gt;
&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
Password: sample&lt;br /&gt;
&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code Changes:&lt;br /&gt;
1.	&lt;br /&gt;
 &lt;br /&gt;
2.	&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Code Smells identified and removed:&lt;br /&gt;
•	Duplicated code: Identical or very similar code exists in more than one location.&lt;br /&gt;
•	Long method: A method, function, or procedure that has grown too large.&lt;br /&gt;
•	Too many parameters: A long list of parameters in a procedure or function make readability and code quality worse.&lt;br /&gt;
•	Excessively long identifiers: In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
•	Excessively short identifiers: The name of a variable should reflect its function unless the function is obvious.&lt;br /&gt;
•	Excessive use of literals: These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
•	Complex conditionals: Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=80941</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=80941"/>
		<updated>2013-10-30T18:12:42Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ==&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&lt;br /&gt;
==Design Changes==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can now be called from both submit_file and custom_submit_file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def submit_file&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    file = params[:uploaded_file]&lt;br /&gt;
    participant.set_student_directory_num&lt;br /&gt;
&lt;br /&gt;
    @current_folder = DisplayOption.new&lt;br /&gt;
    @current_folder.name = &amp;quot;/&amp;quot;&lt;br /&gt;
    if params[:current_folder]&lt;br /&gt;
      @current_folder.name = FileHelper::sanitize_folder(params[:current_folder][:name])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    curr_directory = participant.get_path.to_s+@current_folder.name&lt;br /&gt;
    check_file_exists(curr_directory)&lt;br /&gt;
&lt;br /&gt;
    safe_filename = file.original_filename.gsub(/\\/,&amp;quot;/&amp;quot;)&lt;br /&gt;
    safe_filename = FileHelper::sanitize_filename(safe_filename) # new code to sanitize file path before upload*&lt;br /&gt;
    full_filename =  curr_directory + File.split(safe_filename).last.gsub(&amp;quot; &amp;quot;,'_') #safe_filename #curr_directory +&lt;br /&gt;
    File.open(full_filename, &amp;quot;wb&amp;quot;) { |f| f.write(file.read) }&lt;br /&gt;
&lt;br /&gt;
    if params['unzip']&lt;br /&gt;
      SubmittedContentHelper::unzip_file(full_filename, curr_directory, true) if get_file_type(safe_filename) == &amp;quot;zip&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    participant.update_resubmit_times&lt;br /&gt;
&lt;br /&gt;
    #send message to reviewers when submission has been updated&lt;br /&gt;
    participant.assignment.email(participant.id) rescue nil # If the user has no team: 1) there are no reviewers to notify; 2) calling email will throw an exception. So rescue and ignore it.&lt;br /&gt;
&lt;br /&gt;
    redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; participant.id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
1. Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
	(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
	(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
2. Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
3. Run bundle install &lt;br /&gt;
4. Run - rake db:create:all&lt;br /&gt;
5. Run - rake db:migrate&lt;br /&gt;
6. From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should be able to view the test Database in MySQL in the following way:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
Password: admin&lt;br /&gt;
&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
Password: sample&lt;br /&gt;
&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code Changes:&lt;br /&gt;
1.	&lt;br /&gt;
 &lt;br /&gt;
2.	&lt;br /&gt;
 &lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
 &lt;br /&gt;
3.	Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
 &lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
 &lt;br /&gt;
4.	Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
5.	Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Code Smells identified and removed:&lt;br /&gt;
•	Duplicated code: Identical or very similar code exists in more than one location.&lt;br /&gt;
•	Long method: A method, function, or procedure that has grown too large.&lt;br /&gt;
•	Too many parameters: A long list of parameters in a procedure or function make readability and code quality worse.&lt;br /&gt;
•	Excessively long identifiers: In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
•	Excessively short identifiers: The name of a variable should reflect its function unless the function is obvious.&lt;br /&gt;
•	Excessive use of literals: These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
•	Complex conditionals: Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Display_change.png&amp;diff=80863</id>
		<title>File:Display change.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Display_change.png&amp;diff=80863"/>
		<updated>2013-10-30T17:30:56Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Display_variable.png&amp;diff=80862</id>
		<title>File:Display variable.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Display_variable.png&amp;diff=80862"/>
		<updated>2013-10-30T17:30:40Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Unzip_file.JPG&amp;diff=80846</id>
		<title>File:Unzip file.JPG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Unzip_file.JPG&amp;diff=80846"/>
		<updated>2013-10-30T17:24:50Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=80843</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=80843"/>
		<updated>2013-10-30T17:23:32Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ==&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&lt;br /&gt;
==Design Changes==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def check_file_exists  curr_directory&lt;br /&gt;
    #check if file exists. If not, create a new file. Else, remove the existing file and then create new file.&lt;br /&gt;
    if !File.exists? curr_directory&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    else&lt;br /&gt;
      FileUtils.rm_rf(curr_directory)&lt;br /&gt;
      FileUtils.mkdir_p(curr_directory)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
1. Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
	(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
	(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
2. Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
3. Run bundle install &lt;br /&gt;
4. Run - rake db:create:all&lt;br /&gt;
5. Run - rake db:migrate&lt;br /&gt;
6. From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should be able to view the test Database in MySQL in the following way:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
Password: admin&lt;br /&gt;
&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
Password: sample&lt;br /&gt;
&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code Changes:&lt;br /&gt;
1.	&lt;br /&gt;
 &lt;br /&gt;
2.	Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
 &lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
 &lt;br /&gt;
3.	Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
 &lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
 &lt;br /&gt;
4.	Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
5.	Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Code Smells identified and removed:&lt;br /&gt;
•	Duplicated code: Identical or very similar code exists in more than one location.&lt;br /&gt;
•	Long method: A method, function, or procedure that has grown too large.&lt;br /&gt;
•	Too many parameters: A long list of parameters in a procedure or function make readability and code quality worse.&lt;br /&gt;
•	Excessively long identifiers: In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
•	Excessively short identifiers: The name of a variable should reflect its function unless the function is obvious.&lt;br /&gt;
•	Excessive use of literals: These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
•	Complex conditionals: Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=80839</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=80839"/>
		<updated>2013-10-30T17:20:24Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ==&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application that is used for Project/Assignment submissions. Students can form teams, select topics, submit assignments, review other's work and give feedback for reviews. Submission of work can be done in two ways:&lt;br /&gt;
*Hyperlinks&lt;br /&gt;
*Files/Folders&lt;br /&gt;
&lt;br /&gt;
Submitted_Content_Controller and Submitted_Content_Helper are designed to handle operations on hyperlinks and files. They include methods to submit, verify and remove hyperlinks; and create, move, rename, submit and remove files.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;br /&gt;
&lt;br /&gt;
==Design Changes==&lt;br /&gt;
&lt;br /&gt;
*Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with code reuse.&lt;br /&gt;
&lt;br /&gt;
We identified a sequence of operations that are repetitively used in methods which are used to submit files for the first time and again in review. The code to check if a file exists or not and creating a new directory path for any new submission is common for both submission and review pages. Thus we separated it out as a different method ‘check_file_exists’ as shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:New method.jpg|frame|none|alt=Refactored method|Refactored method]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix: setup issues==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Git repository: https://github.com/hsure/expertiza&lt;br /&gt;
Application URL: 152.1.13.219::3000&lt;br /&gt;
&lt;br /&gt;
Steps to setup the project:&lt;br /&gt;
1. Extract source code in RubyMine using the following url: https://github.com/hsure/expertiza&lt;br /&gt;
	(A) VCS -&amp;gt; Checkout from version control -&amp;gt; Github&lt;br /&gt;
	(B) Give this url:  https://github.com/hsure/expertiza -&amp;gt; Finish&lt;br /&gt;
2. Confirm the sdk for RubyMine to ruby1.9.3 using File -&amp;gt; Settings &lt;br /&gt;
3. Run bundle install &lt;br /&gt;
4. Run - rake db:create:all&lt;br /&gt;
5. Run - rake db:migrate&lt;br /&gt;
6. From the Expertiza folder (project root) execute the command “rails server”&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should be able to view the test Database in MySQL in the following way:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Use the following credentials to explore the application:&lt;br /&gt;
Username: admin (Administrator)&lt;br /&gt;
Password: admin&lt;br /&gt;
&lt;br /&gt;
Username: sample (User)&lt;br /&gt;
Password: sample&lt;br /&gt;
&lt;br /&gt;
In order to test, login with user credentials and navigate to Assignments page. In Homework1 select ‘Your work’ and submit a hyperlink.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code Changes:&lt;br /&gt;
1.	&lt;br /&gt;
 &lt;br /&gt;
2.	Unnecessary variable declarations which are never used in the method increase the length of code and confuse the readers. For example, the variable ‘display’ shown in the code snippet below was defined but never used in the method. Such variables can be removed.&lt;br /&gt;
 &lt;br /&gt;
The actual variable that was used which is ‘disp’ can now be renamed to ‘display’ which is more meaningful.&lt;br /&gt;
 &lt;br /&gt;
3.	Long methods are often caused due to unnecessary parameters. Long list of parameters reduce readability of code. Following changes are made to remove such unnecessary parameters:&lt;br /&gt;
 &lt;br /&gt;
Here the variable safename is declared and used only once. The assignment can be made inline by replacing it in the method call with actual logic in the below way:&lt;br /&gt;
 &lt;br /&gt;
4.	Below is another name change from ‘fpath’ to ‘file_path’ which is made to eliminate the most common code smell ‘Excessively short identifiers’.&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
5.	Consecutive assignments or modifications of the same variable can lead to “Long method” or “Excessive use of literals”. Such code smells are removed. For example, variable ‘newloc’ which is modified consecutively is refactored in the following way:&lt;br /&gt;
 &lt;br /&gt;
Modified code reduces the method length and increases Readability.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of Code Smells identified and removed:&lt;br /&gt;
•	Duplicated code: Identical or very similar code exists in more than one location.&lt;br /&gt;
•	Long method: A method, function, or procedure that has grown too large.&lt;br /&gt;
•	Too many parameters: A long list of parameters in a procedure or function make readability and code quality worse.&lt;br /&gt;
•	Excessively long identifiers: In particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture.&lt;br /&gt;
•	Excessively short identifiers: The name of a variable should reflect its function unless the function is obvious.&lt;br /&gt;
•	Excessive use of literals: These should be coded as named constants, to improve readability and to avoid programming errors. Additionally, literals can and should be externalized into resource files/scripts where possible, to facilitate localization of software if it is intended to be deployed in different regions.&lt;br /&gt;
•	Complex conditionals: Branches that check lots of unrelated conditions and edge cases that don't seem to capture the meaning of a block of code.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:New_method.JPG&amp;diff=80836</id>
		<title>File:New method.JPG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:New_method.JPG&amp;diff=80836"/>
		<updated>2013-10-30T17:16:59Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=80524</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=80524"/>
		<updated>2013-10-30T03:46:55Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
	 submitted_content_helper.rb (98 lines) &amp;lt;br&amp;gt;&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza. &amp;lt;br&amp;gt;&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=80523</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=80523"/>
		<updated>2013-10-30T03:46:24Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ==&lt;br /&gt;
&lt;br /&gt;
Classes: submitted_content_controller.rb (250 lines)&lt;br /&gt;
	 submitted_content_helper.rb (98 lines)&lt;br /&gt;
What they do: Allow users to submit files and links to Expertiza.&lt;br /&gt;
What needs to be done:  The methods are long and complex, and contain a lot of duplicated code.  In particular, there are two different ways of submitting files: as a homework submission, and uploading a review file requested by a review rubric.  These should use common code as much as possible.  The approach to deleting submitted links and submitted files should be analogous.  There have been bugs in deleting hyperlinks, so be sure to test the code thoroughly.&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=80521</id>
		<title>CSC/ECE 517 Fall 2013/oss E811 syn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E811_syn&amp;diff=80521"/>
		<updated>2013-10-30T03:45:37Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: Created page with &amp;quot; == E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ==&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== E811. Refactor &amp;amp; test submitted_content_controller &amp;amp; submitted_content_helper ==&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013&amp;diff=80519</id>
		<title>CSC/ECE 517 Fall 2013</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013&amp;diff=80519"/>
		<updated>2013-10-30T03:44:13Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [[ CSC/ECE 517 Fall 2012/ch1 1w23 ph ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w30 nn]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w21 w]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w01 aj]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w24 nv]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w29 rkld]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w25 aras]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w30 ps]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w19 rj]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w18 bs]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w17 pk]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w22 ss]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w12 vn]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w14 st]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w08 cc]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w10 ga ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w26 as ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w27 ma ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w13 aa ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w11 sv ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w07 d ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w20 gq ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w03 ss ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w28 nm ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w02 pp ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1  1w6 zs ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1  1w04 y ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w05 st ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w09 hs ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w32 av ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w48 x ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w43 av]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w46 ka]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w33 aa]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w35 sa ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w39 as ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w31 vm ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w43 sm ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w44 s ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w47 ka ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w34 fs ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w40 ao ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/oss fmv ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/oss vna ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/oss paa ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/oss mapFeeds ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/oss ssp ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch2 0e808 nsv ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/oss aoa ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/oss cmh ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/oss ans ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/oss ssv]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/oss E818 mra ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/oss SocialMediaFeeds ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/oss E811 syn ]]&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78799</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w23 ph</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78799"/>
		<updated>2013-09-24T20:12:21Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* See Also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby Coding Guidelines''' ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] Coding Guidelines include best practices followed generally for most of the [http://en.wikipedia.org/wiki/Category:Object-oriented_programming_languages object oriented programming languages] as Ruby is entirely 'Object Oriented'. Also known as 'Ruby Coding conventions', these are a set of guidelines that recommend programming style, practices and methods for each aspect of a piece of program written in Ruby. &lt;br /&gt;
&lt;br /&gt;
Software programmers are highly recommended to follow these guidelines to help improve the readability of their source code and make software maintenance easier. Naming conventions, class and member design principles, maintainability, performance, documentation and layout are the important areas where these guidelines have to be followed. More important than the reasons for having a guideline is actually adhering to it consistently.  Having a coding guideline documented and available means nothing if developers are not using it consistently.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Types of Guidelines''' ==&lt;br /&gt;
Coding guidelines in Ruby can be defined individually for major sections that code consists of. Naming , Class Design , Member Design , Maintainability, Performance, Documentation and Layout guidelines are illustrated below. These guidelines contain sections common to all of these as well as sections which apply to each one individually.&lt;br /&gt;
&lt;br /&gt;
=== Naming Guidelines&amp;lt;ref&amp;gt;http://itsignals.cascadia.com.au/?p=7&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Ruby uses the first character of the name to help it determine it’s intended use.&lt;br /&gt;
The standard Ruby file extension is .rb, although many people working on [http://en.wikipedia.org/wiki/Unix UNIX]-like systems don't bother with it for stand-alone scripts. Whether or not one uses it for scripts is up to them, but they will need to use it for library files or they will not be found by the interpreter.&lt;br /&gt;
&lt;br /&gt;
*'''Local Variables'''&lt;br /&gt;
:Should use lowercase letter followed by other characters. Naming convention states that it is better to use underscores rather than [http://en.wikipedia.org/wiki/CamelCase camelBack] for multiple word names, e.g. average, variable_xyz&lt;br /&gt;
*'''Instance Variables'''&lt;br /&gt;
:Instance variables are defined using the single &amp;quot;at&amp;quot; sign (@) followed by a name. It is suggested that a lowercase letter should succeed @, e.g. @color &lt;br /&gt;
*'''Instance Methods'''&lt;br /&gt;
:Method names should start with a lowercase letter, and may be followed by digits, underscores, and letters. The name should possibly be a verb e.g. move, display_details&lt;br /&gt;
*'''Class Variables'''&lt;br /&gt;
:Class variable names start with a double &amp;quot;at&amp;quot; sign (@@) and may be followed by digits, underscores, and letters, e.g. @@color&lt;br /&gt;
*'''Constant''' &lt;br /&gt;
:Constant names usually start with an uppercase letter followed by other characters. Constant objects are by convention named using all uppercase letters and underscores between words, e.g. THIS_IS_A_CONSTANT&lt;br /&gt;
*'''Class and Module''' &lt;br /&gt;
:Class names are recommended to be be nouns. In the case of modules, it's harder to make a clear recommendation. The names of [http://en.wikipedia.org/wiki/Mixin mix-ins] (which are just modules), however,  should probably be adjectives, such as the standard [http://en.wikibooks.org/wiki/Ruby_Programming/Reference/Objects/Enumerable Enumerable] and [http://www.ruby-doc.org/core-2.0.0/Comparable.html Comparable] modules. Class and module names starts with an uppercase letter, by convention they are named using MixedCase, e.g. module Encryption, class MixedCase&lt;br /&gt;
*'''Global Variables'''&lt;br /&gt;
:Starts with a dollar ($) sign followed by other characters, e.g. $global&lt;br /&gt;
&lt;br /&gt;
Considering customer order information as the data being used for an application, below naming guidelines give an idea of good class/table/file names.&lt;br /&gt;
*'''Model Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Table: orders&lt;br /&gt;
Class: Order&lt;br /&gt;
File: /app/models/order.rb&lt;br /&gt;
Primary Key: id&lt;br /&gt;
Foreign Key: customer_id&lt;br /&gt;
Link Tables: items_orders&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Controller Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class: OrdersController&lt;br /&gt;
File: /app/controllers/orders_controller.rb&lt;br /&gt;
Layout: /app/layouts/orders.html.erb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''View Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Helper: /app/helpers/orders_helper.rb&lt;br /&gt;
Helper Module: OrdersHelper&lt;br /&gt;
Views: /app/views/orders/… (list.html.erb for example)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Tests Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Unit: /test/unit/order_test.rb&lt;br /&gt;
Functional: /test/functional/orders_controller_test.rb&lt;br /&gt;
Fixtures: /test/fixtures/orders.yml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Class Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A class in Ruby always starts with the keyword class followed by the name of the class. The name should always be in initial capitals. Class Customer can be displayed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Customer&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A class is terminated by using the keyword end. All the data members in the class are between the class definition and the end keyword. &lt;br /&gt;
&lt;br /&gt;
Ruby blurs the distinction between design and implementation. Ideas that have to be expressed at the design level in other languages can be implemented directly in Ruby. To help in this process, Ruby has support for some design-level strategies. These strategies can be used to design classes accordingly as suitable for different types of  applications.&lt;br /&gt;
&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Visitor_pattern The Visitor pattern]''' is a way of traversing a collection without having to know the internal organization of that collection.&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Delegation_pattern Delegation]''' is a way of composing classes more flexibly and dynamically than can be done using standard inheritance.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Singleton_pattern Singleton pattern]''' is a way of ensuring that only one instantiation of a particular class exists at a time.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Observer_pattern Observer pattern]''' implements a protocol allowing one object to notify a set of interested objects when certain changes have occurred.&lt;br /&gt;
&lt;br /&gt;
Normally, all four of these strategies require explicit code each time they're implemented. With Ruby, they can be abstracted into a library and reused freely and transparently.&lt;br /&gt;
&lt;br /&gt;
=== Member Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
While defining class members, it is very important to keep in mind the access restrictions. Scope and life-time of class members are different for different restrictions, as illustrated below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public&lt;br /&gt;
totally accessible.&lt;br /&gt;
protected&lt;br /&gt;
accessible only by instances of class and direct descendants. Even through hasA relationships. (see below)&lt;br /&gt;
private&lt;br /&gt;
accessible only by instances of class (must be called nekkid no “self.” or anything else).&lt;br /&gt;
class A&lt;br /&gt;
  # Restriction used w/o arguments set the default access control.&lt;br /&gt;
  protected&lt;br /&gt;
&lt;br /&gt;
  def protected_method&lt;br /&gt;
    # nothing&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class B &amp;lt; A&lt;br /&gt;
  def test_protected&lt;br /&gt;
    myA = A.new&lt;br /&gt;
    myA.protected_method&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Used with arguments, sets the access of the named methods and constants.&lt;br /&gt;
  public :test_protected&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
b = B.new.test_protected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Maintainability Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
Maintainability guidelines are important to programmers for a number of reasons:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
*40%-80% of the lifetime cost of a piece of software goes to maintenance.&lt;br /&gt;
*Hardly any software is maintained for its whole life by the original author. &lt;br /&gt;
*Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. &lt;br /&gt;
*If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
The following guidelines are to be followed to improve the software maintainability&lt;br /&gt;
* '''Profile your code regularly'''&lt;br /&gt;
: If you profile your code regularly you’ll be able to tell if the latest change to the code will have an adverse effect on performance.  Integrate profiling into your testing process and make it automated to ensure that it’s not forgotten.  Like unit testing and BDD([http://en.wikipedia.org/wiki/Behavior-driven_development Behavior-driven development]) profiling goes a long way.&lt;br /&gt;
&lt;br /&gt;
=== Performance Guidelines&amp;lt;ref&amp;gt;http://blog.monitis.com/index.php/2012/02/08/20-ruby-performance-tips/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
The key parameter on which a software application is rated is by its performance. It is the time taken by the application to respond to a user's request. Performance of ruby can be improved significantly by following certain coding guidelines, as below.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid nesting loops more than three levels deep'''&lt;br /&gt;
: Nesting affects the performance of the code proportionally with the increasing levels in loops. Limiting nesting to three levels is one good practice to keep the code's performance well.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary variable assignments'''&lt;br /&gt;
: New programmers, often use unwanted variables in code.  A great example is when someone defines a variable to store a return value and then returns that variable; just return the value directly.&lt;br /&gt;
&lt;br /&gt;
*'''Reduce usage of disk I/O'''&lt;br /&gt;
: Disk I/O is a very costly operation as far as computing is concerned. Keeping it to the minimal improves the application response time drastically. Using disk I/O, makes the application extremely slow. Using storage systems such as memcached reduces disk I/O operations to a great extent as lot of data is kept in memory. The speed improvement while using a memory caching system is tremendous.&lt;br /&gt;
&lt;br /&gt;
*'''Use Ruby Enterprise Edition'''&lt;br /&gt;
: Ruby Enterprise edition provides up to [http://www.rubyenterpriseedition.com/faq.html#thirty_three_percent_mem_reduction 33% lower memory] usage.  Though, to get benefited by this performance one needs to follow their guidelines.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid method calls as much as possible'''&lt;br /&gt;
: Method calls are expensive operations in ruby. They should be avoided to keep up the performance of the application.&lt;br /&gt;
&lt;br /&gt;
*'''Use interpolated strings instead of concatenated strings'''&lt;br /&gt;
: Concatenated strings calls a method to get executed. So, it affects the performance as it is one of the most frequently used operation. Its better to replace them with Interpolated strings which runs faster as it doesn't invoke a method call.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
put “Hello there, #{name}!”vs.puts “Hello there, ” &amp;lt;&amp;lt; name = “!”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Destructive operations are faster'''&lt;br /&gt;
: Ruby’s in-place methods that which modifies the actual value than working on a copy of the data are much faster. But this should be handled carefully as original data gets disturbed.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary calls to uniq on arrays'''&lt;br /&gt;
: In many cases methods are already calling uniq on an array and there’s no need for you to call it yet again.&lt;br /&gt;
&lt;br /&gt;
*'''For loops are faster than .each'''&lt;br /&gt;
: .each uses an enumeration object behind the scene which adds a delay in execution. Using for instead of .each would improve performance but for short loops only.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/6406112/why-are-ruby-method-calls-particularly-slow-in-comparison-to-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Use x.blank? over x.nil? || x.empty?'''&lt;br /&gt;
: When using ActionPack there’s no need for x.nil? or x.empty?; x.blank? checks for both of these.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid calls to parse_date and strftime'''&lt;br /&gt;
: Both these calls are very expensive. using regular expressions would improve the time.&lt;br /&gt;
&lt;br /&gt;
*'''Know your gems'''&lt;br /&gt;
: All libraries are not efficient. Many gems may need to be removed to problem to fix a problem with the code. This is a common scenario when many gems are installed. So performing bench marking and testing a gem with others that perform same task would help in picking the right gem.&lt;br /&gt;
&lt;br /&gt;
*'''Improve your algorithms before you try to improve your code'''&lt;br /&gt;
: Algorithmic improvements results in evident improvements in performance of the code. It is always ideal to design an efficient algorithm without unwanted method calls.&lt;br /&gt;
&lt;br /&gt;
*'''Test the most frequently occurring case first'''&lt;br /&gt;
: While using if statements or a case statement always test the cases that occur most frequently. This allows less code to run before a decision is made.  It may not seem like much but over several hundred or thousand runs through the decision logic you’ll notice a definite performance gain.&lt;br /&gt;
&lt;br /&gt;
*'''Optimize the way you access global constants'''&lt;br /&gt;
: While accessing the global constants one should use namespace before the constants to avoid entire library search for the constant.&lt;br /&gt;
 &lt;br /&gt;
*'''Use explicit returns'''&lt;br /&gt;
: Even though the result of last operation is returned for a method, using explicit returns would speed up the code. Explicit returns are faster, especially in older Ruby versions such as 1.8.x.&lt;br /&gt;
&lt;br /&gt;
=== Documentation Guidelines&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/api_documentation_guidelines.html&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Documentation comments&amp;lt;ref&amp;gt;http://www.jetbrains.com/ruby/webhelp/documenting-source-code-in-rubymine.html&amp;lt;/ref&amp;gt; can be created in accordance with [http://rdoc.sourceforge.net/ RDoc] and [http://yardoc.org/ YARD] syntax. Note that RDoc highlighting in documentation comments can be turned enabled or disabled in the Appearance page of the editor settings.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The most common Documentation guidelines are listed below.&lt;br /&gt;
*Write simple, declarative sentences. Brevity is a plus: get to the point.&lt;br /&gt;
*Write in present tense: &amp;quot;Returns a hash that...&amp;quot;, rather than &amp;quot;Returned a hash that...&amp;quot; or &amp;quot;Will return a hash that...&amp;quot;.&lt;br /&gt;
*Start comments in upper case. Follow regular punctuation rules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Declares an attribute reader backed by an internally-named &lt;br /&gt;
# instance variable.&lt;br /&gt;
def attr_internal_reader(*attrs)&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Communicate to the reader the current way of doing things, both explicitly and implicitly. Use the idioms recommended in edge. Reorder sections to emphasize favored approaches if needed, etc. The documentation should be a model for best practices and canonical, modern Rails usage.&lt;br /&gt;
&lt;br /&gt;
Documentation has to be concise but comprehensive. Explore and document edge cases.&lt;br /&gt;
&lt;br /&gt;
=== Layout Guidelines&amp;lt;ref&amp;gt;http://www.caliban.org/ruby/rubyguide.shtml&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Designing the layout of any application determines the readability factor for other developers.&lt;br /&gt;
Most followed order of code is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
header block with author's name, Perforce Id tag and a brief description of what the program or library is for.&lt;br /&gt;
require statements&lt;br /&gt;
include statements&lt;br /&gt;
class and module definitions&lt;br /&gt;
main program section&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Spreading Code Out and Lining it Up'''&lt;br /&gt;
:This is very important for readability. Basically the principle is to:&lt;br /&gt;
:*separate each component part by white space.&lt;br /&gt;
:*align everything meaningfully.&lt;br /&gt;
:As such one can easily scan up and down the code and see the patterns. This is very important not only for understanding the code, but also for looking for anomalies and as a tool for rationalizing and consolidating the code.&lt;br /&gt;
:Code that has a lot of 'noise' - a lot of unnecessary variation and untidiness - is code that one can waste a lot of time working on. Well written and formatted code is code that is easy and quick to work with. It is code that allows one to easily 'see the wood from the trees'.&lt;br /&gt;
&lt;br /&gt;
== '''Code Analysis Tools''' ==&lt;br /&gt;
&lt;br /&gt;
Ruby itself goes a long way towards helping developers write clear code.&lt;br /&gt;
&lt;br /&gt;
*'''The Ruby debugger''' is a library loaded into Ruby at run-time. &lt;br /&gt;
This is done as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby -r debug [&lt;br /&gt;
            options&lt;br /&gt;
            ] [&lt;br /&gt;
            programfile&lt;br /&gt;
            ] [&lt;br /&gt;
            arguments&lt;br /&gt;
            ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debugger can do all the usual things one would expect it to, such as set breakpoints, step into and over code, print out the call stack, etc.&lt;br /&gt;
&lt;br /&gt;
While tools for the mainstream languages such as Java and C++ have reached a certain maturity, tools for Ruby are still growing. And they might be needed more and more as Ruby's usage spreads from early adopters to the early majority, and SLOC (Source Lines Of Code) continues to increase. Automatic tools&amp;lt;ref&amp;gt;https://www.ruby-toolbox.com/categories/code_metrics&amp;lt;/ref&amp;gt; can be used to detect several types of problems including inconsistent style, long methods and repeated code.&lt;br /&gt;
&lt;br /&gt;
*[http://www.ruby-toolbox.com/categories/code_metrics '''Roodi'''] (Ruby Object Oriented Design Inferometer) - this parses Ruby code and warns about design issues from the list  configured, ie: Class line count check, for loop check, parameter number check, cyclomatic checks and 10 other checks&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Reek'''] - similar in concept to Roodi&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Saikuro'''] - designed to check cyclomatic complexity&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Flog'''] - created by Ryan Davis, this computes a score of code written: the higher the score is, the worse your code is. ABC metrics (Assignments, Branches and Calls) are taken into account to compute the score&lt;br /&gt;
*[http://www.harukizaemon.com/simian/ '''Simian'''] - a similarity analyzer, this can be used for duplication identification (a $99 license is needed for commercial use)&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Flay'''] - this is another free tool from Ryan Davis that finds structural similarities in code&lt;br /&gt;
&lt;br /&gt;
[[File:Code Analysis Outputs.png|frame|none|alt=Code Analysis Tool Results|Code Analysis Tool Results]]&lt;br /&gt;
&lt;br /&gt;
== '''Summary''' ==&lt;br /&gt;
Ruby developers should follow a certain criteria or guidelines during software development. Coding standards are set of rules, guidelines and regulations on the manner of writing a code that helps programmers and developers read and understand quickly the source code that conforms to style and help avoid introducing misunderstanding and faults.&lt;br /&gt;
&lt;br /&gt;
Particularly in Ruby development, coding standards are extremely important; therefore Ruby developers should put an importance to them. This is because these standards offer higher uniformity and consistency when writing code by different programmers. This could result in a code that's simple to know and preserve, thus reducing the project’s overall expenses.&lt;br /&gt;
&lt;br /&gt;
Some of the benefits of using coding standards are:&lt;br /&gt;
&lt;br /&gt;
*Easy to understand and maintained&lt;br /&gt;
*Boost the code’s readability&lt;br /&gt;
*Maintainable applications&lt;br /&gt;
*Eradicates complexity&lt;br /&gt;
*Separate documents look more appropriate&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://www.caliban.org/ruby/rubyguide.shtml&lt;br /&gt;
*http://github.com/styleguide/ruby&lt;br /&gt;
*http://www.ruby-doc.org/docs/ProgrammingRuby/&lt;br /&gt;
*http://www.ruby-lang.org/en/documentation/&lt;br /&gt;
*http://en.wikibooks.org/wiki/Ruby_programming_language&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78795</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w23 ph</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78795"/>
		<updated>2013-09-24T20:11:36Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* Code Analysis Tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby Coding Guidelines''' ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] Coding Guidelines include best practices followed generally for most of the [http://en.wikipedia.org/wiki/Category:Object-oriented_programming_languages object oriented programming languages] as Ruby is entirely 'Object Oriented'. Also known as 'Ruby Coding conventions', these are a set of guidelines that recommend programming style, practices and methods for each aspect of a piece of program written in Ruby. &lt;br /&gt;
&lt;br /&gt;
Software programmers are highly recommended to follow these guidelines to help improve the readability of their source code and make software maintenance easier. Naming conventions, class and member design principles, maintainability, performance, documentation and layout are the important areas where these guidelines have to be followed. More important than the reasons for having a guideline is actually adhering to it consistently.  Having a coding guideline documented and available means nothing if developers are not using it consistently.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Types of Guidelines''' ==&lt;br /&gt;
Coding guidelines in Ruby can be defined individually for major sections that code consists of. Naming , Class Design , Member Design , Maintainability, Performance, Documentation and Layout guidelines are illustrated below. These guidelines contain sections common to all of these as well as sections which apply to each one individually.&lt;br /&gt;
&lt;br /&gt;
=== Naming Guidelines&amp;lt;ref&amp;gt;http://itsignals.cascadia.com.au/?p=7&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Ruby uses the first character of the name to help it determine it’s intended use.&lt;br /&gt;
The standard Ruby file extension is .rb, although many people working on [http://en.wikipedia.org/wiki/Unix UNIX]-like systems don't bother with it for stand-alone scripts. Whether or not one uses it for scripts is up to them, but they will need to use it for library files or they will not be found by the interpreter.&lt;br /&gt;
&lt;br /&gt;
*'''Local Variables'''&lt;br /&gt;
:Should use lowercase letter followed by other characters. Naming convention states that it is better to use underscores rather than [http://en.wikipedia.org/wiki/CamelCase camelBack] for multiple word names, e.g. average, variable_xyz&lt;br /&gt;
*'''Instance Variables'''&lt;br /&gt;
:Instance variables are defined using the single &amp;quot;at&amp;quot; sign (@) followed by a name. It is suggested that a lowercase letter should succeed @, e.g. @color &lt;br /&gt;
*'''Instance Methods'''&lt;br /&gt;
:Method names should start with a lowercase letter, and may be followed by digits, underscores, and letters. The name should possibly be a verb e.g. move, display_details&lt;br /&gt;
*'''Class Variables'''&lt;br /&gt;
:Class variable names start with a double &amp;quot;at&amp;quot; sign (@@) and may be followed by digits, underscores, and letters, e.g. @@color&lt;br /&gt;
*'''Constant''' &lt;br /&gt;
:Constant names usually start with an uppercase letter followed by other characters. Constant objects are by convention named using all uppercase letters and underscores between words, e.g. THIS_IS_A_CONSTANT&lt;br /&gt;
*'''Class and Module''' &lt;br /&gt;
:Class names are recommended to be be nouns. In the case of modules, it's harder to make a clear recommendation. The names of [http://en.wikipedia.org/wiki/Mixin mix-ins] (which are just modules), however,  should probably be adjectives, such as the standard [http://en.wikibooks.org/wiki/Ruby_Programming/Reference/Objects/Enumerable Enumerable] and [http://www.ruby-doc.org/core-2.0.0/Comparable.html Comparable] modules. Class and module names starts with an uppercase letter, by convention they are named using MixedCase, e.g. module Encryption, class MixedCase&lt;br /&gt;
*'''Global Variables'''&lt;br /&gt;
:Starts with a dollar ($) sign followed by other characters, e.g. $global&lt;br /&gt;
&lt;br /&gt;
Considering customer order information as the data being used for an application, below naming guidelines give an idea of good class/table/file names.&lt;br /&gt;
*'''Model Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Table: orders&lt;br /&gt;
Class: Order&lt;br /&gt;
File: /app/models/order.rb&lt;br /&gt;
Primary Key: id&lt;br /&gt;
Foreign Key: customer_id&lt;br /&gt;
Link Tables: items_orders&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Controller Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class: OrdersController&lt;br /&gt;
File: /app/controllers/orders_controller.rb&lt;br /&gt;
Layout: /app/layouts/orders.html.erb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''View Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Helper: /app/helpers/orders_helper.rb&lt;br /&gt;
Helper Module: OrdersHelper&lt;br /&gt;
Views: /app/views/orders/… (list.html.erb for example)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Tests Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Unit: /test/unit/order_test.rb&lt;br /&gt;
Functional: /test/functional/orders_controller_test.rb&lt;br /&gt;
Fixtures: /test/fixtures/orders.yml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Class Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A class in Ruby always starts with the keyword class followed by the name of the class. The name should always be in initial capitals. Class Customer can be displayed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Customer&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A class is terminated by using the keyword end. All the data members in the class are between the class definition and the end keyword. &lt;br /&gt;
&lt;br /&gt;
Ruby blurs the distinction between design and implementation. Ideas that have to be expressed at the design level in other languages can be implemented directly in Ruby. To help in this process, Ruby has support for some design-level strategies. These strategies can be used to design classes accordingly as suitable for different types of  applications.&lt;br /&gt;
&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Visitor_pattern The Visitor pattern]''' is a way of traversing a collection without having to know the internal organization of that collection.&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Delegation_pattern Delegation]''' is a way of composing classes more flexibly and dynamically than can be done using standard inheritance.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Singleton_pattern Singleton pattern]''' is a way of ensuring that only one instantiation of a particular class exists at a time.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Observer_pattern Observer pattern]''' implements a protocol allowing one object to notify a set of interested objects when certain changes have occurred.&lt;br /&gt;
&lt;br /&gt;
Normally, all four of these strategies require explicit code each time they're implemented. With Ruby, they can be abstracted into a library and reused freely and transparently.&lt;br /&gt;
&lt;br /&gt;
=== Member Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
While defining class members, it is very important to keep in mind the access restrictions. Scope and life-time of class members are different for different restrictions, as illustrated below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public&lt;br /&gt;
totally accessible.&lt;br /&gt;
protected&lt;br /&gt;
accessible only by instances of class and direct descendants. Even through hasA relationships. (see below)&lt;br /&gt;
private&lt;br /&gt;
accessible only by instances of class (must be called nekkid no “self.” or anything else).&lt;br /&gt;
class A&lt;br /&gt;
  # Restriction used w/o arguments set the default access control.&lt;br /&gt;
  protected&lt;br /&gt;
&lt;br /&gt;
  def protected_method&lt;br /&gt;
    # nothing&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class B &amp;lt; A&lt;br /&gt;
  def test_protected&lt;br /&gt;
    myA = A.new&lt;br /&gt;
    myA.protected_method&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Used with arguments, sets the access of the named methods and constants.&lt;br /&gt;
  public :test_protected&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
b = B.new.test_protected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Maintainability Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
Maintainability guidelines are important to programmers for a number of reasons:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
*40%-80% of the lifetime cost of a piece of software goes to maintenance.&lt;br /&gt;
*Hardly any software is maintained for its whole life by the original author. &lt;br /&gt;
*Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. &lt;br /&gt;
*If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
The following guidelines are to be followed to improve the software maintainability&lt;br /&gt;
* '''Profile your code regularly'''&lt;br /&gt;
: If you profile your code regularly you’ll be able to tell if the latest change to the code will have an adverse effect on performance.  Integrate profiling into your testing process and make it automated to ensure that it’s not forgotten.  Like unit testing and BDD([http://en.wikipedia.org/wiki/Behavior-driven_development Behavior-driven development]) profiling goes a long way.&lt;br /&gt;
&lt;br /&gt;
=== Performance Guidelines&amp;lt;ref&amp;gt;http://blog.monitis.com/index.php/2012/02/08/20-ruby-performance-tips/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
The key parameter on which a software application is rated is by its performance. It is the time taken by the application to respond to a user's request. Performance of ruby can be improved significantly by following certain coding guidelines, as below.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid nesting loops more than three levels deep'''&lt;br /&gt;
: Nesting affects the performance of the code proportionally with the increasing levels in loops. Limiting nesting to three levels is one good practice to keep the code's performance well.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary variable assignments'''&lt;br /&gt;
: New programmers, often use unwanted variables in code.  A great example is when someone defines a variable to store a return value and then returns that variable; just return the value directly.&lt;br /&gt;
&lt;br /&gt;
*'''Reduce usage of disk I/O'''&lt;br /&gt;
: Disk I/O is a very costly operation as far as computing is concerned. Keeping it to the minimal improves the application response time drastically. Using disk I/O, makes the application extremely slow. Using storage systems such as memcached reduces disk I/O operations to a great extent as lot of data is kept in memory. The speed improvement while using a memory caching system is tremendous.&lt;br /&gt;
&lt;br /&gt;
*'''Use Ruby Enterprise Edition'''&lt;br /&gt;
: Ruby Enterprise edition provides up to [http://www.rubyenterpriseedition.com/faq.html#thirty_three_percent_mem_reduction 33% lower memory] usage.  Though, to get benefited by this performance one needs to follow their guidelines.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid method calls as much as possible'''&lt;br /&gt;
: Method calls are expensive operations in ruby. They should be avoided to keep up the performance of the application.&lt;br /&gt;
&lt;br /&gt;
*'''Use interpolated strings instead of concatenated strings'''&lt;br /&gt;
: Concatenated strings calls a method to get executed. So, it affects the performance as it is one of the most frequently used operation. Its better to replace them with Interpolated strings which runs faster as it doesn't invoke a method call.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
put “Hello there, #{name}!”vs.puts “Hello there, ” &amp;lt;&amp;lt; name = “!”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Destructive operations are faster'''&lt;br /&gt;
: Ruby’s in-place methods that which modifies the actual value than working on a copy of the data are much faster. But this should be handled carefully as original data gets disturbed.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary calls to uniq on arrays'''&lt;br /&gt;
: In many cases methods are already calling uniq on an array and there’s no need for you to call it yet again.&lt;br /&gt;
&lt;br /&gt;
*'''For loops are faster than .each'''&lt;br /&gt;
: .each uses an enumeration object behind the scene which adds a delay in execution. Using for instead of .each would improve performance but for short loops only.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/6406112/why-are-ruby-method-calls-particularly-slow-in-comparison-to-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Use x.blank? over x.nil? || x.empty?'''&lt;br /&gt;
: When using ActionPack there’s no need for x.nil? or x.empty?; x.blank? checks for both of these.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid calls to parse_date and strftime'''&lt;br /&gt;
: Both these calls are very expensive. using regular expressions would improve the time.&lt;br /&gt;
&lt;br /&gt;
*'''Know your gems'''&lt;br /&gt;
: All libraries are not efficient. Many gems may need to be removed to problem to fix a problem with the code. This is a common scenario when many gems are installed. So performing bench marking and testing a gem with others that perform same task would help in picking the right gem.&lt;br /&gt;
&lt;br /&gt;
*'''Improve your algorithms before you try to improve your code'''&lt;br /&gt;
: Algorithmic improvements results in evident improvements in performance of the code. It is always ideal to design an efficient algorithm without unwanted method calls.&lt;br /&gt;
&lt;br /&gt;
*'''Test the most frequently occurring case first'''&lt;br /&gt;
: While using if statements or a case statement always test the cases that occur most frequently. This allows less code to run before a decision is made.  It may not seem like much but over several hundred or thousand runs through the decision logic you’ll notice a definite performance gain.&lt;br /&gt;
&lt;br /&gt;
*'''Optimize the way you access global constants'''&lt;br /&gt;
: While accessing the global constants one should use namespace before the constants to avoid entire library search for the constant.&lt;br /&gt;
 &lt;br /&gt;
*'''Use explicit returns'''&lt;br /&gt;
: Even though the result of last operation is returned for a method, using explicit returns would speed up the code. Explicit returns are faster, especially in older Ruby versions such as 1.8.x.&lt;br /&gt;
&lt;br /&gt;
=== Documentation Guidelines&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/api_documentation_guidelines.html&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Documentation comments&amp;lt;ref&amp;gt;http://www.jetbrains.com/ruby/webhelp/documenting-source-code-in-rubymine.html&amp;lt;/ref&amp;gt; can be created in accordance with [http://rdoc.sourceforge.net/ RDoc] and [http://yardoc.org/ YARD] syntax. Note that RDoc highlighting in documentation comments can be turned enabled or disabled in the Appearance page of the editor settings.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The most common Documentation guidelines are listed below.&lt;br /&gt;
*Write simple, declarative sentences. Brevity is a plus: get to the point.&lt;br /&gt;
*Write in present tense: &amp;quot;Returns a hash that...&amp;quot;, rather than &amp;quot;Returned a hash that...&amp;quot; or &amp;quot;Will return a hash that...&amp;quot;.&lt;br /&gt;
*Start comments in upper case. Follow regular punctuation rules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Declares an attribute reader backed by an internally-named &lt;br /&gt;
# instance variable.&lt;br /&gt;
def attr_internal_reader(*attrs)&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Communicate to the reader the current way of doing things, both explicitly and implicitly. Use the idioms recommended in edge. Reorder sections to emphasize favored approaches if needed, etc. The documentation should be a model for best practices and canonical, modern Rails usage.&lt;br /&gt;
&lt;br /&gt;
Documentation has to be concise but comprehensive. Explore and document edge cases.&lt;br /&gt;
&lt;br /&gt;
=== Layout Guidelines&amp;lt;ref&amp;gt;http://www.caliban.org/ruby/rubyguide.shtml&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Designing the layout of any application determines the readability factor for other developers.&lt;br /&gt;
Most followed order of code is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
header block with author's name, Perforce Id tag and a brief description of what the program or library is for.&lt;br /&gt;
require statements&lt;br /&gt;
include statements&lt;br /&gt;
class and module definitions&lt;br /&gt;
main program section&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Spreading Code Out and Lining it Up'''&lt;br /&gt;
:This is very important for readability. Basically the principle is to:&lt;br /&gt;
:*separate each component part by white space.&lt;br /&gt;
:*align everything meaningfully.&lt;br /&gt;
:As such one can easily scan up and down the code and see the patterns. This is very important not only for understanding the code, but also for looking for anomalies and as a tool for rationalizing and consolidating the code.&lt;br /&gt;
:Code that has a lot of 'noise' - a lot of unnecessary variation and untidiness - is code that one can waste a lot of time working on. Well written and formatted code is code that is easy and quick to work with. It is code that allows one to easily 'see the wood from the trees'.&lt;br /&gt;
&lt;br /&gt;
== '''Code Analysis Tools''' ==&lt;br /&gt;
&lt;br /&gt;
Ruby itself goes a long way towards helping developers write clear code.&lt;br /&gt;
&lt;br /&gt;
*'''The Ruby debugger''' is a library loaded into Ruby at run-time. &lt;br /&gt;
This is done as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby -r debug [&lt;br /&gt;
            options&lt;br /&gt;
            ] [&lt;br /&gt;
            programfile&lt;br /&gt;
            ] [&lt;br /&gt;
            arguments&lt;br /&gt;
            ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debugger can do all the usual things one would expect it to, such as set breakpoints, step into and over code, print out the call stack, etc.&lt;br /&gt;
&lt;br /&gt;
While tools for the mainstream languages such as Java and C++ have reached a certain maturity, tools for Ruby are still growing. And they might be needed more and more as Ruby's usage spreads from early adopters to the early majority, and SLOC (Source Lines Of Code) continues to increase. Automatic tools&amp;lt;ref&amp;gt;https://www.ruby-toolbox.com/categories/code_metrics&amp;lt;/ref&amp;gt; can be used to detect several types of problems including inconsistent style, long methods and repeated code.&lt;br /&gt;
&lt;br /&gt;
*[http://www.ruby-toolbox.com/categories/code_metrics '''Roodi'''] (Ruby Object Oriented Design Inferometer) - this parses Ruby code and warns about design issues from the list  configured, ie: Class line count check, for loop check, parameter number check, cyclomatic checks and 10 other checks&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Reek'''] - similar in concept to Roodi&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Saikuro'''] - designed to check cyclomatic complexity&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Flog'''] - created by Ryan Davis, this computes a score of code written: the higher the score is, the worse your code is. ABC metrics (Assignments, Branches and Calls) are taken into account to compute the score&lt;br /&gt;
*[http://www.harukizaemon.com/simian/ '''Simian'''] - a similarity analyzer, this can be used for duplication identification (a $99 license is needed for commercial use)&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Flay'''] - this is another free tool from Ryan Davis that finds structural similarities in code&lt;br /&gt;
&lt;br /&gt;
[[File:Code Analysis Outputs.png|frame|none|alt=Code Analysis Tool Results|Code Analysis Tool Results]]&lt;br /&gt;
&lt;br /&gt;
== '''Summary''' ==&lt;br /&gt;
Ruby developers should follow a certain criteria or guidelines during software development. Coding standards are set of rules, guidelines and regulations on the manner of writing a code that helps programmers and developers read and understand quickly the source code that conforms to style and help avoid introducing misunderstanding and faults.&lt;br /&gt;
&lt;br /&gt;
Particularly in Ruby development, coding standards are extremely important; therefore Ruby developers should put an importance to them. This is because these standards offer higher uniformity and consistency when writing code by different programmers. This could result in a code that's simple to know and preserve, thus reducing the project’s overall expenses.&lt;br /&gt;
&lt;br /&gt;
Some of the benefits of using coding standards are:&lt;br /&gt;
&lt;br /&gt;
*Easy to understand and maintained&lt;br /&gt;
*Boost the code’s readability&lt;br /&gt;
*Maintainable applications&lt;br /&gt;
*Eradicates complexity&lt;br /&gt;
*Separate documents look more appropriate&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://www.caliban.org/ruby/rubyguide.shtml&lt;br /&gt;
*https://github.com/styleguide/ruby&lt;br /&gt;
*http://www.ruby-doc.org/docs/ProgrammingRuby/&lt;br /&gt;
*https://www.ruby-lang.org/en/documentation/&lt;br /&gt;
*http://en.wikibooks.org/wiki/Ruby_programming_language&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78789</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w23 ph</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78789"/>
		<updated>2013-09-24T20:09:35Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: Undo revision 78480 by Pyadla (talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby Coding Guidelines''' ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] Coding Guidelines include best practices followed generally for most of the [http://en.wikipedia.org/wiki/Category:Object-oriented_programming_languages object oriented programming languages] as Ruby is entirely 'Object Oriented'. Also known as 'Ruby Coding conventions', these are a set of guidelines that recommend programming style, practices and methods for each aspect of a piece of program written in Ruby. &lt;br /&gt;
&lt;br /&gt;
Software programmers are highly recommended to follow these guidelines to help improve the readability of their source code and make software maintenance easier. Naming conventions, class and member design principles, maintainability, performance, documentation and layout are the important areas where these guidelines have to be followed. More important than the reasons for having a guideline is actually adhering to it consistently.  Having a coding guideline documented and available means nothing if developers are not using it consistently.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Types of Guidelines''' ==&lt;br /&gt;
Coding guidelines in Ruby can be defined individually for major sections that code consists of. Naming , Class Design , Member Design , Maintainability, Performance, Documentation and Layout guidelines are illustrated below. These guidelines contain sections common to all of these as well as sections which apply to each one individually.&lt;br /&gt;
&lt;br /&gt;
=== Naming Guidelines&amp;lt;ref&amp;gt;http://itsignals.cascadia.com.au/?p=7&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Ruby uses the first character of the name to help it determine it’s intended use.&lt;br /&gt;
The standard Ruby file extension is .rb, although many people working on [http://en.wikipedia.org/wiki/Unix UNIX]-like systems don't bother with it for stand-alone scripts. Whether or not one uses it for scripts is up to them, but they will need to use it for library files or they will not be found by the interpreter.&lt;br /&gt;
&lt;br /&gt;
*'''Local Variables'''&lt;br /&gt;
:Should use lowercase letter followed by other characters. Naming convention states that it is better to use underscores rather than [http://en.wikipedia.org/wiki/CamelCase camelBack] for multiple word names, e.g. average, variable_xyz&lt;br /&gt;
*'''Instance Variables'''&lt;br /&gt;
:Instance variables are defined using the single &amp;quot;at&amp;quot; sign (@) followed by a name. It is suggested that a lowercase letter should succeed @, e.g. @color &lt;br /&gt;
*'''Instance Methods'''&lt;br /&gt;
:Method names should start with a lowercase letter, and may be followed by digits, underscores, and letters. The name should possibly be a verb e.g. move, display_details&lt;br /&gt;
*'''Class Variables'''&lt;br /&gt;
:Class variable names start with a double &amp;quot;at&amp;quot; sign (@@) and may be followed by digits, underscores, and letters, e.g. @@color&lt;br /&gt;
*'''Constant''' &lt;br /&gt;
:Constant names usually start with an uppercase letter followed by other characters. Constant objects are by convention named using all uppercase letters and underscores between words, e.g. THIS_IS_A_CONSTANT&lt;br /&gt;
*'''Class and Module''' &lt;br /&gt;
:Class names are recommended to be be nouns. In the case of modules, it's harder to make a clear recommendation. The names of [http://en.wikipedia.org/wiki/Mixin mix-ins] (which are just modules), however,  should probably be adjectives, such as the standard [http://en.wikibooks.org/wiki/Ruby_Programming/Reference/Objects/Enumerable Enumerable] and [http://www.ruby-doc.org/core-2.0.0/Comparable.html Comparable] modules. Class and module names starts with an uppercase letter, by convention they are named using MixedCase, e.g. module Encryption, class MixedCase&lt;br /&gt;
*'''Global Variables'''&lt;br /&gt;
:Starts with a dollar ($) sign followed by other characters, e.g. $global&lt;br /&gt;
&lt;br /&gt;
Considering customer order information as the data being used for an application, below naming guidelines give an idea of good class/table/file names.&lt;br /&gt;
*'''Model Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Table: orders&lt;br /&gt;
Class: Order&lt;br /&gt;
File: /app/models/order.rb&lt;br /&gt;
Primary Key: id&lt;br /&gt;
Foreign Key: customer_id&lt;br /&gt;
Link Tables: items_orders&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Controller Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class: OrdersController&lt;br /&gt;
File: /app/controllers/orders_controller.rb&lt;br /&gt;
Layout: /app/layouts/orders.html.erb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''View Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Helper: /app/helpers/orders_helper.rb&lt;br /&gt;
Helper Module: OrdersHelper&lt;br /&gt;
Views: /app/views/orders/… (list.html.erb for example)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Tests Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Unit: /test/unit/order_test.rb&lt;br /&gt;
Functional: /test/functional/orders_controller_test.rb&lt;br /&gt;
Fixtures: /test/fixtures/orders.yml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Class Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A class in Ruby always starts with the keyword class followed by the name of the class. The name should always be in initial capitals. Class Customer can be displayed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Customer&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A class is terminated by using the keyword end. All the data members in the class are between the class definition and the end keyword. &lt;br /&gt;
&lt;br /&gt;
Ruby blurs the distinction between design and implementation. Ideas that have to be expressed at the design level in other languages can be implemented directly in Ruby. To help in this process, Ruby has support for some design-level strategies. These strategies can be used to design classes accordingly as suitable for different types of  applications.&lt;br /&gt;
&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Visitor_pattern The Visitor pattern]''' is a way of traversing a collection without having to know the internal organization of that collection.&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Delegation_pattern Delegation]''' is a way of composing classes more flexibly and dynamically than can be done using standard inheritance.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Singleton_pattern Singleton pattern]''' is a way of ensuring that only one instantiation of a particular class exists at a time.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Observer_pattern Observer pattern]''' implements a protocol allowing one object to notify a set of interested objects when certain changes have occurred.&lt;br /&gt;
&lt;br /&gt;
Normally, all four of these strategies require explicit code each time they're implemented. With Ruby, they can be abstracted into a library and reused freely and transparently.&lt;br /&gt;
&lt;br /&gt;
=== Member Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
While defining class members, it is very important to keep in mind the access restrictions. Scope and life-time of class members are different for different restrictions, as illustrated below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public&lt;br /&gt;
totally accessible.&lt;br /&gt;
protected&lt;br /&gt;
accessible only by instances of class and direct descendants. Even through hasA relationships. (see below)&lt;br /&gt;
private&lt;br /&gt;
accessible only by instances of class (must be called nekkid no “self.” or anything else).&lt;br /&gt;
class A&lt;br /&gt;
  # Restriction used w/o arguments set the default access control.&lt;br /&gt;
  protected&lt;br /&gt;
&lt;br /&gt;
  def protected_method&lt;br /&gt;
    # nothing&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class B &amp;lt; A&lt;br /&gt;
  def test_protected&lt;br /&gt;
    myA = A.new&lt;br /&gt;
    myA.protected_method&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Used with arguments, sets the access of the named methods and constants.&lt;br /&gt;
  public :test_protected&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
b = B.new.test_protected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Maintainability Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
Maintainability guidelines are important to programmers for a number of reasons:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
*40%-80% of the lifetime cost of a piece of software goes to maintenance.&lt;br /&gt;
*Hardly any software is maintained for its whole life by the original author. &lt;br /&gt;
*Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. &lt;br /&gt;
*If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
The following guidelines are to be followed to improve the software maintainability&lt;br /&gt;
* '''Profile your code regularly'''&lt;br /&gt;
: If you profile your code regularly you’ll be able to tell if the latest change to the code will have an adverse effect on performance.  Integrate profiling into your testing process and make it automated to ensure that it’s not forgotten.  Like unit testing and BDD([http://en.wikipedia.org/wiki/Behavior-driven_development Behavior-driven development]) profiling goes a long way.&lt;br /&gt;
&lt;br /&gt;
=== Performance Guidelines&amp;lt;ref&amp;gt;http://blog.monitis.com/index.php/2012/02/08/20-ruby-performance-tips/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
The key parameter on which a software application is rated is by its performance. It is the time taken by the application to respond to a user's request. Performance of ruby can be improved significantly by following certain coding guidelines, as below.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid nesting loops more than three levels deep'''&lt;br /&gt;
: Nesting affects the performance of the code proportionally with the increasing levels in loops. Limiting nesting to three levels is one good practice to keep the code's performance well.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary variable assignments'''&lt;br /&gt;
: New programmers, often use unwanted variables in code.  A great example is when someone defines a variable to store a return value and then returns that variable; just return the value directly.&lt;br /&gt;
&lt;br /&gt;
*'''Reduce usage of disk I/O'''&lt;br /&gt;
: Disk I/O is a very costly operation as far as computing is concerned. Keeping it to the minimal improves the application response time drastically. Using disk I/O, makes the application extremely slow. Using storage systems such as memcached reduces disk I/O operations to a great extent as lot of data is kept in memory. The speed improvement while using a memory caching system is tremendous.&lt;br /&gt;
&lt;br /&gt;
*'''Use Ruby Enterprise Edition'''&lt;br /&gt;
: Ruby Enterprise edition provides up to [http://www.rubyenterpriseedition.com/faq.html#thirty_three_percent_mem_reduction 33% lower memory] usage.  Though, to get benefited by this performance one needs to follow their guidelines.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid method calls as much as possible'''&lt;br /&gt;
: Method calls are expensive operations in ruby. They should be avoided to keep up the performance of the application.&lt;br /&gt;
&lt;br /&gt;
*'''Use interpolated strings instead of concatenated strings'''&lt;br /&gt;
: Concatenated strings calls a method to get executed. So, it affects the performance as it is one of the most frequently used operation. Its better to replace them with Interpolated strings which runs faster as it doesn't invoke a method call.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
put “Hello there, #{name}!”vs.puts “Hello there, ” &amp;lt;&amp;lt; name = “!”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Destructive operations are faster'''&lt;br /&gt;
: Ruby’s in-place methods that which modifies the actual value than working on a copy of the data are much faster. But this should be handled carefully as original data gets disturbed.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary calls to uniq on arrays'''&lt;br /&gt;
: In many cases methods are already calling uniq on an array and there’s no need for you to call it yet again.&lt;br /&gt;
&lt;br /&gt;
*'''For loops are faster than .each'''&lt;br /&gt;
: .each uses an enumeration object behind the scene which adds a delay in execution. Using for instead of .each would improve performance but for short loops only.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/6406112/why-are-ruby-method-calls-particularly-slow-in-comparison-to-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Use x.blank? over x.nil? || x.empty?'''&lt;br /&gt;
: When using ActionPack there’s no need for x.nil? or x.empty?; x.blank? checks for both of these.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid calls to parse_date and strftime'''&lt;br /&gt;
: Both these calls are very expensive. using regular expressions would improve the time.&lt;br /&gt;
&lt;br /&gt;
*'''Know your gems'''&lt;br /&gt;
: All libraries are not efficient. Many gems may need to be removed to problem to fix a problem with the code. This is a common scenario when many gems are installed. So performing bench marking and testing a gem with others that perform same task would help in picking the right gem.&lt;br /&gt;
&lt;br /&gt;
*'''Improve your algorithms before you try to improve your code'''&lt;br /&gt;
: Algorithmic improvements results in evident improvements in performance of the code. It is always ideal to design an efficient algorithm without unwanted method calls.&lt;br /&gt;
&lt;br /&gt;
*'''Test the most frequently occurring case first'''&lt;br /&gt;
: While using if statements or a case statement always test the cases that occur most frequently. This allows less code to run before a decision is made.  It may not seem like much but over several hundred or thousand runs through the decision logic you’ll notice a definite performance gain.&lt;br /&gt;
&lt;br /&gt;
*'''Optimize the way you access global constants'''&lt;br /&gt;
: While accessing the global constants one should use namespace before the constants to avoid entire library search for the constant.&lt;br /&gt;
 &lt;br /&gt;
*'''Use explicit returns'''&lt;br /&gt;
: Even though the result of last operation is returned for a method, using explicit returns would speed up the code. Explicit returns are faster, especially in older Ruby versions such as 1.8.x.&lt;br /&gt;
&lt;br /&gt;
=== Documentation Guidelines&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/api_documentation_guidelines.html&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Documentation comments&amp;lt;ref&amp;gt;http://www.jetbrains.com/ruby/webhelp/documenting-source-code-in-rubymine.html&amp;lt;/ref&amp;gt; can be created in accordance with [http://rdoc.sourceforge.net/ RDoc] and [http://yardoc.org/ YARD] syntax. Note that RDoc highlighting in documentation comments can be turned enabled or disabled in the Appearance page of the editor settings.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The most common Documentation guidelines are listed below.&lt;br /&gt;
*Write simple, declarative sentences. Brevity is a plus: get to the point.&lt;br /&gt;
*Write in present tense: &amp;quot;Returns a hash that...&amp;quot;, rather than &amp;quot;Returned a hash that...&amp;quot; or &amp;quot;Will return a hash that...&amp;quot;.&lt;br /&gt;
*Start comments in upper case. Follow regular punctuation rules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Declares an attribute reader backed by an internally-named &lt;br /&gt;
# instance variable.&lt;br /&gt;
def attr_internal_reader(*attrs)&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Communicate to the reader the current way of doing things, both explicitly and implicitly. Use the idioms recommended in edge. Reorder sections to emphasize favored approaches if needed, etc. The documentation should be a model for best practices and canonical, modern Rails usage.&lt;br /&gt;
&lt;br /&gt;
Documentation has to be concise but comprehensive. Explore and document edge cases.&lt;br /&gt;
&lt;br /&gt;
=== Layout Guidelines&amp;lt;ref&amp;gt;http://www.caliban.org/ruby/rubyguide.shtml&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Designing the layout of any application determines the readability factor for other developers.&lt;br /&gt;
Most followed order of code is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
header block with author's name, Perforce Id tag and a brief description of what the program or library is for.&lt;br /&gt;
require statements&lt;br /&gt;
include statements&lt;br /&gt;
class and module definitions&lt;br /&gt;
main program section&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Spreading Code Out and Lining it Up'''&lt;br /&gt;
:This is very important for readability. Basically the principle is to:&lt;br /&gt;
:*separate each component part by white space.&lt;br /&gt;
:*align everything meaningfully.&lt;br /&gt;
:As such one can easily scan up and down the code and see the patterns. This is very important not only for understanding the code, but also for looking for anomalies and as a tool for rationalizing and consolidating the code.&lt;br /&gt;
:Code that has a lot of 'noise' - a lot of unnecessary variation and untidiness - is code that one can waste a lot of time working on. Well written and formatted code is code that is easy and quick to work with. It is code that allows one to easily 'see the wood from the trees'.&lt;br /&gt;
&lt;br /&gt;
== '''Code Analysis Tools''' ==&lt;br /&gt;
&lt;br /&gt;
Ruby itself goes a long way towards helping developers write clear code.&lt;br /&gt;
&lt;br /&gt;
*'''The Ruby debugger''' is a library loaded into Ruby at run-time. &lt;br /&gt;
This is done as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby -r debug [&lt;br /&gt;
            options&lt;br /&gt;
            ] [&lt;br /&gt;
            programfile&lt;br /&gt;
            ] [&lt;br /&gt;
            arguments&lt;br /&gt;
            ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debugger can do all the usual things one would expect it to, such as set breakpoints, step into and over code, print out the call stack, etc.&lt;br /&gt;
&lt;br /&gt;
While tools for the mainstream languages such as Java and C++ have reached a certain maturity, tools for Ruby are still growing. And they might be needed more and more as Ruby's usage spreads from early adopters to the early majority, and SLOC (Source Lines Of Code) continues to increase. Automatic tools&amp;lt;ref&amp;gt;https://www.ruby-toolbox.com/categories/code_metrics&amp;lt;/ref&amp;gt; can be used to detect several types of problems including inconsistent style, long methods and repeated code.&lt;br /&gt;
&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Roodi'''] (Ruby Object Oriented Design Inferometer) - this parses Ruby code and warns about design issues from the list  configured, ie: Class line count check, for loop check, parameter number check, cyclomatic checks and 10 other checks&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Reek'''] - similar in concept to Roodi&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Saikuro'''] - designed to check cyclomatic complexity&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Flog'''] - created by Ryan Davis, this computes a score of code written: the higher the score is, the worse your code is. ABC metrics (Assignments, Branches and Calls) are taken into account to compute the score&lt;br /&gt;
*[http://www.harukizaemon.com/simian/ '''Simian'''] - a similarity analyzer, this can be used for duplication identification (a $99 license is needed for commercial use)&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Flay'''] - this is another free tool from Ryan Davis that finds structural similarities in code&lt;br /&gt;
&lt;br /&gt;
[[File:Code Analysis Outputs.png|frame|none|alt=Code Analysis Tool Results|Code Analysis Tool Results]]&lt;br /&gt;
&lt;br /&gt;
== '''Summary''' ==&lt;br /&gt;
Ruby developers should follow a certain criteria or guidelines during software development. Coding standards are set of rules, guidelines and regulations on the manner of writing a code that helps programmers and developers read and understand quickly the source code that conforms to style and help avoid introducing misunderstanding and faults.&lt;br /&gt;
&lt;br /&gt;
Particularly in Ruby development, coding standards are extremely important; therefore Ruby developers should put an importance to them. This is because these standards offer higher uniformity and consistency when writing code by different programmers. This could result in a code that's simple to know and preserve, thus reducing the project’s overall expenses.&lt;br /&gt;
&lt;br /&gt;
Some of the benefits of using coding standards are:&lt;br /&gt;
&lt;br /&gt;
*Easy to understand and maintained&lt;br /&gt;
*Boost the code’s readability&lt;br /&gt;
*Maintainable applications&lt;br /&gt;
*Eradicates complexity&lt;br /&gt;
*Separate documents look more appropriate&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://www.caliban.org/ruby/rubyguide.shtml&lt;br /&gt;
*https://github.com/styleguide/ruby&lt;br /&gt;
*http://www.ruby-doc.org/docs/ProgrammingRuby/&lt;br /&gt;
*https://www.ruby-lang.org/en/documentation/&lt;br /&gt;
*http://en.wikibooks.org/wiki/Ruby_programming_language&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78480</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w23 ph</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78480"/>
		<updated>2013-09-23T21:23:35Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* Code Analysis Tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby Coding Guidelines''' ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] Coding Guidelines include best practices followed generally for most of the [http://en.wikipedia.org/wiki/Category:Object-oriented_programming_languages object oriented programming languages] as Ruby is entirely 'Object Oriented'. Also known as 'Ruby Coding conventions', these are a set of guidelines that recommend programming style, practices and methods for each aspect of a piece of program written in Ruby. &lt;br /&gt;
&lt;br /&gt;
Software programmers are highly recommended to follow these guidelines to help improve the readability of their source code and make software maintenance easier. Naming conventions, class and member design principles, maintainability, performance, documentation and layout are the important areas where these guidelines have to be followed. More important than the reasons for having a guideline is actually adhering to it consistently.  Having a coding guideline documented and available means nothing if developers are not using it consistently.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Types of Guidelines''' ==&lt;br /&gt;
Coding guidelines in Ruby can be defined individually for major sections that code consists of. Naming , Class Design , Member Design , Maintainability, Performance, Documentation and Layout guidelines are illustrated below. These guidelines contain sections common to all of these as well as sections which apply to each one individually.&lt;br /&gt;
&lt;br /&gt;
=== Naming Guidelines&amp;lt;ref&amp;gt;http://itsignals.cascadia.com.au/?p=7&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Ruby uses the first character of the name to help it determine it’s intended use.&lt;br /&gt;
The standard Ruby file extension is .rb, although many people working on [http://en.wikipedia.org/wiki/Unix UNIX]-like systems don't bother with it for stand-alone scripts. Whether or not one uses it for scripts is up to them, but they will need to use it for library files or they will not be found by the interpreter.&lt;br /&gt;
&lt;br /&gt;
*'''Local Variables'''&lt;br /&gt;
:Should use lowercase letter followed by other characters. Naming convention states that it is better to use underscores rather than [http://en.wikipedia.org/wiki/CamelCase camelBack] for multiple word names, e.g. average, variable_xyz&lt;br /&gt;
*'''Instance Variables'''&lt;br /&gt;
:Instance variables are defined using the single &amp;quot;at&amp;quot; sign (@) followed by a name. It is suggested that a lowercase letter should succeed @, e.g. @color &lt;br /&gt;
*'''Instance Methods'''&lt;br /&gt;
:Method names should start with a lowercase letter, and may be followed by digits, underscores, and letters. The name should possibly be a verb e.g. move, display_details&lt;br /&gt;
*'''Class Variables'''&lt;br /&gt;
:Class variable names start with a double &amp;quot;at&amp;quot; sign (@@) and may be followed by digits, underscores, and letters, e.g. @@color&lt;br /&gt;
*'''Constant''' &lt;br /&gt;
:Constant names usually start with an uppercase letter followed by other characters. Constant objects are by convention named using all uppercase letters and underscores between words, e.g. THIS_IS_A_CONSTANT&lt;br /&gt;
*'''Class and Module''' &lt;br /&gt;
:Class names are recommended to be be nouns. In the case of modules, it's harder to make a clear recommendation. The names of [http://en.wikipedia.org/wiki/Mixin mix-ins] (which are just modules), however,  should probably be adjectives, such as the standard [http://en.wikibooks.org/wiki/Ruby_Programming/Reference/Objects/Enumerable Enumerable] and [http://www.ruby-doc.org/core-2.0.0/Comparable.html Comparable] modules. Class and module names starts with an uppercase letter, by convention they are named using MixedCase, e.g. module Encryption, class MixedCase&lt;br /&gt;
*'''Global Variables'''&lt;br /&gt;
:Starts with a dollar ($) sign followed by other characters, e.g. $global&lt;br /&gt;
&lt;br /&gt;
Considering customer order information as the data being used for an application, below naming guidelines give an idea of good class/table/file names.&lt;br /&gt;
*'''Model Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Table: orders&lt;br /&gt;
Class: Order&lt;br /&gt;
File: /app/models/order.rb&lt;br /&gt;
Primary Key: id&lt;br /&gt;
Foreign Key: customer_id&lt;br /&gt;
Link Tables: items_orders&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Controller Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class: OrdersController&lt;br /&gt;
File: /app/controllers/orders_controller.rb&lt;br /&gt;
Layout: /app/layouts/orders.html.erb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''View Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Helper: /app/helpers/orders_helper.rb&lt;br /&gt;
Helper Module: OrdersHelper&lt;br /&gt;
Views: /app/views/orders/… (list.html.erb for example)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Tests Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Unit: /test/unit/order_test.rb&lt;br /&gt;
Functional: /test/functional/orders_controller_test.rb&lt;br /&gt;
Fixtures: /test/fixtures/orders.yml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Class Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A class in Ruby always starts with the keyword class followed by the name of the class. The name should always be in initial capitals. Class Customer can be displayed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Customer&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A class is terminated by using the keyword end. All the data members in the class are between the class definition and the end keyword. &lt;br /&gt;
&lt;br /&gt;
Ruby blurs the distinction between design and implementation. Ideas that have to be expressed at the design level in other languages can be implemented directly in Ruby. To help in this process, Ruby has support for some design-level strategies. These strategies can be used to design classes accordingly as suitable for different types of  applications.&lt;br /&gt;
&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Visitor_pattern The Visitor pattern]''' is a way of traversing a collection without having to know the internal organization of that collection.&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Delegation_pattern Delegation]''' is a way of composing classes more flexibly and dynamically than can be done using standard inheritance.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Singleton_pattern Singleton pattern]''' is a way of ensuring that only one instantiation of a particular class exists at a time.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Observer_pattern Observer pattern]''' implements a protocol allowing one object to notify a set of interested objects when certain changes have occurred.&lt;br /&gt;
&lt;br /&gt;
Normally, all four of these strategies require explicit code each time they're implemented. With Ruby, they can be abstracted into a library and reused freely and transparently.&lt;br /&gt;
&lt;br /&gt;
=== Member Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
While defining class members, it is very important to keep in mind the access restrictions. Scope and life-time of class members are different for different restrictions, as illustrated below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public&lt;br /&gt;
totally accessible.&lt;br /&gt;
protected&lt;br /&gt;
accessible only by instances of class and direct descendants. Even through hasA relationships. (see below)&lt;br /&gt;
private&lt;br /&gt;
accessible only by instances of class (must be called nekkid no “self.” or anything else).&lt;br /&gt;
class A&lt;br /&gt;
  # Restriction used w/o arguments set the default access control.&lt;br /&gt;
  protected&lt;br /&gt;
&lt;br /&gt;
  def protected_method&lt;br /&gt;
    # nothing&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class B &amp;lt; A&lt;br /&gt;
  def test_protected&lt;br /&gt;
    myA = A.new&lt;br /&gt;
    myA.protected_method&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Used with arguments, sets the access of the named methods and constants.&lt;br /&gt;
  public :test_protected&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
b = B.new.test_protected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Maintainability Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
Maintainability guidelines are important to programmers for a number of reasons:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
*40%-80% of the lifetime cost of a piece of software goes to maintenance.&lt;br /&gt;
*Hardly any software is maintained for its whole life by the original author. &lt;br /&gt;
*Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. &lt;br /&gt;
*If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
The following guidelines are to be followed to improve the software maintainability&lt;br /&gt;
* '''Profile your code regularly'''&lt;br /&gt;
: If you profile your code regularly you’ll be able to tell if the latest change to the code will have an adverse effect on performance.  Integrate profiling into your testing process and make it automated to ensure that it’s not forgotten.  Like unit testing and BDD([http://en.wikipedia.org/wiki/Behavior-driven_development Behavior-driven development]) profiling goes a long way.&lt;br /&gt;
&lt;br /&gt;
=== Performance Guidelines&amp;lt;ref&amp;gt;http://blog.monitis.com/index.php/2012/02/08/20-ruby-performance-tips/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
The key parameter on which a software application is rated is by its performance. It is the time taken by the application to respond to a user's request. Performance of ruby can be improved significantly by following certain coding guidelines, as below.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid nesting loops more than three levels deep'''&lt;br /&gt;
: Nesting affects the performance of the code proportionally with the increasing levels in loops. Limiting nesting to three levels is one good practice to keep the code's performance well.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary variable assignments'''&lt;br /&gt;
: New programmers, often use unwanted variables in code.  A great example is when someone defines a variable to store a return value and then returns that variable; just return the value directly.&lt;br /&gt;
&lt;br /&gt;
*'''Reduce usage of disk I/O'''&lt;br /&gt;
: Disk I/O is a very costly operation as far as computing is concerned. Keeping it to the minimal improves the application response time drastically. Using disk I/O, makes the application extremely slow. Using storage systems such as memcached reduces disk I/O operations to a great extent as lot of data is kept in memory. The speed improvement while using a memory caching system is tremendous.&lt;br /&gt;
&lt;br /&gt;
*'''Use Ruby Enterprise Edition'''&lt;br /&gt;
: Ruby Enterprise edition provides up to [http://www.rubyenterpriseedition.com/faq.html#thirty_three_percent_mem_reduction 33% lower memory] usage.  Though, to get benefited by this performance one needs to follow their guidelines.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid method calls as much as possible'''&lt;br /&gt;
: Method calls are expensive operations in ruby. They should be avoided to keep up the performance of the application.&lt;br /&gt;
&lt;br /&gt;
*'''Use interpolated strings instead of concatenated strings'''&lt;br /&gt;
: Concatenated strings calls a method to get executed. So, it affects the performance as it is one of the most frequently used operation. Its better to replace them with Interpolated strings which runs faster as it doesn't invoke a method call.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
put “Hello there, #{name}!”vs.puts “Hello there, ” &amp;lt;&amp;lt; name = “!”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Destructive operations are faster'''&lt;br /&gt;
: Ruby’s in-place methods that which modifies the actual value than working on a copy of the data are much faster. But this should be handled carefully as original data gets disturbed.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary calls to uniq on arrays'''&lt;br /&gt;
: In many cases methods are already calling uniq on an array and there’s no need for you to call it yet again.&lt;br /&gt;
&lt;br /&gt;
*'''For loops are faster than .each'''&lt;br /&gt;
: .each uses an enumeration object behind the scene which adds a delay in execution. Using for instead of .each would improve performance but for short loops only.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/6406112/why-are-ruby-method-calls-particularly-slow-in-comparison-to-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Use x.blank? over x.nil? || x.empty?'''&lt;br /&gt;
: When using ActionPack there’s no need for x.nil? or x.empty?; x.blank? checks for both of these.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid calls to parse_date and strftime'''&lt;br /&gt;
: Both these calls are very expensive. using regular expressions would improve the time.&lt;br /&gt;
&lt;br /&gt;
*'''Know your gems'''&lt;br /&gt;
: All libraries are not efficient. Many gems may need to be removed to problem to fix a problem with the code. This is a common scenario when many gems are installed. So performing bench marking and testing a gem with others that perform same task would help in picking the right gem.&lt;br /&gt;
&lt;br /&gt;
*'''Improve your algorithms before you try to improve your code'''&lt;br /&gt;
: Algorithmic improvements results in evident improvements in performance of the code. It is always ideal to design an efficient algorithm without unwanted method calls.&lt;br /&gt;
&lt;br /&gt;
*'''Test the most frequently occurring case first'''&lt;br /&gt;
: While using if statements or a case statement always test the cases that occur most frequently. This allows less code to run before a decision is made.  It may not seem like much but over several hundred or thousand runs through the decision logic you’ll notice a definite performance gain.&lt;br /&gt;
&lt;br /&gt;
*'''Optimize the way you access global constants'''&lt;br /&gt;
: While accessing the global constants one should use namespace before the constants to avoid entire library search for the constant.&lt;br /&gt;
 &lt;br /&gt;
*'''Use explicit returns'''&lt;br /&gt;
: Even though the result of last operation is returned for a method, using explicit returns would speed up the code. Explicit returns are faster, especially in older Ruby versions such as 1.8.x.&lt;br /&gt;
&lt;br /&gt;
=== Documentation Guidelines&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/api_documentation_guidelines.html&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Documentation comments&amp;lt;ref&amp;gt;http://www.jetbrains.com/ruby/webhelp/documenting-source-code-in-rubymine.html&amp;lt;/ref&amp;gt; can be created in accordance with [http://rdoc.sourceforge.net/ RDoc] and [http://yardoc.org/ YARD] syntax. Note that RDoc highlighting in documentation comments can be turned enabled or disabled in the Appearance page of the editor settings.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The most common Documentation guidelines are listed below.&lt;br /&gt;
*Write simple, declarative sentences. Brevity is a plus: get to the point.&lt;br /&gt;
*Write in present tense: &amp;quot;Returns a hash that...&amp;quot;, rather than &amp;quot;Returned a hash that...&amp;quot; or &amp;quot;Will return a hash that...&amp;quot;.&lt;br /&gt;
*Start comments in upper case. Follow regular punctuation rules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Declares an attribute reader backed by an internally-named &lt;br /&gt;
# instance variable.&lt;br /&gt;
def attr_internal_reader(*attrs)&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Communicate to the reader the current way of doing things, both explicitly and implicitly. Use the idioms recommended in edge. Reorder sections to emphasize favored approaches if needed, etc. The documentation should be a model for best practices and canonical, modern Rails usage.&lt;br /&gt;
&lt;br /&gt;
Documentation has to be concise but comprehensive. Explore and document edge cases.&lt;br /&gt;
&lt;br /&gt;
=== Layout Guidelines&amp;lt;ref&amp;gt;http://www.caliban.org/ruby/rubyguide.shtml&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Designing the layout of any application determines the readability factor for other developers.&lt;br /&gt;
Most followed order of code is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
header block with author's name, Perforce Id tag and a brief description of what the program or library is for.&lt;br /&gt;
require statements&lt;br /&gt;
include statements&lt;br /&gt;
class and module definitions&lt;br /&gt;
main program section&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Spreading Code Out and Lining it Up'''&lt;br /&gt;
:This is very important for readability. Basically the principle is to:&lt;br /&gt;
:*separate each component part by white space.&lt;br /&gt;
:*align everything meaningfully.&lt;br /&gt;
:As such one can easily scan up and down the code and see the patterns. This is very important not only for understanding the code, but also for looking for anomalies and as a tool for rationalizing and consolidating the code.&lt;br /&gt;
:Code that has a lot of 'noise' - a lot of unnecessary variation and untidiness - is code that one can waste a lot of time working on. Well written and formatted code is code that is easy and quick to work with. It is code that allows one to easily 'see the wood from the trees'.&lt;br /&gt;
&lt;br /&gt;
== '''Code Analysis Tools''' ==&lt;br /&gt;
&lt;br /&gt;
Ruby itself goes a long way towards helping developers write clear code.&lt;br /&gt;
&lt;br /&gt;
*'''The Ruby debugger''' is a library loaded into Ruby at run-time. &lt;br /&gt;
This is done as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby -r debug [&lt;br /&gt;
            options&lt;br /&gt;
            ] [&lt;br /&gt;
            programfile&lt;br /&gt;
            ] [&lt;br /&gt;
            arguments&lt;br /&gt;
            ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debugger can do all the usual things one would expect it to, such as set breakpoints, step into and over code, print out the call stack, etc.&lt;br /&gt;
&lt;br /&gt;
While tools for the mainstream languages such as Java and C++ have reached a certain maturity, tools for Ruby are still growing. And they might be needed more and more as Ruby's usage spreads from early adopters to the early majority, and SLOC (Source Lines Of Code) continues to increase. Automatic tools&amp;lt;ref&amp;gt;https://www.ruby-toolbox.com/categories/code_metrics&amp;lt;/ref&amp;gt; can be used to detect several types of problems including inconsistent style, long methods and repeated code.&lt;br /&gt;
&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Roodi'''] (Ruby Object Oriented Design Inferometer) - this parses Ruby code and warns about design issues from the list  configured, ie: Class line count check, for loop check, parameter number check, cyclomatic checks and 10 other checks&lt;br /&gt;
*[https://github.com/troessner/reek/wiki '''Reek'''] - similar in concept to Roodi&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Saikuro'''] - designed to check cyclomatic complexity&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Flog'''] - created by Ryan Davis, this computes a score of code written: the higher the score is, the worse your code is. ABC metrics (Assignments, Branches and Calls) are taken into account to compute the score&lt;br /&gt;
*[http://www.harukizaemon.com/simian/ '''Simian'''] - a similarity analyzer, this can be used for duplication identification (a $99 license is needed for commercial use)&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Flay'''] - this is another free tool from Ryan Davis that finds structural similarities in code&lt;br /&gt;
&lt;br /&gt;
[[File:Code Analysis Outputs.png|frame|none|alt=Code Analysis Tool Results|Code Analysis Tool Results]]&lt;br /&gt;
&lt;br /&gt;
== '''Summary''' ==&lt;br /&gt;
Ruby developers should follow a certain criteria or guidelines during software development. Coding standards are set of rules, guidelines and regulations on the manner of writing a code that helps programmers and developers read and understand quickly the source code that conforms to style and help avoid introducing misunderstanding and faults.&lt;br /&gt;
&lt;br /&gt;
Particularly in Ruby development, coding standards are extremely important; therefore Ruby developers should put an importance to them. This is because these standards offer higher uniformity and consistency when writing code by different programmers. This could result in a code that's simple to know and preserve, thus reducing the project’s overall expenses.&lt;br /&gt;
&lt;br /&gt;
Some of the benefits of using coding standards are:&lt;br /&gt;
&lt;br /&gt;
*Easy to understand and maintained&lt;br /&gt;
*Boost the code’s readability&lt;br /&gt;
*Maintainable applications&lt;br /&gt;
*Eradicates complexity&lt;br /&gt;
*Separate documents look more appropriate&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://www.caliban.org/ruby/rubyguide.shtml&lt;br /&gt;
*https://github.com/styleguide/ruby&lt;br /&gt;
*http://www.ruby-doc.org/docs/ProgrammingRuby/&lt;br /&gt;
*https://www.ruby-lang.org/en/documentation/&lt;br /&gt;
*http://en.wikibooks.org/wiki/Ruby_programming_language&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78478</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w23 ph</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78478"/>
		<updated>2013-09-23T21:22:30Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* Code Analysis Tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby Coding Guidelines''' ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] Coding Guidelines include best practices followed generally for most of the [http://en.wikipedia.org/wiki/Category:Object-oriented_programming_languages object oriented programming languages] as Ruby is entirely 'Object Oriented'. Also known as 'Ruby Coding conventions', these are a set of guidelines that recommend programming style, practices and methods for each aspect of a piece of program written in Ruby. &lt;br /&gt;
&lt;br /&gt;
Software programmers are highly recommended to follow these guidelines to help improve the readability of their source code and make software maintenance easier. Naming conventions, class and member design principles, maintainability, performance, documentation and layout are the important areas where these guidelines have to be followed. More important than the reasons for having a guideline is actually adhering to it consistently.  Having a coding guideline documented and available means nothing if developers are not using it consistently.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Types of Guidelines''' ==&lt;br /&gt;
Coding guidelines in Ruby can be defined individually for major sections that code consists of. Naming , Class Design , Member Design , Maintainability, Performance, Documentation and Layout guidelines are illustrated below. These guidelines contain sections common to all of these as well as sections which apply to each one individually.&lt;br /&gt;
&lt;br /&gt;
=== Naming Guidelines&amp;lt;ref&amp;gt;http://itsignals.cascadia.com.au/?p=7&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Ruby uses the first character of the name to help it determine it’s intended use.&lt;br /&gt;
The standard Ruby file extension is .rb, although many people working on [http://en.wikipedia.org/wiki/Unix UNIX]-like systems don't bother with it for stand-alone scripts. Whether or not one uses it for scripts is up to them, but they will need to use it for library files or they will not be found by the interpreter.&lt;br /&gt;
&lt;br /&gt;
*'''Local Variables'''&lt;br /&gt;
:Should use lowercase letter followed by other characters. Naming convention states that it is better to use underscores rather than [http://en.wikipedia.org/wiki/CamelCase camelBack] for multiple word names, e.g. average, variable_xyz&lt;br /&gt;
*'''Instance Variables'''&lt;br /&gt;
:Instance variables are defined using the single &amp;quot;at&amp;quot; sign (@) followed by a name. It is suggested that a lowercase letter should succeed @, e.g. @color &lt;br /&gt;
*'''Instance Methods'''&lt;br /&gt;
:Method names should start with a lowercase letter, and may be followed by digits, underscores, and letters. The name should possibly be a verb e.g. move, display_details&lt;br /&gt;
*'''Class Variables'''&lt;br /&gt;
:Class variable names start with a double &amp;quot;at&amp;quot; sign (@@) and may be followed by digits, underscores, and letters, e.g. @@color&lt;br /&gt;
*'''Constant''' &lt;br /&gt;
:Constant names usually start with an uppercase letter followed by other characters. Constant objects are by convention named using all uppercase letters and underscores between words, e.g. THIS_IS_A_CONSTANT&lt;br /&gt;
*'''Class and Module''' &lt;br /&gt;
:Class names are recommended to be be nouns. In the case of modules, it's harder to make a clear recommendation. The names of [http://en.wikipedia.org/wiki/Mixin mix-ins] (which are just modules), however,  should probably be adjectives, such as the standard [http://en.wikibooks.org/wiki/Ruby_Programming/Reference/Objects/Enumerable Enumerable] and [http://www.ruby-doc.org/core-2.0.0/Comparable.html Comparable] modules. Class and module names starts with an uppercase letter, by convention they are named using MixedCase, e.g. module Encryption, class MixedCase&lt;br /&gt;
*'''Global Variables'''&lt;br /&gt;
:Starts with a dollar ($) sign followed by other characters, e.g. $global&lt;br /&gt;
&lt;br /&gt;
Considering customer order information as the data being used for an application, below naming guidelines give an idea of good class/table/file names.&lt;br /&gt;
*'''Model Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Table: orders&lt;br /&gt;
Class: Order&lt;br /&gt;
File: /app/models/order.rb&lt;br /&gt;
Primary Key: id&lt;br /&gt;
Foreign Key: customer_id&lt;br /&gt;
Link Tables: items_orders&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Controller Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class: OrdersController&lt;br /&gt;
File: /app/controllers/orders_controller.rb&lt;br /&gt;
Layout: /app/layouts/orders.html.erb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''View Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Helper: /app/helpers/orders_helper.rb&lt;br /&gt;
Helper Module: OrdersHelper&lt;br /&gt;
Views: /app/views/orders/… (list.html.erb for example)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Tests Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Unit: /test/unit/order_test.rb&lt;br /&gt;
Functional: /test/functional/orders_controller_test.rb&lt;br /&gt;
Fixtures: /test/fixtures/orders.yml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Class Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A class in Ruby always starts with the keyword class followed by the name of the class. The name should always be in initial capitals. Class Customer can be displayed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Customer&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A class is terminated by using the keyword end. All the data members in the class are between the class definition and the end keyword. &lt;br /&gt;
&lt;br /&gt;
Ruby blurs the distinction between design and implementation. Ideas that have to be expressed at the design level in other languages can be implemented directly in Ruby. To help in this process, Ruby has support for some design-level strategies. These strategies can be used to design classes accordingly as suitable for different types of  applications.&lt;br /&gt;
&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Visitor_pattern The Visitor pattern]''' is a way of traversing a collection without having to know the internal organization of that collection.&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Delegation_pattern Delegation]''' is a way of composing classes more flexibly and dynamically than can be done using standard inheritance.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Singleton_pattern Singleton pattern]''' is a way of ensuring that only one instantiation of a particular class exists at a time.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Observer_pattern Observer pattern]''' implements a protocol allowing one object to notify a set of interested objects when certain changes have occurred.&lt;br /&gt;
&lt;br /&gt;
Normally, all four of these strategies require explicit code each time they're implemented. With Ruby, they can be abstracted into a library and reused freely and transparently.&lt;br /&gt;
&lt;br /&gt;
=== Member Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
While defining class members, it is very important to keep in mind the access restrictions. Scope and life-time of class members are different for different restrictions, as illustrated below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public&lt;br /&gt;
totally accessible.&lt;br /&gt;
protected&lt;br /&gt;
accessible only by instances of class and direct descendants. Even through hasA relationships. (see below)&lt;br /&gt;
private&lt;br /&gt;
accessible only by instances of class (must be called nekkid no “self.” or anything else).&lt;br /&gt;
class A&lt;br /&gt;
  # Restriction used w/o arguments set the default access control.&lt;br /&gt;
  protected&lt;br /&gt;
&lt;br /&gt;
  def protected_method&lt;br /&gt;
    # nothing&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class B &amp;lt; A&lt;br /&gt;
  def test_protected&lt;br /&gt;
    myA = A.new&lt;br /&gt;
    myA.protected_method&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Used with arguments, sets the access of the named methods and constants.&lt;br /&gt;
  public :test_protected&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
b = B.new.test_protected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Maintainability Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
Maintainability guidelines are important to programmers for a number of reasons:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
*40%-80% of the lifetime cost of a piece of software goes to maintenance.&lt;br /&gt;
*Hardly any software is maintained for its whole life by the original author. &lt;br /&gt;
*Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. &lt;br /&gt;
*If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
The following guidelines are to be followed to improve the software maintainability&lt;br /&gt;
* '''Profile your code regularly'''&lt;br /&gt;
: If you profile your code regularly you’ll be able to tell if the latest change to the code will have an adverse effect on performance.  Integrate profiling into your testing process and make it automated to ensure that it’s not forgotten.  Like unit testing and BDD([http://en.wikipedia.org/wiki/Behavior-driven_development Behavior-driven development]) profiling goes a long way.&lt;br /&gt;
&lt;br /&gt;
=== Performance Guidelines&amp;lt;ref&amp;gt;http://blog.monitis.com/index.php/2012/02/08/20-ruby-performance-tips/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
The key parameter on which a software application is rated is by its performance. It is the time taken by the application to respond to a user's request. Performance of ruby can be improved significantly by following certain coding guidelines, as below.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid nesting loops more than three levels deep'''&lt;br /&gt;
: Nesting affects the performance of the code proportionally with the increasing levels in loops. Limiting nesting to three levels is one good practice to keep the code's performance well.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary variable assignments'''&lt;br /&gt;
: New programmers, often use unwanted variables in code.  A great example is when someone defines a variable to store a return value and then returns that variable; just return the value directly.&lt;br /&gt;
&lt;br /&gt;
*'''Reduce usage of disk I/O'''&lt;br /&gt;
: Disk I/O is a very costly operation as far as computing is concerned. Keeping it to the minimal improves the application response time drastically. Using disk I/O, makes the application extremely slow. Using storage systems such as memcached reduces disk I/O operations to a great extent as lot of data is kept in memory. The speed improvement while using a memory caching system is tremendous.&lt;br /&gt;
&lt;br /&gt;
*'''Use Ruby Enterprise Edition'''&lt;br /&gt;
: Ruby Enterprise edition provides up to [http://www.rubyenterpriseedition.com/faq.html#thirty_three_percent_mem_reduction 33% lower memory] usage.  Though, to get benefited by this performance one needs to follow their guidelines.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid method calls as much as possible'''&lt;br /&gt;
: Method calls are expensive operations in ruby. They should be avoided to keep up the performance of the application.&lt;br /&gt;
&lt;br /&gt;
*'''Use interpolated strings instead of concatenated strings'''&lt;br /&gt;
: Concatenated strings calls a method to get executed. So, it affects the performance as it is one of the most frequently used operation. Its better to replace them with Interpolated strings which runs faster as it doesn't invoke a method call.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
put “Hello there, #{name}!”vs.puts “Hello there, ” &amp;lt;&amp;lt; name = “!”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Destructive operations are faster'''&lt;br /&gt;
: Ruby’s in-place methods that which modifies the actual value than working on a copy of the data are much faster. But this should be handled carefully as original data gets disturbed.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary calls to uniq on arrays'''&lt;br /&gt;
: In many cases methods are already calling uniq on an array and there’s no need for you to call it yet again.&lt;br /&gt;
&lt;br /&gt;
*'''For loops are faster than .each'''&lt;br /&gt;
: .each uses an enumeration object behind the scene which adds a delay in execution. Using for instead of .each would improve performance but for short loops only.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/6406112/why-are-ruby-method-calls-particularly-slow-in-comparison-to-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Use x.blank? over x.nil? || x.empty?'''&lt;br /&gt;
: When using ActionPack there’s no need for x.nil? or x.empty?; x.blank? checks for both of these.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid calls to parse_date and strftime'''&lt;br /&gt;
: Both these calls are very expensive. using regular expressions would improve the time.&lt;br /&gt;
&lt;br /&gt;
*'''Know your gems'''&lt;br /&gt;
: All libraries are not efficient. Many gems may need to be removed to problem to fix a problem with the code. This is a common scenario when many gems are installed. So performing bench marking and testing a gem with others that perform same task would help in picking the right gem.&lt;br /&gt;
&lt;br /&gt;
*'''Improve your algorithms before you try to improve your code'''&lt;br /&gt;
: Algorithmic improvements results in evident improvements in performance of the code. It is always ideal to design an efficient algorithm without unwanted method calls.&lt;br /&gt;
&lt;br /&gt;
*'''Test the most frequently occurring case first'''&lt;br /&gt;
: While using if statements or a case statement always test the cases that occur most frequently. This allows less code to run before a decision is made.  It may not seem like much but over several hundred or thousand runs through the decision logic you’ll notice a definite performance gain.&lt;br /&gt;
&lt;br /&gt;
*'''Optimize the way you access global constants'''&lt;br /&gt;
: While accessing the global constants one should use namespace before the constants to avoid entire library search for the constant.&lt;br /&gt;
 &lt;br /&gt;
*'''Use explicit returns'''&lt;br /&gt;
: Even though the result of last operation is returned for a method, using explicit returns would speed up the code. Explicit returns are faster, especially in older Ruby versions such as 1.8.x.&lt;br /&gt;
&lt;br /&gt;
=== Documentation Guidelines&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/api_documentation_guidelines.html&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Documentation comments&amp;lt;ref&amp;gt;http://www.jetbrains.com/ruby/webhelp/documenting-source-code-in-rubymine.html&amp;lt;/ref&amp;gt; can be created in accordance with [http://rdoc.sourceforge.net/ RDoc] and [http://yardoc.org/ YARD] syntax. Note that RDoc highlighting in documentation comments can be turned enabled or disabled in the Appearance page of the editor settings.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The most common Documentation guidelines are listed below.&lt;br /&gt;
*Write simple, declarative sentences. Brevity is a plus: get to the point.&lt;br /&gt;
*Write in present tense: &amp;quot;Returns a hash that...&amp;quot;, rather than &amp;quot;Returned a hash that...&amp;quot; or &amp;quot;Will return a hash that...&amp;quot;.&lt;br /&gt;
*Start comments in upper case. Follow regular punctuation rules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Declares an attribute reader backed by an internally-named &lt;br /&gt;
# instance variable.&lt;br /&gt;
def attr_internal_reader(*attrs)&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Communicate to the reader the current way of doing things, both explicitly and implicitly. Use the idioms recommended in edge. Reorder sections to emphasize favored approaches if needed, etc. The documentation should be a model for best practices and canonical, modern Rails usage.&lt;br /&gt;
&lt;br /&gt;
Documentation has to be concise but comprehensive. Explore and document edge cases.&lt;br /&gt;
&lt;br /&gt;
=== Layout Guidelines&amp;lt;ref&amp;gt;http://www.caliban.org/ruby/rubyguide.shtml&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Designing the layout of any application determines the readability factor for other developers.&lt;br /&gt;
Most followed order of code is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
header block with author's name, Perforce Id tag and a brief description of what the program or library is for.&lt;br /&gt;
require statements&lt;br /&gt;
include statements&lt;br /&gt;
class and module definitions&lt;br /&gt;
main program section&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Spreading Code Out and Lining it Up'''&lt;br /&gt;
:This is very important for readability. Basically the principle is to:&lt;br /&gt;
:*separate each component part by white space.&lt;br /&gt;
:*align everything meaningfully.&lt;br /&gt;
:As such one can easily scan up and down the code and see the patterns. This is very important not only for understanding the code, but also for looking for anomalies and as a tool for rationalizing and consolidating the code.&lt;br /&gt;
:Code that has a lot of 'noise' - a lot of unnecessary variation and untidiness - is code that one can waste a lot of time working on. Well written and formatted code is code that is easy and quick to work with. It is code that allows one to easily 'see the wood from the trees'.&lt;br /&gt;
&lt;br /&gt;
== '''Code Analysis Tools''' ==&lt;br /&gt;
&lt;br /&gt;
Ruby itself goes a long way towards helping developers write clear code.&lt;br /&gt;
&lt;br /&gt;
*'''The Ruby debugger''' is a library loaded into Ruby at run-time. &lt;br /&gt;
This is done as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby -r debug [&lt;br /&gt;
            options&lt;br /&gt;
            ] [&lt;br /&gt;
            programfile&lt;br /&gt;
            ] [&lt;br /&gt;
            arguments&lt;br /&gt;
            ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debugger can do all the usual things one would expect it to, such as set breakpoints, step into and over code, print out the call stack, etc.&lt;br /&gt;
&lt;br /&gt;
While tools for the mainstream languages such as Java and C++ have reached a certain maturity, tools for Ruby are still growing. And they might be needed more and more as Ruby's usage spreads from early adopters to the early majority, and SLOC (Source Lines Of Code) continues to increase. Automatic tools&amp;lt;ref&amp;gt;https://www.ruby-toolbox.com/categories/code_metrics&amp;lt;/ref&amp;gt; can be used to detect several types of problems including inconsistent style, long methods and repeated code.&lt;br /&gt;
&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Roodi'''] (Ruby Object Oriented Design Inferometer) - this parses Ruby code and warns about design issues from the list  configured, ie: Class line count check, for loop check, parameter number check, cyclomatic checks and 10 other checks&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Reek'''] - similar in concept to Roodi&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Saikuro'''] - designed to check cyclomatic complexity&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Flog'''] - created by Ryan Davis, this computes a score of code written: the higher the score is, the worse your code is. ABC metrics (Assignments, Branches and Calls) are taken into account to compute the score&lt;br /&gt;
*[http://www.harukizaemon.com/simian/ '''Simian'''] - a similarity analyzer, this can be used for duplication identification (a $99 license is needed for commercial use)&lt;br /&gt;
*[https://www.ruby-toolbox.com/categories/code_metrics '''Flay'''] - this is another free tool from Ryan Davis that finds structural similarities in code&lt;br /&gt;
&lt;br /&gt;
[[File:Code Analysis Outputs.png|frame|none|alt=Code Analysis Tool Results|Code Analysis Tool Results]]&lt;br /&gt;
&lt;br /&gt;
== '''Summary''' ==&lt;br /&gt;
Ruby developers should follow a certain criteria or guidelines during software development. Coding standards are set of rules, guidelines and regulations on the manner of writing a code that helps programmers and developers read and understand quickly the source code that conforms to style and help avoid introducing misunderstanding and faults.&lt;br /&gt;
&lt;br /&gt;
Particularly in Ruby development, coding standards are extremely important; therefore Ruby developers should put an importance to them. This is because these standards offer higher uniformity and consistency when writing code by different programmers. This could result in a code that's simple to know and preserve, thus reducing the project’s overall expenses.&lt;br /&gt;
&lt;br /&gt;
Some of the benefits of using coding standards are:&lt;br /&gt;
&lt;br /&gt;
*Easy to understand and maintained&lt;br /&gt;
*Boost the code’s readability&lt;br /&gt;
*Maintainable applications&lt;br /&gt;
*Eradicates complexity&lt;br /&gt;
*Separate documents look more appropriate&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://www.caliban.org/ruby/rubyguide.shtml&lt;br /&gt;
*https://github.com/styleguide/ruby&lt;br /&gt;
*http://www.ruby-doc.org/docs/ProgrammingRuby/&lt;br /&gt;
*https://www.ruby-lang.org/en/documentation/&lt;br /&gt;
*http://en.wikibooks.org/wiki/Ruby_programming_language&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78465</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w23 ph</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78465"/>
		<updated>2013-09-23T18:33:07Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* See Also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby Coding Guidelines''' ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] Coding Guidelines include best practices followed generally for most of the [http://en.wikipedia.org/wiki/Category:Object-oriented_programming_languages object oriented programming languages] as Ruby is entirely 'Object Oriented'. Also known as 'Ruby Coding conventions', these are a set of guidelines that recommend programming style, practices and methods for each aspect of a piece of program written in Ruby. &lt;br /&gt;
&lt;br /&gt;
Software programmers are highly recommended to follow these guidelines to help improve the readability of their source code and make software maintenance easier. Naming conventions, class and member design principles, maintainability, performance, documentation and layout are the important areas where these guidelines have to be followed. More important than the reasons for having a guideline is actually adhering to it consistently.  Having a coding guideline documented and available means nothing if developers are not using it consistently.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Types of Guidelines''' ==&lt;br /&gt;
Coding guidelines in Ruby can be defined individually for major sections that code consists of. Naming , Class Design , Member Design , Maintainability, Performance, Documentation and Layout guidelines are illustrated below. These guidelines contain sections common to all of these as well as sections which apply to each one individually.&lt;br /&gt;
&lt;br /&gt;
=== Naming Guidelines&amp;lt;ref&amp;gt;http://itsignals.cascadia.com.au/?p=7&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Ruby uses the first character of the name to help it determine it’s intended use.&lt;br /&gt;
The standard Ruby file extension is .rb, although many people working on [http://en.wikipedia.org/wiki/Unix UNIX]-like systems don't bother with it for stand-alone scripts. Whether or not one uses it for scripts is up to them, but they will need to use it for library files or they will not be found by the interpreter.&lt;br /&gt;
&lt;br /&gt;
*'''Local Variables'''&lt;br /&gt;
:Should use lowercase letter followed by other characters. Naming convention states that it is better to use underscores rather than [http://en.wikipedia.org/wiki/CamelCase camelBack] for multiple word names, e.g. average, variable_xyz&lt;br /&gt;
*'''Instance Variables'''&lt;br /&gt;
:Instance variables are defined using the single &amp;quot;at&amp;quot; sign (@) followed by a name. It is suggested that a lowercase letter should succeed @, e.g. @color &lt;br /&gt;
*'''Instance Methods'''&lt;br /&gt;
:Method names should start with a lowercase letter, and may be followed by digits, underscores, and letters. The name should possibly be a verb e.g. move, display_details&lt;br /&gt;
*'''Class Variables'''&lt;br /&gt;
:Class variable names start with a double &amp;quot;at&amp;quot; sign (@@) and may be followed by digits, underscores, and letters, e.g. @@color&lt;br /&gt;
*'''Constant''' &lt;br /&gt;
:Constant names usually start with an uppercase letter followed by other characters. Constant objects are by convention named using all uppercase letters and underscores between words, e.g. THIS_IS_A_CONSTANT&lt;br /&gt;
*'''Class and Module''' &lt;br /&gt;
:Class names are recommended to be be nouns. In the case of modules, it's harder to make a clear recommendation. The names of [http://en.wikipedia.org/wiki/Mixin mix-ins] (which are just modules), however,  should probably be adjectives, such as the standard [http://en.wikibooks.org/wiki/Ruby_Programming/Reference/Objects/Enumerable Enumerable] and [http://www.ruby-doc.org/core-2.0.0/Comparable.html Comparable] modules. Class and module names starts with an uppercase letter, by convention they are named using MixedCase, e.g. module Encryption, class MixedCase&lt;br /&gt;
*'''Global Variables'''&lt;br /&gt;
:Starts with a dollar ($) sign followed by other characters, e.g. $global&lt;br /&gt;
&lt;br /&gt;
Considering customer order information as the data being used for an application, below naming guidelines give an idea of good class/table/file names.&lt;br /&gt;
*'''Model Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Table: orders&lt;br /&gt;
Class: Order&lt;br /&gt;
File: /app/models/order.rb&lt;br /&gt;
Primary Key: id&lt;br /&gt;
Foreign Key: customer_id&lt;br /&gt;
Link Tables: items_orders&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Controller Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class: OrdersController&lt;br /&gt;
File: /app/controllers/orders_controller.rb&lt;br /&gt;
Layout: /app/layouts/orders.html.erb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''View Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Helper: /app/helpers/orders_helper.rb&lt;br /&gt;
Helper Module: OrdersHelper&lt;br /&gt;
Views: /app/views/orders/… (list.html.erb for example)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Tests Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Unit: /test/unit/order_test.rb&lt;br /&gt;
Functional: /test/functional/orders_controller_test.rb&lt;br /&gt;
Fixtures: /test/fixtures/orders.yml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Class Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A class in Ruby always starts with the keyword class followed by the name of the class. The name should always be in initial capitals. Class Customer can be displayed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Customer&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A class is terminated by using the keyword end. All the data members in the class are between the class definition and the end keyword. &lt;br /&gt;
&lt;br /&gt;
Ruby blurs the distinction between design and implementation. Ideas that have to be expressed at the design level in other languages can be implemented directly in Ruby. To help in this process, Ruby has support for some design-level strategies. These strategies can be used to design classes accordingly as suitable for different types of  applications.&lt;br /&gt;
&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Visitor_pattern The Visitor pattern]''' is a way of traversing a collection without having to know the internal organization of that collection.&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Delegation_pattern Delegation]''' is a way of composing classes more flexibly and dynamically than can be done using standard inheritance.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Singleton_pattern Singleton pattern]''' is a way of ensuring that only one instantiation of a particular class exists at a time.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Observer_pattern Observer pattern]''' implements a protocol allowing one object to notify a set of interested objects when certain changes have occurred.&lt;br /&gt;
&lt;br /&gt;
Normally, all four of these strategies require explicit code each time they're implemented. With Ruby, they can be abstracted into a library and reused freely and transparently.&lt;br /&gt;
&lt;br /&gt;
=== Member Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
While defining class members, it is very important to keep in mind the access restrictions. Scope and life-time of class members are different for different restrictions, as illustrated below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public&lt;br /&gt;
totally accessible.&lt;br /&gt;
protected&lt;br /&gt;
accessible only by instances of class and direct descendants. Even through hasA relationships. (see below)&lt;br /&gt;
private&lt;br /&gt;
accessible only by instances of class (must be called nekkid no “self.” or anything else).&lt;br /&gt;
class A&lt;br /&gt;
  # Restriction used w/o arguments set the default access control.&lt;br /&gt;
  protected&lt;br /&gt;
&lt;br /&gt;
  def protected_method&lt;br /&gt;
    # nothing&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class B &amp;lt; A&lt;br /&gt;
  def test_protected&lt;br /&gt;
    myA = A.new&lt;br /&gt;
    myA.protected_method&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Used with arguments, sets the access of the named methods and constants.&lt;br /&gt;
  public :test_protected&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
b = B.new.test_protected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Maintainability Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
Maintainability guidelines are important to programmers for a number of reasons:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
*40%-80% of the lifetime cost of a piece of software goes to maintenance.&lt;br /&gt;
*Hardly any software is maintained for its whole life by the original author. &lt;br /&gt;
*Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. &lt;br /&gt;
*If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
The following guidelines are to be followed to improve the software maintainability&lt;br /&gt;
* '''Profile your code regularly'''&lt;br /&gt;
: If you profile your code regularly you’ll be able to tell if the latest change to the code will have an adverse effect on performance.  Integrate profiling into your testing process and make it automated to ensure that it’s not forgotten.  Like unit testing and BDD([http://en.wikipedia.org/wiki/Behavior-driven_development Behavior-driven development]) profiling goes a long way.&lt;br /&gt;
&lt;br /&gt;
=== Performance Guidelines&amp;lt;ref&amp;gt;http://blog.monitis.com/index.php/2012/02/08/20-ruby-performance-tips/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
The key parameter on which a software application is rated is by its performance. It is the time taken by the application to respond to a user's request. Performance of ruby can be improved significantly by following certain coding guidelines, as below.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid nesting loops more than three levels deep'''&lt;br /&gt;
: Nesting affects the performance of the code proportionally with the increasing levels in loops. Limiting nesting to three levels is one good practice to keep the code's performance well.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary variable assignments'''&lt;br /&gt;
: New programmers, often use unwanted variables in code.  A great example is when someone defines a variable to store a return value and then returns that variable; just return the value directly.&lt;br /&gt;
&lt;br /&gt;
*'''Reduce usage of disk I/O'''&lt;br /&gt;
: Disk I/O is a very costly operation as far as computing is concerned. Keeping it to the minimal improves the application response time drastically. Using disk I/O, makes the application extremely slow. Using storage systems such as memcached reduces disk I/O operations to a great extent as lot of data is kept in memory. The speed improvement while using a memory caching system is tremendous.&lt;br /&gt;
&lt;br /&gt;
*'''Use Ruby Enterprise Edition'''&lt;br /&gt;
: Ruby Enterprise edition provides up to [http://www.rubyenterpriseedition.com/faq.html#thirty_three_percent_mem_reduction 33% lower memory] usage.  Though, to get benefited by this performance one needs to follow their guidelines.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid method calls as much as possible'''&lt;br /&gt;
: Method calls are expensive operations in ruby. They should be avoided to keep up the performance of the application.&lt;br /&gt;
&lt;br /&gt;
*'''Use interpolated strings instead of concatenated strings'''&lt;br /&gt;
: Concatenated strings calls a method to get executed. So, it affects the performance as it is one of the most frequently used operation. Its better to replace them with Interpolated strings which runs faster as it doesn't invoke a method call.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
put “Hello there, #{name}!”vs.puts “Hello there, ” &amp;lt;&amp;lt; name = “!”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Destructive operations are faster'''&lt;br /&gt;
: Ruby’s in-place methods that which modifies the actual value than working on a copy of the data are much faster. But this should be handled carefully as original data gets disturbed.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary calls to uniq on arrays'''&lt;br /&gt;
: In many cases methods are already calling uniq on an array and there’s no need for you to call it yet again.&lt;br /&gt;
&lt;br /&gt;
*'''For loops are faster than .each'''&lt;br /&gt;
: .each uses an enumeration object behind the scene which adds a delay in execution. Using for instead of .each would improve performance but for short loops only.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/6406112/why-are-ruby-method-calls-particularly-slow-in-comparison-to-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Use x.blank? over x.nil? || x.empty?'''&lt;br /&gt;
: When using ActionPack there’s no need for x.nil? or x.empty?; x.blank? checks for both of these.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid calls to parse_date and strftime'''&lt;br /&gt;
: Both these calls are very expensive. using regular expressions would improve the time.&lt;br /&gt;
&lt;br /&gt;
*'''Know your gems'''&lt;br /&gt;
: All libraries are not efficient. Many gems may need to be removed to problem to fix a problem with the code. This is a common scenario when many gems are installed. So performing bench marking and testing a gem with others that perform same task would help in picking the right gem.&lt;br /&gt;
&lt;br /&gt;
*'''Improve your algorithms before you try to improve your code'''&lt;br /&gt;
: Algorithmic improvements results in evident improvements in performance of the code. It is always ideal to design an efficient algorithm without unwanted method calls.&lt;br /&gt;
&lt;br /&gt;
*'''Test the most frequently occurring case first'''&lt;br /&gt;
: While using if statements or a case statement always test the cases that occur most frequently. This allows less code to run before a decision is made.  It may not seem like much but over several hundred or thousand runs through the decision logic you’ll notice a definite performance gain.&lt;br /&gt;
&lt;br /&gt;
*'''Optimize the way you access global constants'''&lt;br /&gt;
: While accessing the global constants one should use namespace before the constants to avoid entire library search for the constant.&lt;br /&gt;
 &lt;br /&gt;
*'''Use explicit returns'''&lt;br /&gt;
: Even though the result of last operation is returned for a method, using explicit returns would speed up the code. Explicit returns are faster, especially in older Ruby versions such as 1.8.x.&lt;br /&gt;
&lt;br /&gt;
=== Documentation Guidelines&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/api_documentation_guidelines.html&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Documentation comments&amp;lt;ref&amp;gt;http://www.jetbrains.com/ruby/webhelp/documenting-source-code-in-rubymine.html&amp;lt;/ref&amp;gt; can be created in accordance with [http://rdoc.sourceforge.net/ RDoc] and [http://yardoc.org/ YARD] syntax. Note that RDoc highlighting in documentation comments can be turned enabled or disabled in the Appearance page of the editor settings.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The most common Documentation guidelines are listed below.&lt;br /&gt;
*Write simple, declarative sentences. Brevity is a plus: get to the point.&lt;br /&gt;
*Write in present tense: &amp;quot;Returns a hash that...&amp;quot;, rather than &amp;quot;Returned a hash that...&amp;quot; or &amp;quot;Will return a hash that...&amp;quot;.&lt;br /&gt;
*Start comments in upper case. Follow regular punctuation rules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Declares an attribute reader backed by an internally-named &lt;br /&gt;
# instance variable.&lt;br /&gt;
def attr_internal_reader(*attrs)&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Communicate to the reader the current way of doing things, both explicitly and implicitly. Use the idioms recommended in edge. Reorder sections to emphasize favored approaches if needed, etc. The documentation should be a model for best practices and canonical, modern Rails usage.&lt;br /&gt;
&lt;br /&gt;
Documentation has to be concise but comprehensive. Explore and document edge cases.&lt;br /&gt;
&lt;br /&gt;
=== Layout Guidelines&amp;lt;ref&amp;gt;http://www.caliban.org/ruby/rubyguide.shtml&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Designing the layout of any application determines the readability factor for other developers.&lt;br /&gt;
Most followed order of code is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
header block with author's name, Perforce Id tag and a brief description of what the program or library is for.&lt;br /&gt;
require statements&lt;br /&gt;
include statements&lt;br /&gt;
class and module definitions&lt;br /&gt;
main program section&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Spreading Code Out and Lining it Up'''&lt;br /&gt;
:This is very important for readability. Basically the principle is to:&lt;br /&gt;
:*separate each component part by white space.&lt;br /&gt;
:*align everything meaningfully.&lt;br /&gt;
:As such one can easily scan up and down the code and see the patterns. This is very important not only for understanding the code, but also for looking for anomalies and as a tool for rationalizing and consolidating the code.&lt;br /&gt;
:Code that has a lot of 'noise' - a lot of unnecessary variation and untidiness - is code that one can waste a lot of time working on. Well written and formatted code is code that is easy and quick to work with. It is code that allows one to easily 'see the wood from the trees'.&lt;br /&gt;
&lt;br /&gt;
== '''Code Analysis Tools''' ==&lt;br /&gt;
&lt;br /&gt;
Ruby itself goes a long way towards helping developers write clear code.&lt;br /&gt;
&lt;br /&gt;
*'''The Ruby debugger''' is a library loaded into Ruby at run-time. &lt;br /&gt;
This is done as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby -r debug [&lt;br /&gt;
            options&lt;br /&gt;
            ] [&lt;br /&gt;
            programfile&lt;br /&gt;
            ] [&lt;br /&gt;
            arguments&lt;br /&gt;
            ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debugger can do all the usual things one would expect it to, such as set breakpoints, step into and over code, print out the call stack, etc.&lt;br /&gt;
&lt;br /&gt;
While tools for the mainstream languages such as Java and C++ have reached a certain maturity, tools for Ruby are still growing. And they might be needed more and more as Ruby's usage spreads from early adopters to the early majority, and SLOC (Source Lines Of Code) continues to increase. Automatic tools&amp;lt;ref&amp;gt;http://www.infoq.com/news/2009/09/code-quality-metric-fu&amp;lt;/ref&amp;gt; can be used to detect several types of problems including inconsistent style, long methods and repeated code.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/roodi/roodi/tree/master '''Roodi'''] (Ruby Object Oriented Design Inferometer) - this parses Ruby code and warns about design issues from the list  configured, ie: Class line count check, for loop check, parameter number check, cyclomatic checks and 10 other checks&lt;br /&gt;
*[https://github.com/troessner/reek '''Reek'''] - similar in concept to Roodi&lt;br /&gt;
*[https://github.com/devver/saikuro '''Saikuro'''] - designed to check cyclomatic complexity&lt;br /&gt;
*[https://github.com/seattlerb/flog '''Flog'''] - created by Ryan Davis, this computes a score of code written: the higher the score is, the worse your code is. ABC metrics (Assignments, Branches and Calls) are taken into account to compute the score&lt;br /&gt;
*[http://www.harukizaemon.com/simian/ '''Simian'''] - a similarity analyzer, this can be used for duplication identification (a $99 license is needed for commercial use)&lt;br /&gt;
*[https://github.com/seattlerb/flay '''Flay'''] - this is another free tool from Ryan Davis that finds structural similarities in code&lt;br /&gt;
&lt;br /&gt;
[[File:Code Analysis Outputs.png|frame|none|alt=Code Analysis Tool Results|Code Analysis Tool Results]]&lt;br /&gt;
&lt;br /&gt;
== '''Summary''' ==&lt;br /&gt;
Ruby developers should follow a certain criteria or guidelines during software development. Coding standards are set of rules, guidelines and regulations on the manner of writing a code that helps programmers and developers read and understand quickly the source code that conforms to style and help avoid introducing misunderstanding and faults.&lt;br /&gt;
&lt;br /&gt;
Particularly in Ruby development, coding standards are extremely important; therefore Ruby developers should put an importance to them. This is because these standards offer higher uniformity and consistency when writing code by different programmers. This could result in a code that's simple to know and preserve, thus reducing the project’s overall expenses.&lt;br /&gt;
&lt;br /&gt;
Some of the benefits of using coding standards are:&lt;br /&gt;
&lt;br /&gt;
*Easy to understand and maintained&lt;br /&gt;
*Boost the code’s readability&lt;br /&gt;
*Maintainable applications&lt;br /&gt;
*Eradicates complexity&lt;br /&gt;
*Separate documents look more appropriate&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://www.caliban.org/ruby/rubyguide.shtml&lt;br /&gt;
*https://github.com/styleguide/ruby&lt;br /&gt;
*http://www.ruby-doc.org/docs/ProgrammingRuby/&lt;br /&gt;
*https://www.ruby-lang.org/en/documentation/&lt;br /&gt;
*http://en.wikibooks.org/wiki/Ruby_programming_language&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78464</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w23 ph</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78464"/>
		<updated>2013-09-23T18:24:22Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* See Also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby Coding Guidelines''' ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] Coding Guidelines include best practices followed generally for most of the [http://en.wikipedia.org/wiki/Category:Object-oriented_programming_languages object oriented programming languages] as Ruby is entirely 'Object Oriented'. Also known as 'Ruby Coding conventions', these are a set of guidelines that recommend programming style, practices and methods for each aspect of a piece of program written in Ruby. &lt;br /&gt;
&lt;br /&gt;
Software programmers are highly recommended to follow these guidelines to help improve the readability of their source code and make software maintenance easier. Naming conventions, class and member design principles, maintainability, performance, documentation and layout are the important areas where these guidelines have to be followed. More important than the reasons for having a guideline is actually adhering to it consistently.  Having a coding guideline documented and available means nothing if developers are not using it consistently.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Types of Guidelines''' ==&lt;br /&gt;
Coding guidelines in Ruby can be defined individually for major sections that code consists of. Naming , Class Design , Member Design , Maintainability, Performance, Documentation and Layout guidelines are illustrated below. These guidelines contain sections common to all of these as well as sections which apply to each one individually.&lt;br /&gt;
&lt;br /&gt;
=== Naming Guidelines&amp;lt;ref&amp;gt;http://itsignals.cascadia.com.au/?p=7&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Ruby uses the first character of the name to help it determine it’s intended use.&lt;br /&gt;
The standard Ruby file extension is .rb, although many people working on [http://en.wikipedia.org/wiki/Unix UNIX]-like systems don't bother with it for stand-alone scripts. Whether or not one uses it for scripts is up to them, but they will need to use it for library files or they will not be found by the interpreter.&lt;br /&gt;
&lt;br /&gt;
*'''Local Variables'''&lt;br /&gt;
:Should use lowercase letter followed by other characters. Naming convention states that it is better to use underscores rather than [http://en.wikipedia.org/wiki/CamelCase camelBack] for multiple word names, e.g. average, variable_xyz&lt;br /&gt;
*'''Instance Variables'''&lt;br /&gt;
:Instance variables are defined using the single &amp;quot;at&amp;quot; sign (@) followed by a name. It is suggested that a lowercase letter should succeed @, e.g. @color &lt;br /&gt;
*'''Instance Methods'''&lt;br /&gt;
:Method names should start with a lowercase letter, and may be followed by digits, underscores, and letters. The name should possibly be a verb e.g. move, display_details&lt;br /&gt;
*'''Class Variables'''&lt;br /&gt;
:Class variable names start with a double &amp;quot;at&amp;quot; sign (@@) and may be followed by digits, underscores, and letters, e.g. @@color&lt;br /&gt;
*'''Constant''' &lt;br /&gt;
:Constant names usually start with an uppercase letter followed by other characters. Constant objects are by convention named using all uppercase letters and underscores between words, e.g. THIS_IS_A_CONSTANT&lt;br /&gt;
*'''Class and Module''' &lt;br /&gt;
:Class names are recommended to be be nouns. In the case of modules, it's harder to make a clear recommendation. The names of [http://en.wikipedia.org/wiki/Mixin mix-ins] (which are just modules), however,  should probably be adjectives, such as the standard [http://en.wikibooks.org/wiki/Ruby_Programming/Reference/Objects/Enumerable Enumerable] and [http://www.ruby-doc.org/core-2.0.0/Comparable.html Comparable] modules. Class and module names starts with an uppercase letter, by convention they are named using MixedCase, e.g. module Encryption, class MixedCase&lt;br /&gt;
*'''Global Variables'''&lt;br /&gt;
:Starts with a dollar ($) sign followed by other characters, e.g. $global&lt;br /&gt;
&lt;br /&gt;
Considering customer order information as the data being used for an application, below naming guidelines give an idea of good class/table/file names.&lt;br /&gt;
*'''Model Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Table: orders&lt;br /&gt;
Class: Order&lt;br /&gt;
File: /app/models/order.rb&lt;br /&gt;
Primary Key: id&lt;br /&gt;
Foreign Key: customer_id&lt;br /&gt;
Link Tables: items_orders&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Controller Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class: OrdersController&lt;br /&gt;
File: /app/controllers/orders_controller.rb&lt;br /&gt;
Layout: /app/layouts/orders.html.erb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''View Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Helper: /app/helpers/orders_helper.rb&lt;br /&gt;
Helper Module: OrdersHelper&lt;br /&gt;
Views: /app/views/orders/… (list.html.erb for example)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Tests Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Unit: /test/unit/order_test.rb&lt;br /&gt;
Functional: /test/functional/orders_controller_test.rb&lt;br /&gt;
Fixtures: /test/fixtures/orders.yml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Class Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A class in Ruby always starts with the keyword class followed by the name of the class. The name should always be in initial capitals. Class Customer can be displayed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Customer&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A class is terminated by using the keyword end. All the data members in the class are between the class definition and the end keyword. &lt;br /&gt;
&lt;br /&gt;
Ruby blurs the distinction between design and implementation. Ideas that have to be expressed at the design level in other languages can be implemented directly in Ruby. To help in this process, Ruby has support for some design-level strategies. These strategies can be used to design classes accordingly as suitable for different types of  applications.&lt;br /&gt;
&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Visitor_pattern The Visitor pattern]''' is a way of traversing a collection without having to know the internal organization of that collection.&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Delegation_pattern Delegation]''' is a way of composing classes more flexibly and dynamically than can be done using standard inheritance.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Singleton_pattern Singleton pattern]''' is a way of ensuring that only one instantiation of a particular class exists at a time.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Observer_pattern Observer pattern]''' implements a protocol allowing one object to notify a set of interested objects when certain changes have occurred.&lt;br /&gt;
&lt;br /&gt;
Normally, all four of these strategies require explicit code each time they're implemented. With Ruby, they can be abstracted into a library and reused freely and transparently.&lt;br /&gt;
&lt;br /&gt;
=== Member Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
While defining class members, it is very important to keep in mind the access restrictions. Scope and life-time of class members are different for different restrictions, as illustrated below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public&lt;br /&gt;
totally accessible.&lt;br /&gt;
protected&lt;br /&gt;
accessible only by instances of class and direct descendants. Even through hasA relationships. (see below)&lt;br /&gt;
private&lt;br /&gt;
accessible only by instances of class (must be called nekkid no “self.” or anything else).&lt;br /&gt;
class A&lt;br /&gt;
  # Restriction used w/o arguments set the default access control.&lt;br /&gt;
  protected&lt;br /&gt;
&lt;br /&gt;
  def protected_method&lt;br /&gt;
    # nothing&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class B &amp;lt; A&lt;br /&gt;
  def test_protected&lt;br /&gt;
    myA = A.new&lt;br /&gt;
    myA.protected_method&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Used with arguments, sets the access of the named methods and constants.&lt;br /&gt;
  public :test_protected&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
b = B.new.test_protected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Maintainability Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
Maintainability guidelines are important to programmers for a number of reasons:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
*40%-80% of the lifetime cost of a piece of software goes to maintenance.&lt;br /&gt;
*Hardly any software is maintained for its whole life by the original author. &lt;br /&gt;
*Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. &lt;br /&gt;
*If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
The following guidelines are to be followed to improve the software maintainability&lt;br /&gt;
* '''Profile your code regularly'''&lt;br /&gt;
: If you profile your code regularly you’ll be able to tell if the latest change to the code will have an adverse effect on performance.  Integrate profiling into your testing process and make it automated to ensure that it’s not forgotten.  Like unit testing and BDD([http://en.wikipedia.org/wiki/Behavior-driven_development Behavior-driven development]) profiling goes a long way.&lt;br /&gt;
&lt;br /&gt;
=== Performance Guidelines&amp;lt;ref&amp;gt;http://blog.monitis.com/index.php/2012/02/08/20-ruby-performance-tips/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
The key parameter on which a software application is rated is by its performance. It is the time taken by the application to respond to a user's request. Performance of ruby can be improved significantly by following certain coding guidelines, as below.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid nesting loops more than three levels deep'''&lt;br /&gt;
: Nesting affects the performance of the code proportionally with the increasing levels in loops. Limiting nesting to three levels is one good practice to keep the code's performance well.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary variable assignments'''&lt;br /&gt;
: New programmers, often use unwanted variables in code.  A great example is when someone defines a variable to store a return value and then returns that variable; just return the value directly.&lt;br /&gt;
&lt;br /&gt;
*'''Reduce usage of disk I/O'''&lt;br /&gt;
: Disk I/O is a very costly operation as far as computing is concerned. Keeping it to the minimal improves the application response time drastically. Using disk I/O, makes the application extremely slow. Using storage systems such as memcached reduces disk I/O operations to a great extent as lot of data is kept in memory. The speed improvement while using a memory caching system is tremendous.&lt;br /&gt;
&lt;br /&gt;
*'''Use Ruby Enterprise Edition'''&lt;br /&gt;
: Ruby Enterprise edition provides up to [http://www.rubyenterpriseedition.com/faq.html#thirty_three_percent_mem_reduction 33% lower memory] usage.  Though, to get benefited by this performance one needs to follow their guidelines.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid method calls as much as possible'''&lt;br /&gt;
: Method calls are expensive operations in ruby. They should be avoided to keep up the performance of the application.&lt;br /&gt;
&lt;br /&gt;
*'''Use interpolated strings instead of concatenated strings'''&lt;br /&gt;
: Concatenated strings calls a method to get executed. So, it affects the performance as it is one of the most frequently used operation. Its better to replace them with Interpolated strings which runs faster as it doesn't invoke a method call.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
put “Hello there, #{name}!”vs.puts “Hello there, ” &amp;lt;&amp;lt; name = “!”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Destructive operations are faster'''&lt;br /&gt;
: Ruby’s in-place methods that which modifies the actual value than working on a copy of the data are much faster. But this should be handled carefully as original data gets disturbed.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary calls to uniq on arrays'''&lt;br /&gt;
: In many cases methods are already calling uniq on an array and there’s no need for you to call it yet again.&lt;br /&gt;
&lt;br /&gt;
*'''For loops are faster than .each'''&lt;br /&gt;
: .each uses an enumeration object behind the scene which adds a delay in execution. Using for instead of .each would improve performance but for short loops only.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/6406112/why-are-ruby-method-calls-particularly-slow-in-comparison-to-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Use x.blank? over x.nil? || x.empty?'''&lt;br /&gt;
: When using ActionPack there’s no need for x.nil? or x.empty?; x.blank? checks for both of these.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid calls to parse_date and strftime'''&lt;br /&gt;
: Both these calls are very expensive. using regular expressions would improve the time.&lt;br /&gt;
&lt;br /&gt;
*'''Know your gems'''&lt;br /&gt;
: All libraries are not efficient. Many gems may need to be removed to problem to fix a problem with the code. This is a common scenario when many gems are installed. So performing bench marking and testing a gem with others that perform same task would help in picking the right gem.&lt;br /&gt;
&lt;br /&gt;
*'''Improve your algorithms before you try to improve your code'''&lt;br /&gt;
: Algorithmic improvements results in evident improvements in performance of the code. It is always ideal to design an efficient algorithm without unwanted method calls.&lt;br /&gt;
&lt;br /&gt;
*'''Test the most frequently occurring case first'''&lt;br /&gt;
: While using if statements or a case statement always test the cases that occur most frequently. This allows less code to run before a decision is made.  It may not seem like much but over several hundred or thousand runs through the decision logic you’ll notice a definite performance gain.&lt;br /&gt;
&lt;br /&gt;
*'''Optimize the way you access global constants'''&lt;br /&gt;
: While accessing the global constants one should use namespace before the constants to avoid entire library search for the constant.&lt;br /&gt;
 &lt;br /&gt;
*'''Use explicit returns'''&lt;br /&gt;
: Even though the result of last operation is returned for a method, using explicit returns would speed up the code. Explicit returns are faster, especially in older Ruby versions such as 1.8.x.&lt;br /&gt;
&lt;br /&gt;
=== Documentation Guidelines&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/api_documentation_guidelines.html&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Documentation comments&amp;lt;ref&amp;gt;http://www.jetbrains.com/ruby/webhelp/documenting-source-code-in-rubymine.html&amp;lt;/ref&amp;gt; can be created in accordance with [http://rdoc.sourceforge.net/ RDoc] and [http://yardoc.org/ YARD] syntax. Note that RDoc highlighting in documentation comments can be turned enabled or disabled in the Appearance page of the editor settings.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The most common Documentation guidelines are listed below.&lt;br /&gt;
*Write simple, declarative sentences. Brevity is a plus: get to the point.&lt;br /&gt;
*Write in present tense: &amp;quot;Returns a hash that...&amp;quot;, rather than &amp;quot;Returned a hash that...&amp;quot; or &amp;quot;Will return a hash that...&amp;quot;.&lt;br /&gt;
*Start comments in upper case. Follow regular punctuation rules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Declares an attribute reader backed by an internally-named &lt;br /&gt;
# instance variable.&lt;br /&gt;
def attr_internal_reader(*attrs)&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Communicate to the reader the current way of doing things, both explicitly and implicitly. Use the idioms recommended in edge. Reorder sections to emphasize favored approaches if needed, etc. The documentation should be a model for best practices and canonical, modern Rails usage.&lt;br /&gt;
&lt;br /&gt;
Documentation has to be concise but comprehensive. Explore and document edge cases.&lt;br /&gt;
&lt;br /&gt;
=== Layout Guidelines&amp;lt;ref&amp;gt;http://www.caliban.org/ruby/rubyguide.shtml&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Designing the layout of any application determines the readability factor for other developers.&lt;br /&gt;
Most followed order of code is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
header block with author's name, Perforce Id tag and a brief description of what the program or library is for.&lt;br /&gt;
require statements&lt;br /&gt;
include statements&lt;br /&gt;
class and module definitions&lt;br /&gt;
main program section&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Spreading Code Out and Lining it Up'''&lt;br /&gt;
:This is very important for readability. Basically the principle is to:&lt;br /&gt;
:*separate each component part by white space.&lt;br /&gt;
:*align everything meaningfully.&lt;br /&gt;
:As such one can easily scan up and down the code and see the patterns. This is very important not only for understanding the code, but also for looking for anomalies and as a tool for rationalizing and consolidating the code.&lt;br /&gt;
:Code that has a lot of 'noise' - a lot of unnecessary variation and untidiness - is code that one can waste a lot of time working on. Well written and formatted code is code that is easy and quick to work with. It is code that allows one to easily 'see the wood from the trees'.&lt;br /&gt;
&lt;br /&gt;
== '''Code Analysis Tools''' ==&lt;br /&gt;
&lt;br /&gt;
Ruby itself goes a long way towards helping developers write clear code.&lt;br /&gt;
&lt;br /&gt;
*'''The Ruby debugger''' is a library loaded into Ruby at run-time. &lt;br /&gt;
This is done as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby -r debug [&lt;br /&gt;
            options&lt;br /&gt;
            ] [&lt;br /&gt;
            programfile&lt;br /&gt;
            ] [&lt;br /&gt;
            arguments&lt;br /&gt;
            ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debugger can do all the usual things one would expect it to, such as set breakpoints, step into and over code, print out the call stack, etc.&lt;br /&gt;
&lt;br /&gt;
While tools for the mainstream languages such as Java and C++ have reached a certain maturity, tools for Ruby are still growing. And they might be needed more and more as Ruby's usage spreads from early adopters to the early majority, and SLOC (Source Lines Of Code) continues to increase. Automatic tools&amp;lt;ref&amp;gt;http://www.infoq.com/news/2009/09/code-quality-metric-fu&amp;lt;/ref&amp;gt; can be used to detect several types of problems including inconsistent style, long methods and repeated code.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/roodi/roodi/tree/master '''Roodi'''] (Ruby Object Oriented Design Inferometer) - this parses Ruby code and warns about design issues from the list  configured, ie: Class line count check, for loop check, parameter number check, cyclomatic checks and 10 other checks&lt;br /&gt;
*[https://github.com/troessner/reek '''Reek'''] - similar in concept to Roodi&lt;br /&gt;
*[https://github.com/devver/saikuro '''Saikuro'''] - designed to check cyclomatic complexity&lt;br /&gt;
*[https://github.com/seattlerb/flog '''Flog'''] - created by Ryan Davis, this computes a score of code written: the higher the score is, the worse your code is. ABC metrics (Assignments, Branches and Calls) are taken into account to compute the score&lt;br /&gt;
*[http://www.harukizaemon.com/simian/ '''Simian'''] - a similarity analyzer, this can be used for duplication identification (a $99 license is needed for commercial use)&lt;br /&gt;
*[https://github.com/seattlerb/flay '''Flay'''] - this is another free tool from Ryan Davis that finds structural similarities in code&lt;br /&gt;
&lt;br /&gt;
[[File:Code Analysis Outputs.png|frame|none|alt=Code Analysis Tool Results|Code Analysis Tool Results]]&lt;br /&gt;
&lt;br /&gt;
== '''Summary''' ==&lt;br /&gt;
Ruby developers should follow a certain criteria or guidelines during software development. Coding standards are set of rules, guidelines and regulations on the manner of writing a code that helps programmers and developers read and understand quickly the source code that conforms to style and help avoid introducing misunderstanding and faults.&lt;br /&gt;
&lt;br /&gt;
Particularly in Ruby development, coding standards are extremely important; therefore Ruby developers should put an importance to them. This is because these standards offer higher uniformity and consistency when writing code by different programmers. This could result in a code that's simple to know and preserve, thus reducing the project’s overall expenses.&lt;br /&gt;
&lt;br /&gt;
Some of the benefits of using coding standards are:&lt;br /&gt;
&lt;br /&gt;
*Easy to understand and maintained&lt;br /&gt;
*Boost the code’s readability&lt;br /&gt;
*Maintainable applications&lt;br /&gt;
*Eradicates complexity&lt;br /&gt;
*Separate documents look more appropriate&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://www.caliban.org/ruby/rubyguide.shtml&lt;br /&gt;
*https://github.com/styleguide/ruby&lt;br /&gt;
*http://www.ruby-doc.org/docs/ProgrammingRuby/&lt;br /&gt;
*https://www.ruby-lang.org/en/documentation/&lt;br /&gt;
*https://www.ruby-lang.org/en/documentation/&lt;br /&gt;
*http://en.wikibooks.org/wiki/Ruby_programming_language&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78463</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w23 ph</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78463"/>
		<updated>2013-09-23T18:19:51Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* See Also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby Coding Guidelines''' ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] Coding Guidelines include best practices followed generally for most of the [http://en.wikipedia.org/wiki/Category:Object-oriented_programming_languages object oriented programming languages] as Ruby is entirely 'Object Oriented'. Also known as 'Ruby Coding conventions', these are a set of guidelines that recommend programming style, practices and methods for each aspect of a piece of program written in Ruby. &lt;br /&gt;
&lt;br /&gt;
Software programmers are highly recommended to follow these guidelines to help improve the readability of their source code and make software maintenance easier. Naming conventions, class and member design principles, maintainability, performance, documentation and layout are the important areas where these guidelines have to be followed. More important than the reasons for having a guideline is actually adhering to it consistently.  Having a coding guideline documented and available means nothing if developers are not using it consistently.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Types of Guidelines''' ==&lt;br /&gt;
Coding guidelines in Ruby can be defined individually for major sections that code consists of. Naming , Class Design , Member Design , Maintainability, Performance, Documentation and Layout guidelines are illustrated below. These guidelines contain sections common to all of these as well as sections which apply to each one individually.&lt;br /&gt;
&lt;br /&gt;
=== Naming Guidelines&amp;lt;ref&amp;gt;http://itsignals.cascadia.com.au/?p=7&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Ruby uses the first character of the name to help it determine it’s intended use.&lt;br /&gt;
The standard Ruby file extension is .rb, although many people working on [http://en.wikipedia.org/wiki/Unix UNIX]-like systems don't bother with it for stand-alone scripts. Whether or not one uses it for scripts is up to them, but they will need to use it for library files or they will not be found by the interpreter.&lt;br /&gt;
&lt;br /&gt;
*'''Local Variables'''&lt;br /&gt;
:Should use lowercase letter followed by other characters. Naming convention states that it is better to use underscores rather than [http://en.wikipedia.org/wiki/CamelCase camelBack] for multiple word names, e.g. average, variable_xyz&lt;br /&gt;
*'''Instance Variables'''&lt;br /&gt;
:Instance variables are defined using the single &amp;quot;at&amp;quot; sign (@) followed by a name. It is suggested that a lowercase letter should succeed @, e.g. @color &lt;br /&gt;
*'''Instance Methods'''&lt;br /&gt;
:Method names should start with a lowercase letter, and may be followed by digits, underscores, and letters. The name should possibly be a verb e.g. move, display_details&lt;br /&gt;
*'''Class Variables'''&lt;br /&gt;
:Class variable names start with a double &amp;quot;at&amp;quot; sign (@@) and may be followed by digits, underscores, and letters, e.g. @@color&lt;br /&gt;
*'''Constant''' &lt;br /&gt;
:Constant names usually start with an uppercase letter followed by other characters. Constant objects are by convention named using all uppercase letters and underscores between words, e.g. THIS_IS_A_CONSTANT&lt;br /&gt;
*'''Class and Module''' &lt;br /&gt;
:Class names are recommended to be be nouns. In the case of modules, it's harder to make a clear recommendation. The names of [http://en.wikipedia.org/wiki/Mixin mix-ins] (which are just modules), however,  should probably be adjectives, such as the standard [http://en.wikibooks.org/wiki/Ruby_Programming/Reference/Objects/Enumerable Enumerable] and [http://www.ruby-doc.org/core-2.0.0/Comparable.html Comparable] modules. Class and module names starts with an uppercase letter, by convention they are named using MixedCase, e.g. module Encryption, class MixedCase&lt;br /&gt;
*'''Global Variables'''&lt;br /&gt;
:Starts with a dollar ($) sign followed by other characters, e.g. $global&lt;br /&gt;
&lt;br /&gt;
Considering customer order information as the data being used for an application, below naming guidelines give an idea of good class/table/file names.&lt;br /&gt;
*'''Model Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Table: orders&lt;br /&gt;
Class: Order&lt;br /&gt;
File: /app/models/order.rb&lt;br /&gt;
Primary Key: id&lt;br /&gt;
Foreign Key: customer_id&lt;br /&gt;
Link Tables: items_orders&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Controller Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class: OrdersController&lt;br /&gt;
File: /app/controllers/orders_controller.rb&lt;br /&gt;
Layout: /app/layouts/orders.html.erb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''View Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Helper: /app/helpers/orders_helper.rb&lt;br /&gt;
Helper Module: OrdersHelper&lt;br /&gt;
Views: /app/views/orders/… (list.html.erb for example)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Tests Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Unit: /test/unit/order_test.rb&lt;br /&gt;
Functional: /test/functional/orders_controller_test.rb&lt;br /&gt;
Fixtures: /test/fixtures/orders.yml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Class Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A class in Ruby always starts with the keyword class followed by the name of the class. The name should always be in initial capitals. Class Customer can be displayed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Customer&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A class is terminated by using the keyword end. All the data members in the class are between the class definition and the end keyword. &lt;br /&gt;
&lt;br /&gt;
Ruby blurs the distinction between design and implementation. Ideas that have to be expressed at the design level in other languages can be implemented directly in Ruby. To help in this process, Ruby has support for some design-level strategies. These strategies can be used to design classes accordingly as suitable for different types of  applications.&lt;br /&gt;
&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Visitor_pattern The Visitor pattern]''' is a way of traversing a collection without having to know the internal organization of that collection.&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Delegation_pattern Delegation]''' is a way of composing classes more flexibly and dynamically than can be done using standard inheritance.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Singleton_pattern Singleton pattern]''' is a way of ensuring that only one instantiation of a particular class exists at a time.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Observer_pattern Observer pattern]''' implements a protocol allowing one object to notify a set of interested objects when certain changes have occurred.&lt;br /&gt;
&lt;br /&gt;
Normally, all four of these strategies require explicit code each time they're implemented. With Ruby, they can be abstracted into a library and reused freely and transparently.&lt;br /&gt;
&lt;br /&gt;
=== Member Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
While defining class members, it is very important to keep in mind the access restrictions. Scope and life-time of class members are different for different restrictions, as illustrated below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public&lt;br /&gt;
totally accessible.&lt;br /&gt;
protected&lt;br /&gt;
accessible only by instances of class and direct descendants. Even through hasA relationships. (see below)&lt;br /&gt;
private&lt;br /&gt;
accessible only by instances of class (must be called nekkid no “self.” or anything else).&lt;br /&gt;
class A&lt;br /&gt;
  # Restriction used w/o arguments set the default access control.&lt;br /&gt;
  protected&lt;br /&gt;
&lt;br /&gt;
  def protected_method&lt;br /&gt;
    # nothing&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class B &amp;lt; A&lt;br /&gt;
  def test_protected&lt;br /&gt;
    myA = A.new&lt;br /&gt;
    myA.protected_method&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Used with arguments, sets the access of the named methods and constants.&lt;br /&gt;
  public :test_protected&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
b = B.new.test_protected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Maintainability Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
Maintainability guidelines are important to programmers for a number of reasons:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
*40%-80% of the lifetime cost of a piece of software goes to maintenance.&lt;br /&gt;
*Hardly any software is maintained for its whole life by the original author. &lt;br /&gt;
*Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. &lt;br /&gt;
*If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
The following guidelines are to be followed to improve the software maintainability&lt;br /&gt;
* '''Profile your code regularly'''&lt;br /&gt;
: If you profile your code regularly you’ll be able to tell if the latest change to the code will have an adverse effect on performance.  Integrate profiling into your testing process and make it automated to ensure that it’s not forgotten.  Like unit testing and BDD([http://en.wikipedia.org/wiki/Behavior-driven_development Behavior-driven development]) profiling goes a long way.&lt;br /&gt;
&lt;br /&gt;
=== Performance Guidelines&amp;lt;ref&amp;gt;http://blog.monitis.com/index.php/2012/02/08/20-ruby-performance-tips/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
The key parameter on which a software application is rated is by its performance. It is the time taken by the application to respond to a user's request. Performance of ruby can be improved significantly by following certain coding guidelines, as below.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid nesting loops more than three levels deep'''&lt;br /&gt;
: Nesting affects the performance of the code proportionally with the increasing levels in loops. Limiting nesting to three levels is one good practice to keep the code's performance well.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary variable assignments'''&lt;br /&gt;
: New programmers, often use unwanted variables in code.  A great example is when someone defines a variable to store a return value and then returns that variable; just return the value directly.&lt;br /&gt;
&lt;br /&gt;
*'''Reduce usage of disk I/O'''&lt;br /&gt;
: Disk I/O is a very costly operation as far as computing is concerned. Keeping it to the minimal improves the application response time drastically. Using disk I/O, makes the application extremely slow. Using storage systems such as memcached reduces disk I/O operations to a great extent as lot of data is kept in memory. The speed improvement while using a memory caching system is tremendous.&lt;br /&gt;
&lt;br /&gt;
*'''Use Ruby Enterprise Edition'''&lt;br /&gt;
: Ruby Enterprise edition provides up to [http://www.rubyenterpriseedition.com/faq.html#thirty_three_percent_mem_reduction 33% lower memory] usage.  Though, to get benefited by this performance one needs to follow their guidelines.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid method calls as much as possible'''&lt;br /&gt;
: Method calls are expensive operations in ruby. They should be avoided to keep up the performance of the application.&lt;br /&gt;
&lt;br /&gt;
*'''Use interpolated strings instead of concatenated strings'''&lt;br /&gt;
: Concatenated strings calls a method to get executed. So, it affects the performance as it is one of the most frequently used operation. Its better to replace them with Interpolated strings which runs faster as it doesn't invoke a method call.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
put “Hello there, #{name}!”vs.puts “Hello there, ” &amp;lt;&amp;lt; name = “!”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Destructive operations are faster'''&lt;br /&gt;
: Ruby’s in-place methods that which modifies the actual value than working on a copy of the data are much faster. But this should be handled carefully as original data gets disturbed.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary calls to uniq on arrays'''&lt;br /&gt;
: In many cases methods are already calling uniq on an array and there’s no need for you to call it yet again.&lt;br /&gt;
&lt;br /&gt;
*'''For loops are faster than .each'''&lt;br /&gt;
: .each uses an enumeration object behind the scene which adds a delay in execution. Using for instead of .each would improve performance but for short loops only.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/6406112/why-are-ruby-method-calls-particularly-slow-in-comparison-to-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Use x.blank? over x.nil? || x.empty?'''&lt;br /&gt;
: When using ActionPack there’s no need for x.nil? or x.empty?; x.blank? checks for both of these.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid calls to parse_date and strftime'''&lt;br /&gt;
: Both these calls are very expensive. using regular expressions would improve the time.&lt;br /&gt;
&lt;br /&gt;
*'''Know your gems'''&lt;br /&gt;
: All libraries are not efficient. Many gems may need to be removed to problem to fix a problem with the code. This is a common scenario when many gems are installed. So performing bench marking and testing a gem with others that perform same task would help in picking the right gem.&lt;br /&gt;
&lt;br /&gt;
*'''Improve your algorithms before you try to improve your code'''&lt;br /&gt;
: Algorithmic improvements results in evident improvements in performance of the code. It is always ideal to design an efficient algorithm without unwanted method calls.&lt;br /&gt;
&lt;br /&gt;
*'''Test the most frequently occurring case first'''&lt;br /&gt;
: While using if statements or a case statement always test the cases that occur most frequently. This allows less code to run before a decision is made.  It may not seem like much but over several hundred or thousand runs through the decision logic you’ll notice a definite performance gain.&lt;br /&gt;
&lt;br /&gt;
*'''Optimize the way you access global constants'''&lt;br /&gt;
: While accessing the global constants one should use namespace before the constants to avoid entire library search for the constant.&lt;br /&gt;
 &lt;br /&gt;
*'''Use explicit returns'''&lt;br /&gt;
: Even though the result of last operation is returned for a method, using explicit returns would speed up the code. Explicit returns are faster, especially in older Ruby versions such as 1.8.x.&lt;br /&gt;
&lt;br /&gt;
=== Documentation Guidelines&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/api_documentation_guidelines.html&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Documentation comments&amp;lt;ref&amp;gt;http://www.jetbrains.com/ruby/webhelp/documenting-source-code-in-rubymine.html&amp;lt;/ref&amp;gt; can be created in accordance with [http://rdoc.sourceforge.net/ RDoc] and [http://yardoc.org/ YARD] syntax. Note that RDoc highlighting in documentation comments can be turned enabled or disabled in the Appearance page of the editor settings.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The most common Documentation guidelines are listed below.&lt;br /&gt;
*Write simple, declarative sentences. Brevity is a plus: get to the point.&lt;br /&gt;
*Write in present tense: &amp;quot;Returns a hash that...&amp;quot;, rather than &amp;quot;Returned a hash that...&amp;quot; or &amp;quot;Will return a hash that...&amp;quot;.&lt;br /&gt;
*Start comments in upper case. Follow regular punctuation rules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Declares an attribute reader backed by an internally-named &lt;br /&gt;
# instance variable.&lt;br /&gt;
def attr_internal_reader(*attrs)&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Communicate to the reader the current way of doing things, both explicitly and implicitly. Use the idioms recommended in edge. Reorder sections to emphasize favored approaches if needed, etc. The documentation should be a model for best practices and canonical, modern Rails usage.&lt;br /&gt;
&lt;br /&gt;
Documentation has to be concise but comprehensive. Explore and document edge cases.&lt;br /&gt;
&lt;br /&gt;
=== Layout Guidelines&amp;lt;ref&amp;gt;http://www.caliban.org/ruby/rubyguide.shtml&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Designing the layout of any application determines the readability factor for other developers.&lt;br /&gt;
Most followed order of code is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
header block with author's name, Perforce Id tag and a brief description of what the program or library is for.&lt;br /&gt;
require statements&lt;br /&gt;
include statements&lt;br /&gt;
class and module definitions&lt;br /&gt;
main program section&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Spreading Code Out and Lining it Up'''&lt;br /&gt;
:This is very important for readability. Basically the principle is to:&lt;br /&gt;
:*separate each component part by white space.&lt;br /&gt;
:*align everything meaningfully.&lt;br /&gt;
:As such one can easily scan up and down the code and see the patterns. This is very important not only for understanding the code, but also for looking for anomalies and as a tool for rationalizing and consolidating the code.&lt;br /&gt;
:Code that has a lot of 'noise' - a lot of unnecessary variation and untidiness - is code that one can waste a lot of time working on. Well written and formatted code is code that is easy and quick to work with. It is code that allows one to easily 'see the wood from the trees'.&lt;br /&gt;
&lt;br /&gt;
== '''Code Analysis Tools''' ==&lt;br /&gt;
&lt;br /&gt;
Ruby itself goes a long way towards helping developers write clear code.&lt;br /&gt;
&lt;br /&gt;
*'''The Ruby debugger''' is a library loaded into Ruby at run-time. &lt;br /&gt;
This is done as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby -r debug [&lt;br /&gt;
            options&lt;br /&gt;
            ] [&lt;br /&gt;
            programfile&lt;br /&gt;
            ] [&lt;br /&gt;
            arguments&lt;br /&gt;
            ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debugger can do all the usual things one would expect it to, such as set breakpoints, step into and over code, print out the call stack, etc.&lt;br /&gt;
&lt;br /&gt;
While tools for the mainstream languages such as Java and C++ have reached a certain maturity, tools for Ruby are still growing. And they might be needed more and more as Ruby's usage spreads from early adopters to the early majority, and SLOC (Source Lines Of Code) continues to increase. Automatic tools&amp;lt;ref&amp;gt;http://www.infoq.com/news/2009/09/code-quality-metric-fu&amp;lt;/ref&amp;gt; can be used to detect several types of problems including inconsistent style, long methods and repeated code.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/roodi/roodi/tree/master '''Roodi'''] (Ruby Object Oriented Design Inferometer) - this parses Ruby code and warns about design issues from the list  configured, ie: Class line count check, for loop check, parameter number check, cyclomatic checks and 10 other checks&lt;br /&gt;
*[https://github.com/troessner/reek '''Reek'''] - similar in concept to Roodi&lt;br /&gt;
*[https://github.com/devver/saikuro '''Saikuro'''] - designed to check cyclomatic complexity&lt;br /&gt;
*[https://github.com/seattlerb/flog '''Flog'''] - created by Ryan Davis, this computes a score of code written: the higher the score is, the worse your code is. ABC metrics (Assignments, Branches and Calls) are taken into account to compute the score&lt;br /&gt;
*[http://www.harukizaemon.com/simian/ '''Simian'''] - a similarity analyzer, this can be used for duplication identification (a $99 license is needed for commercial use)&lt;br /&gt;
*[https://github.com/seattlerb/flay '''Flay'''] - this is another free tool from Ryan Davis that finds structural similarities in code&lt;br /&gt;
&lt;br /&gt;
[[File:Code Analysis Outputs.png|frame|none|alt=Code Analysis Tool Results|Code Analysis Tool Results]]&lt;br /&gt;
&lt;br /&gt;
== '''Summary''' ==&lt;br /&gt;
Ruby developers should follow a certain criteria or guidelines during software development. Coding standards are set of rules, guidelines and regulations on the manner of writing a code that helps programmers and developers read and understand quickly the source code that conforms to style and help avoid introducing misunderstanding and faults.&lt;br /&gt;
&lt;br /&gt;
Particularly in Ruby development, coding standards are extremely important; therefore Ruby developers should put an importance to them. This is because these standards offer higher uniformity and consistency when writing code by different programmers. This could result in a code that's simple to know and preserve, thus reducing the project’s overall expenses.&lt;br /&gt;
&lt;br /&gt;
Some of the benefits of using coding standards are:&lt;br /&gt;
&lt;br /&gt;
*Easy to understand and maintained&lt;br /&gt;
*Boost the code’s readability&lt;br /&gt;
*Maintainable applications&lt;br /&gt;
*Eradicates complexity&lt;br /&gt;
*Separate documents look more appropriate&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://www.caliban.org/ruby/rubyguide.shtml&lt;br /&gt;
*https://github.com/styleguide/ruby&lt;br /&gt;
*http://www.ruby-doc.org/docs/ProgrammingRuby/&lt;br /&gt;
*https://www.ruby-lang.org/en/documentation/&lt;br /&gt;
*https://www.ruby-lang.org/en/documentation/&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78462</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w23 ph</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78462"/>
		<updated>2013-09-23T18:17:57Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* See Also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby Coding Guidelines''' ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] Coding Guidelines include best practices followed generally for most of the [http://en.wikipedia.org/wiki/Category:Object-oriented_programming_languages object oriented programming languages] as Ruby is entirely 'Object Oriented'. Also known as 'Ruby Coding conventions', these are a set of guidelines that recommend programming style, practices and methods for each aspect of a piece of program written in Ruby. &lt;br /&gt;
&lt;br /&gt;
Software programmers are highly recommended to follow these guidelines to help improve the readability of their source code and make software maintenance easier. Naming conventions, class and member design principles, maintainability, performance, documentation and layout are the important areas where these guidelines have to be followed. More important than the reasons for having a guideline is actually adhering to it consistently.  Having a coding guideline documented and available means nothing if developers are not using it consistently.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Types of Guidelines''' ==&lt;br /&gt;
Coding guidelines in Ruby can be defined individually for major sections that code consists of. Naming , Class Design , Member Design , Maintainability, Performance, Documentation and Layout guidelines are illustrated below. These guidelines contain sections common to all of these as well as sections which apply to each one individually.&lt;br /&gt;
&lt;br /&gt;
=== Naming Guidelines&amp;lt;ref&amp;gt;http://itsignals.cascadia.com.au/?p=7&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Ruby uses the first character of the name to help it determine it’s intended use.&lt;br /&gt;
The standard Ruby file extension is .rb, although many people working on [http://en.wikipedia.org/wiki/Unix UNIX]-like systems don't bother with it for stand-alone scripts. Whether or not one uses it for scripts is up to them, but they will need to use it for library files or they will not be found by the interpreter.&lt;br /&gt;
&lt;br /&gt;
*'''Local Variables'''&lt;br /&gt;
:Should use lowercase letter followed by other characters. Naming convention states that it is better to use underscores rather than [http://en.wikipedia.org/wiki/CamelCase camelBack] for multiple word names, e.g. average, variable_xyz&lt;br /&gt;
*'''Instance Variables'''&lt;br /&gt;
:Instance variables are defined using the single &amp;quot;at&amp;quot; sign (@) followed by a name. It is suggested that a lowercase letter should succeed @, e.g. @color &lt;br /&gt;
*'''Instance Methods'''&lt;br /&gt;
:Method names should start with a lowercase letter, and may be followed by digits, underscores, and letters. The name should possibly be a verb e.g. move, display_details&lt;br /&gt;
*'''Class Variables'''&lt;br /&gt;
:Class variable names start with a double &amp;quot;at&amp;quot; sign (@@) and may be followed by digits, underscores, and letters, e.g. @@color&lt;br /&gt;
*'''Constant''' &lt;br /&gt;
:Constant names usually start with an uppercase letter followed by other characters. Constant objects are by convention named using all uppercase letters and underscores between words, e.g. THIS_IS_A_CONSTANT&lt;br /&gt;
*'''Class and Module''' &lt;br /&gt;
:Class names are recommended to be be nouns. In the case of modules, it's harder to make a clear recommendation. The names of [http://en.wikipedia.org/wiki/Mixin mix-ins] (which are just modules), however,  should probably be adjectives, such as the standard [http://en.wikibooks.org/wiki/Ruby_Programming/Reference/Objects/Enumerable Enumerable] and [http://www.ruby-doc.org/core-2.0.0/Comparable.html Comparable] modules. Class and module names starts with an uppercase letter, by convention they are named using MixedCase, e.g. module Encryption, class MixedCase&lt;br /&gt;
*'''Global Variables'''&lt;br /&gt;
:Starts with a dollar ($) sign followed by other characters, e.g. $global&lt;br /&gt;
&lt;br /&gt;
Considering customer order information as the data being used for an application, below naming guidelines give an idea of good class/table/file names.&lt;br /&gt;
*'''Model Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Table: orders&lt;br /&gt;
Class: Order&lt;br /&gt;
File: /app/models/order.rb&lt;br /&gt;
Primary Key: id&lt;br /&gt;
Foreign Key: customer_id&lt;br /&gt;
Link Tables: items_orders&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Controller Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class: OrdersController&lt;br /&gt;
File: /app/controllers/orders_controller.rb&lt;br /&gt;
Layout: /app/layouts/orders.html.erb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''View Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Helper: /app/helpers/orders_helper.rb&lt;br /&gt;
Helper Module: OrdersHelper&lt;br /&gt;
Views: /app/views/orders/… (list.html.erb for example)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Tests Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Unit: /test/unit/order_test.rb&lt;br /&gt;
Functional: /test/functional/orders_controller_test.rb&lt;br /&gt;
Fixtures: /test/fixtures/orders.yml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Class Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A class in Ruby always starts with the keyword class followed by the name of the class. The name should always be in initial capitals. Class Customer can be displayed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Customer&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A class is terminated by using the keyword end. All the data members in the class are between the class definition and the end keyword. &lt;br /&gt;
&lt;br /&gt;
Ruby blurs the distinction between design and implementation. Ideas that have to be expressed at the design level in other languages can be implemented directly in Ruby. To help in this process, Ruby has support for some design-level strategies. These strategies can be used to design classes accordingly as suitable for different types of  applications.&lt;br /&gt;
&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Visitor_pattern The Visitor pattern]''' is a way of traversing a collection without having to know the internal organization of that collection.&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Delegation_pattern Delegation]''' is a way of composing classes more flexibly and dynamically than can be done using standard inheritance.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Singleton_pattern Singleton pattern]''' is a way of ensuring that only one instantiation of a particular class exists at a time.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Observer_pattern Observer pattern]''' implements a protocol allowing one object to notify a set of interested objects when certain changes have occurred.&lt;br /&gt;
&lt;br /&gt;
Normally, all four of these strategies require explicit code each time they're implemented. With Ruby, they can be abstracted into a library and reused freely and transparently.&lt;br /&gt;
&lt;br /&gt;
=== Member Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
While defining class members, it is very important to keep in mind the access restrictions. Scope and life-time of class members are different for different restrictions, as illustrated below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public&lt;br /&gt;
totally accessible.&lt;br /&gt;
protected&lt;br /&gt;
accessible only by instances of class and direct descendants. Even through hasA relationships. (see below)&lt;br /&gt;
private&lt;br /&gt;
accessible only by instances of class (must be called nekkid no “self.” or anything else).&lt;br /&gt;
class A&lt;br /&gt;
  # Restriction used w/o arguments set the default access control.&lt;br /&gt;
  protected&lt;br /&gt;
&lt;br /&gt;
  def protected_method&lt;br /&gt;
    # nothing&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class B &amp;lt; A&lt;br /&gt;
  def test_protected&lt;br /&gt;
    myA = A.new&lt;br /&gt;
    myA.protected_method&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Used with arguments, sets the access of the named methods and constants.&lt;br /&gt;
  public :test_protected&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
b = B.new.test_protected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Maintainability Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
Maintainability guidelines are important to programmers for a number of reasons:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
*40%-80% of the lifetime cost of a piece of software goes to maintenance.&lt;br /&gt;
*Hardly any software is maintained for its whole life by the original author. &lt;br /&gt;
*Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. &lt;br /&gt;
*If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
The following guidelines are to be followed to improve the software maintainability&lt;br /&gt;
* '''Profile your code regularly'''&lt;br /&gt;
: If you profile your code regularly you’ll be able to tell if the latest change to the code will have an adverse effect on performance.  Integrate profiling into your testing process and make it automated to ensure that it’s not forgotten.  Like unit testing and BDD([http://en.wikipedia.org/wiki/Behavior-driven_development Behavior-driven development]) profiling goes a long way.&lt;br /&gt;
&lt;br /&gt;
=== Performance Guidelines&amp;lt;ref&amp;gt;http://blog.monitis.com/index.php/2012/02/08/20-ruby-performance-tips/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
The key parameter on which a software application is rated is by its performance. It is the time taken by the application to respond to a user's request. Performance of ruby can be improved significantly by following certain coding guidelines, as below.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid nesting loops more than three levels deep'''&lt;br /&gt;
: Nesting affects the performance of the code proportionally with the increasing levels in loops. Limiting nesting to three levels is one good practice to keep the code's performance well.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary variable assignments'''&lt;br /&gt;
: New programmers, often use unwanted variables in code.  A great example is when someone defines a variable to store a return value and then returns that variable; just return the value directly.&lt;br /&gt;
&lt;br /&gt;
*'''Reduce usage of disk I/O'''&lt;br /&gt;
: Disk I/O is a very costly operation as far as computing is concerned. Keeping it to the minimal improves the application response time drastically. Using disk I/O, makes the application extremely slow. Using storage systems such as memcached reduces disk I/O operations to a great extent as lot of data is kept in memory. The speed improvement while using a memory caching system is tremendous.&lt;br /&gt;
&lt;br /&gt;
*'''Use Ruby Enterprise Edition'''&lt;br /&gt;
: Ruby Enterprise edition provides up to [http://www.rubyenterpriseedition.com/faq.html#thirty_three_percent_mem_reduction 33% lower memory] usage.  Though, to get benefited by this performance one needs to follow their guidelines.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid method calls as much as possible'''&lt;br /&gt;
: Method calls are expensive operations in ruby. They should be avoided to keep up the performance of the application.&lt;br /&gt;
&lt;br /&gt;
*'''Use interpolated strings instead of concatenated strings'''&lt;br /&gt;
: Concatenated strings calls a method to get executed. So, it affects the performance as it is one of the most frequently used operation. Its better to replace them with Interpolated strings which runs faster as it doesn't invoke a method call.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
put “Hello there, #{name}!”vs.puts “Hello there, ” &amp;lt;&amp;lt; name = “!”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Destructive operations are faster'''&lt;br /&gt;
: Ruby’s in-place methods that which modifies the actual value than working on a copy of the data are much faster. But this should be handled carefully as original data gets disturbed.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary calls to uniq on arrays'''&lt;br /&gt;
: In many cases methods are already calling uniq on an array and there’s no need for you to call it yet again.&lt;br /&gt;
&lt;br /&gt;
*'''For loops are faster than .each'''&lt;br /&gt;
: .each uses an enumeration object behind the scene which adds a delay in execution. Using for instead of .each would improve performance but for short loops only.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/6406112/why-are-ruby-method-calls-particularly-slow-in-comparison-to-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Use x.blank? over x.nil? || x.empty?'''&lt;br /&gt;
: When using ActionPack there’s no need for x.nil? or x.empty?; x.blank? checks for both of these.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid calls to parse_date and strftime'''&lt;br /&gt;
: Both these calls are very expensive. using regular expressions would improve the time.&lt;br /&gt;
&lt;br /&gt;
*'''Know your gems'''&lt;br /&gt;
: All libraries are not efficient. Many gems may need to be removed to problem to fix a problem with the code. This is a common scenario when many gems are installed. So performing bench marking and testing a gem with others that perform same task would help in picking the right gem.&lt;br /&gt;
&lt;br /&gt;
*'''Improve your algorithms before you try to improve your code'''&lt;br /&gt;
: Algorithmic improvements results in evident improvements in performance of the code. It is always ideal to design an efficient algorithm without unwanted method calls.&lt;br /&gt;
&lt;br /&gt;
*'''Test the most frequently occurring case first'''&lt;br /&gt;
: While using if statements or a case statement always test the cases that occur most frequently. This allows less code to run before a decision is made.  It may not seem like much but over several hundred or thousand runs through the decision logic you’ll notice a definite performance gain.&lt;br /&gt;
&lt;br /&gt;
*'''Optimize the way you access global constants'''&lt;br /&gt;
: While accessing the global constants one should use namespace before the constants to avoid entire library search for the constant.&lt;br /&gt;
 &lt;br /&gt;
*'''Use explicit returns'''&lt;br /&gt;
: Even though the result of last operation is returned for a method, using explicit returns would speed up the code. Explicit returns are faster, especially in older Ruby versions such as 1.8.x.&lt;br /&gt;
&lt;br /&gt;
=== Documentation Guidelines&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/api_documentation_guidelines.html&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Documentation comments&amp;lt;ref&amp;gt;http://www.jetbrains.com/ruby/webhelp/documenting-source-code-in-rubymine.html&amp;lt;/ref&amp;gt; can be created in accordance with [http://rdoc.sourceforge.net/ RDoc] and [http://yardoc.org/ YARD] syntax. Note that RDoc highlighting in documentation comments can be turned enabled or disabled in the Appearance page of the editor settings.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The most common Documentation guidelines are listed below.&lt;br /&gt;
*Write simple, declarative sentences. Brevity is a plus: get to the point.&lt;br /&gt;
*Write in present tense: &amp;quot;Returns a hash that...&amp;quot;, rather than &amp;quot;Returned a hash that...&amp;quot; or &amp;quot;Will return a hash that...&amp;quot;.&lt;br /&gt;
*Start comments in upper case. Follow regular punctuation rules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Declares an attribute reader backed by an internally-named &lt;br /&gt;
# instance variable.&lt;br /&gt;
def attr_internal_reader(*attrs)&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Communicate to the reader the current way of doing things, both explicitly and implicitly. Use the idioms recommended in edge. Reorder sections to emphasize favored approaches if needed, etc. The documentation should be a model for best practices and canonical, modern Rails usage.&lt;br /&gt;
&lt;br /&gt;
Documentation has to be concise but comprehensive. Explore and document edge cases.&lt;br /&gt;
&lt;br /&gt;
=== Layout Guidelines&amp;lt;ref&amp;gt;http://www.caliban.org/ruby/rubyguide.shtml&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Designing the layout of any application determines the readability factor for other developers.&lt;br /&gt;
Most followed order of code is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
header block with author's name, Perforce Id tag and a brief description of what the program or library is for.&lt;br /&gt;
require statements&lt;br /&gt;
include statements&lt;br /&gt;
class and module definitions&lt;br /&gt;
main program section&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Spreading Code Out and Lining it Up'''&lt;br /&gt;
:This is very important for readability. Basically the principle is to:&lt;br /&gt;
:*separate each component part by white space.&lt;br /&gt;
:*align everything meaningfully.&lt;br /&gt;
:As such one can easily scan up and down the code and see the patterns. This is very important not only for understanding the code, but also for looking for anomalies and as a tool for rationalizing and consolidating the code.&lt;br /&gt;
:Code that has a lot of 'noise' - a lot of unnecessary variation and untidiness - is code that one can waste a lot of time working on. Well written and formatted code is code that is easy and quick to work with. It is code that allows one to easily 'see the wood from the trees'.&lt;br /&gt;
&lt;br /&gt;
== '''Code Analysis Tools''' ==&lt;br /&gt;
&lt;br /&gt;
Ruby itself goes a long way towards helping developers write clear code.&lt;br /&gt;
&lt;br /&gt;
*'''The Ruby debugger''' is a library loaded into Ruby at run-time. &lt;br /&gt;
This is done as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby -r debug [&lt;br /&gt;
            options&lt;br /&gt;
            ] [&lt;br /&gt;
            programfile&lt;br /&gt;
            ] [&lt;br /&gt;
            arguments&lt;br /&gt;
            ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debugger can do all the usual things one would expect it to, such as set breakpoints, step into and over code, print out the call stack, etc.&lt;br /&gt;
&lt;br /&gt;
While tools for the mainstream languages such as Java and C++ have reached a certain maturity, tools for Ruby are still growing. And they might be needed more and more as Ruby's usage spreads from early adopters to the early majority, and SLOC (Source Lines Of Code) continues to increase. Automatic tools&amp;lt;ref&amp;gt;http://www.infoq.com/news/2009/09/code-quality-metric-fu&amp;lt;/ref&amp;gt; can be used to detect several types of problems including inconsistent style, long methods and repeated code.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/roodi/roodi/tree/master '''Roodi'''] (Ruby Object Oriented Design Inferometer) - this parses Ruby code and warns about design issues from the list  configured, ie: Class line count check, for loop check, parameter number check, cyclomatic checks and 10 other checks&lt;br /&gt;
*[https://github.com/troessner/reek '''Reek'''] - similar in concept to Roodi&lt;br /&gt;
*[https://github.com/devver/saikuro '''Saikuro'''] - designed to check cyclomatic complexity&lt;br /&gt;
*[https://github.com/seattlerb/flog '''Flog'''] - created by Ryan Davis, this computes a score of code written: the higher the score is, the worse your code is. ABC metrics (Assignments, Branches and Calls) are taken into account to compute the score&lt;br /&gt;
*[http://www.harukizaemon.com/simian/ '''Simian'''] - a similarity analyzer, this can be used for duplication identification (a $99 license is needed for commercial use)&lt;br /&gt;
*[https://github.com/seattlerb/flay '''Flay'''] - this is another free tool from Ryan Davis that finds structural similarities in code&lt;br /&gt;
&lt;br /&gt;
[[File:Code Analysis Outputs.png|frame|none|alt=Code Analysis Tool Results|Code Analysis Tool Results]]&lt;br /&gt;
&lt;br /&gt;
== '''Summary''' ==&lt;br /&gt;
Ruby developers should follow a certain criteria or guidelines during software development. Coding standards are set of rules, guidelines and regulations on the manner of writing a code that helps programmers and developers read and understand quickly the source code that conforms to style and help avoid introducing misunderstanding and faults.&lt;br /&gt;
&lt;br /&gt;
Particularly in Ruby development, coding standards are extremely important; therefore Ruby developers should put an importance to them. This is because these standards offer higher uniformity and consistency when writing code by different programmers. This could result in a code that's simple to know and preserve, thus reducing the project’s overall expenses.&lt;br /&gt;
&lt;br /&gt;
Some of the benefits of using coding standards are:&lt;br /&gt;
&lt;br /&gt;
*Easy to understand and maintained&lt;br /&gt;
*Boost the code’s readability&lt;br /&gt;
*Maintainable applications&lt;br /&gt;
*Eradicates complexity&lt;br /&gt;
*Separate documents look more appropriate&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://www.caliban.org/ruby/rubyguide.shtml&lt;br /&gt;
*https://github.com/styleguide/ruby&lt;br /&gt;
*http://www.ruby-doc.org/docs/ProgrammingRuby/&lt;br /&gt;
*https://www.ruby-lang.org/en/documentation/&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78461</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w23 ph</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78461"/>
		<updated>2013-09-23T18:17:28Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* See Also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby Coding Guidelines''' ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] Coding Guidelines include best practices followed generally for most of the [http://en.wikipedia.org/wiki/Category:Object-oriented_programming_languages object oriented programming languages] as Ruby is entirely 'Object Oriented'. Also known as 'Ruby Coding conventions', these are a set of guidelines that recommend programming style, practices and methods for each aspect of a piece of program written in Ruby. &lt;br /&gt;
&lt;br /&gt;
Software programmers are highly recommended to follow these guidelines to help improve the readability of their source code and make software maintenance easier. Naming conventions, class and member design principles, maintainability, performance, documentation and layout are the important areas where these guidelines have to be followed. More important than the reasons for having a guideline is actually adhering to it consistently.  Having a coding guideline documented and available means nothing if developers are not using it consistently.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Types of Guidelines''' ==&lt;br /&gt;
Coding guidelines in Ruby can be defined individually for major sections that code consists of. Naming , Class Design , Member Design , Maintainability, Performance, Documentation and Layout guidelines are illustrated below. These guidelines contain sections common to all of these as well as sections which apply to each one individually.&lt;br /&gt;
&lt;br /&gt;
=== Naming Guidelines&amp;lt;ref&amp;gt;http://itsignals.cascadia.com.au/?p=7&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Ruby uses the first character of the name to help it determine it’s intended use.&lt;br /&gt;
The standard Ruby file extension is .rb, although many people working on [http://en.wikipedia.org/wiki/Unix UNIX]-like systems don't bother with it for stand-alone scripts. Whether or not one uses it for scripts is up to them, but they will need to use it for library files or they will not be found by the interpreter.&lt;br /&gt;
&lt;br /&gt;
*'''Local Variables'''&lt;br /&gt;
:Should use lowercase letter followed by other characters. Naming convention states that it is better to use underscores rather than [http://en.wikipedia.org/wiki/CamelCase camelBack] for multiple word names, e.g. average, variable_xyz&lt;br /&gt;
*'''Instance Variables'''&lt;br /&gt;
:Instance variables are defined using the single &amp;quot;at&amp;quot; sign (@) followed by a name. It is suggested that a lowercase letter should succeed @, e.g. @color &lt;br /&gt;
*'''Instance Methods'''&lt;br /&gt;
:Method names should start with a lowercase letter, and may be followed by digits, underscores, and letters. The name should possibly be a verb e.g. move, display_details&lt;br /&gt;
*'''Class Variables'''&lt;br /&gt;
:Class variable names start with a double &amp;quot;at&amp;quot; sign (@@) and may be followed by digits, underscores, and letters, e.g. @@color&lt;br /&gt;
*'''Constant''' &lt;br /&gt;
:Constant names usually start with an uppercase letter followed by other characters. Constant objects are by convention named using all uppercase letters and underscores between words, e.g. THIS_IS_A_CONSTANT&lt;br /&gt;
*'''Class and Module''' &lt;br /&gt;
:Class names are recommended to be be nouns. In the case of modules, it's harder to make a clear recommendation. The names of [http://en.wikipedia.org/wiki/Mixin mix-ins] (which are just modules), however,  should probably be adjectives, such as the standard [http://en.wikibooks.org/wiki/Ruby_Programming/Reference/Objects/Enumerable Enumerable] and [http://www.ruby-doc.org/core-2.0.0/Comparable.html Comparable] modules. Class and module names starts with an uppercase letter, by convention they are named using MixedCase, e.g. module Encryption, class MixedCase&lt;br /&gt;
*'''Global Variables'''&lt;br /&gt;
:Starts with a dollar ($) sign followed by other characters, e.g. $global&lt;br /&gt;
&lt;br /&gt;
Considering customer order information as the data being used for an application, below naming guidelines give an idea of good class/table/file names.&lt;br /&gt;
*'''Model Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Table: orders&lt;br /&gt;
Class: Order&lt;br /&gt;
File: /app/models/order.rb&lt;br /&gt;
Primary Key: id&lt;br /&gt;
Foreign Key: customer_id&lt;br /&gt;
Link Tables: items_orders&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Controller Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class: OrdersController&lt;br /&gt;
File: /app/controllers/orders_controller.rb&lt;br /&gt;
Layout: /app/layouts/orders.html.erb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''View Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Helper: /app/helpers/orders_helper.rb&lt;br /&gt;
Helper Module: OrdersHelper&lt;br /&gt;
Views: /app/views/orders/… (list.html.erb for example)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Tests Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Unit: /test/unit/order_test.rb&lt;br /&gt;
Functional: /test/functional/orders_controller_test.rb&lt;br /&gt;
Fixtures: /test/fixtures/orders.yml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Class Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A class in Ruby always starts with the keyword class followed by the name of the class. The name should always be in initial capitals. Class Customer can be displayed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Customer&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A class is terminated by using the keyword end. All the data members in the class are between the class definition and the end keyword. &lt;br /&gt;
&lt;br /&gt;
Ruby blurs the distinction between design and implementation. Ideas that have to be expressed at the design level in other languages can be implemented directly in Ruby. To help in this process, Ruby has support for some design-level strategies. These strategies can be used to design classes accordingly as suitable for different types of  applications.&lt;br /&gt;
&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Visitor_pattern The Visitor pattern]''' is a way of traversing a collection without having to know the internal organization of that collection.&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Delegation_pattern Delegation]''' is a way of composing classes more flexibly and dynamically than can be done using standard inheritance.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Singleton_pattern Singleton pattern]''' is a way of ensuring that only one instantiation of a particular class exists at a time.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Observer_pattern Observer pattern]''' implements a protocol allowing one object to notify a set of interested objects when certain changes have occurred.&lt;br /&gt;
&lt;br /&gt;
Normally, all four of these strategies require explicit code each time they're implemented. With Ruby, they can be abstracted into a library and reused freely and transparently.&lt;br /&gt;
&lt;br /&gt;
=== Member Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
While defining class members, it is very important to keep in mind the access restrictions. Scope and life-time of class members are different for different restrictions, as illustrated below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public&lt;br /&gt;
totally accessible.&lt;br /&gt;
protected&lt;br /&gt;
accessible only by instances of class and direct descendants. Even through hasA relationships. (see below)&lt;br /&gt;
private&lt;br /&gt;
accessible only by instances of class (must be called nekkid no “self.” or anything else).&lt;br /&gt;
class A&lt;br /&gt;
  # Restriction used w/o arguments set the default access control.&lt;br /&gt;
  protected&lt;br /&gt;
&lt;br /&gt;
  def protected_method&lt;br /&gt;
    # nothing&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class B &amp;lt; A&lt;br /&gt;
  def test_protected&lt;br /&gt;
    myA = A.new&lt;br /&gt;
    myA.protected_method&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Used with arguments, sets the access of the named methods and constants.&lt;br /&gt;
  public :test_protected&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
b = B.new.test_protected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Maintainability Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
Maintainability guidelines are important to programmers for a number of reasons:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
*40%-80% of the lifetime cost of a piece of software goes to maintenance.&lt;br /&gt;
*Hardly any software is maintained for its whole life by the original author. &lt;br /&gt;
*Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. &lt;br /&gt;
*If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
The following guidelines are to be followed to improve the software maintainability&lt;br /&gt;
* '''Profile your code regularly'''&lt;br /&gt;
: If you profile your code regularly you’ll be able to tell if the latest change to the code will have an adverse effect on performance.  Integrate profiling into your testing process and make it automated to ensure that it’s not forgotten.  Like unit testing and BDD([http://en.wikipedia.org/wiki/Behavior-driven_development Behavior-driven development]) profiling goes a long way.&lt;br /&gt;
&lt;br /&gt;
=== Performance Guidelines&amp;lt;ref&amp;gt;http://blog.monitis.com/index.php/2012/02/08/20-ruby-performance-tips/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
The key parameter on which a software application is rated is by its performance. It is the time taken by the application to respond to a user's request. Performance of ruby can be improved significantly by following certain coding guidelines, as below.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid nesting loops more than three levels deep'''&lt;br /&gt;
: Nesting affects the performance of the code proportionally with the increasing levels in loops. Limiting nesting to three levels is one good practice to keep the code's performance well.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary variable assignments'''&lt;br /&gt;
: New programmers, often use unwanted variables in code.  A great example is when someone defines a variable to store a return value and then returns that variable; just return the value directly.&lt;br /&gt;
&lt;br /&gt;
*'''Reduce usage of disk I/O'''&lt;br /&gt;
: Disk I/O is a very costly operation as far as computing is concerned. Keeping it to the minimal improves the application response time drastically. Using disk I/O, makes the application extremely slow. Using storage systems such as memcached reduces disk I/O operations to a great extent as lot of data is kept in memory. The speed improvement while using a memory caching system is tremendous.&lt;br /&gt;
&lt;br /&gt;
*'''Use Ruby Enterprise Edition'''&lt;br /&gt;
: Ruby Enterprise edition provides up to [http://www.rubyenterpriseedition.com/faq.html#thirty_three_percent_mem_reduction 33% lower memory] usage.  Though, to get benefited by this performance one needs to follow their guidelines.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid method calls as much as possible'''&lt;br /&gt;
: Method calls are expensive operations in ruby. They should be avoided to keep up the performance of the application.&lt;br /&gt;
&lt;br /&gt;
*'''Use interpolated strings instead of concatenated strings'''&lt;br /&gt;
: Concatenated strings calls a method to get executed. So, it affects the performance as it is one of the most frequently used operation. Its better to replace them with Interpolated strings which runs faster as it doesn't invoke a method call.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
put “Hello there, #{name}!”vs.puts “Hello there, ” &amp;lt;&amp;lt; name = “!”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Destructive operations are faster'''&lt;br /&gt;
: Ruby’s in-place methods that which modifies the actual value than working on a copy of the data are much faster. But this should be handled carefully as original data gets disturbed.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary calls to uniq on arrays'''&lt;br /&gt;
: In many cases methods are already calling uniq on an array and there’s no need for you to call it yet again.&lt;br /&gt;
&lt;br /&gt;
*'''For loops are faster than .each'''&lt;br /&gt;
: .each uses an enumeration object behind the scene which adds a delay in execution. Using for instead of .each would improve performance but for short loops only.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/6406112/why-are-ruby-method-calls-particularly-slow-in-comparison-to-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Use x.blank? over x.nil? || x.empty?'''&lt;br /&gt;
: When using ActionPack there’s no need for x.nil? or x.empty?; x.blank? checks for both of these.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid calls to parse_date and strftime'''&lt;br /&gt;
: Both these calls are very expensive. using regular expressions would improve the time.&lt;br /&gt;
&lt;br /&gt;
*'''Know your gems'''&lt;br /&gt;
: All libraries are not efficient. Many gems may need to be removed to problem to fix a problem with the code. This is a common scenario when many gems are installed. So performing bench marking and testing a gem with others that perform same task would help in picking the right gem.&lt;br /&gt;
&lt;br /&gt;
*'''Improve your algorithms before you try to improve your code'''&lt;br /&gt;
: Algorithmic improvements results in evident improvements in performance of the code. It is always ideal to design an efficient algorithm without unwanted method calls.&lt;br /&gt;
&lt;br /&gt;
*'''Test the most frequently occurring case first'''&lt;br /&gt;
: While using if statements or a case statement always test the cases that occur most frequently. This allows less code to run before a decision is made.  It may not seem like much but over several hundred or thousand runs through the decision logic you’ll notice a definite performance gain.&lt;br /&gt;
&lt;br /&gt;
*'''Optimize the way you access global constants'''&lt;br /&gt;
: While accessing the global constants one should use namespace before the constants to avoid entire library search for the constant.&lt;br /&gt;
 &lt;br /&gt;
*'''Use explicit returns'''&lt;br /&gt;
: Even though the result of last operation is returned for a method, using explicit returns would speed up the code. Explicit returns are faster, especially in older Ruby versions such as 1.8.x.&lt;br /&gt;
&lt;br /&gt;
=== Documentation Guidelines&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/api_documentation_guidelines.html&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Documentation comments&amp;lt;ref&amp;gt;http://www.jetbrains.com/ruby/webhelp/documenting-source-code-in-rubymine.html&amp;lt;/ref&amp;gt; can be created in accordance with [http://rdoc.sourceforge.net/ RDoc] and [http://yardoc.org/ YARD] syntax. Note that RDoc highlighting in documentation comments can be turned enabled or disabled in the Appearance page of the editor settings.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The most common Documentation guidelines are listed below.&lt;br /&gt;
*Write simple, declarative sentences. Brevity is a plus: get to the point.&lt;br /&gt;
*Write in present tense: &amp;quot;Returns a hash that...&amp;quot;, rather than &amp;quot;Returned a hash that...&amp;quot; or &amp;quot;Will return a hash that...&amp;quot;.&lt;br /&gt;
*Start comments in upper case. Follow regular punctuation rules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Declares an attribute reader backed by an internally-named &lt;br /&gt;
# instance variable.&lt;br /&gt;
def attr_internal_reader(*attrs)&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Communicate to the reader the current way of doing things, both explicitly and implicitly. Use the idioms recommended in edge. Reorder sections to emphasize favored approaches if needed, etc. The documentation should be a model for best practices and canonical, modern Rails usage.&lt;br /&gt;
&lt;br /&gt;
Documentation has to be concise but comprehensive. Explore and document edge cases.&lt;br /&gt;
&lt;br /&gt;
=== Layout Guidelines&amp;lt;ref&amp;gt;http://www.caliban.org/ruby/rubyguide.shtml&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Designing the layout of any application determines the readability factor for other developers.&lt;br /&gt;
Most followed order of code is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
header block with author's name, Perforce Id tag and a brief description of what the program or library is for.&lt;br /&gt;
require statements&lt;br /&gt;
include statements&lt;br /&gt;
class and module definitions&lt;br /&gt;
main program section&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Spreading Code Out and Lining it Up'''&lt;br /&gt;
:This is very important for readability. Basically the principle is to:&lt;br /&gt;
:*separate each component part by white space.&lt;br /&gt;
:*align everything meaningfully.&lt;br /&gt;
:As such one can easily scan up and down the code and see the patterns. This is very important not only for understanding the code, but also for looking for anomalies and as a tool for rationalizing and consolidating the code.&lt;br /&gt;
:Code that has a lot of 'noise' - a lot of unnecessary variation and untidiness - is code that one can waste a lot of time working on. Well written and formatted code is code that is easy and quick to work with. It is code that allows one to easily 'see the wood from the trees'.&lt;br /&gt;
&lt;br /&gt;
== '''Code Analysis Tools''' ==&lt;br /&gt;
&lt;br /&gt;
Ruby itself goes a long way towards helping developers write clear code.&lt;br /&gt;
&lt;br /&gt;
*'''The Ruby debugger''' is a library loaded into Ruby at run-time. &lt;br /&gt;
This is done as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby -r debug [&lt;br /&gt;
            options&lt;br /&gt;
            ] [&lt;br /&gt;
            programfile&lt;br /&gt;
            ] [&lt;br /&gt;
            arguments&lt;br /&gt;
            ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debugger can do all the usual things one would expect it to, such as set breakpoints, step into and over code, print out the call stack, etc.&lt;br /&gt;
&lt;br /&gt;
While tools for the mainstream languages such as Java and C++ have reached a certain maturity, tools for Ruby are still growing. And they might be needed more and more as Ruby's usage spreads from early adopters to the early majority, and SLOC (Source Lines Of Code) continues to increase. Automatic tools&amp;lt;ref&amp;gt;http://www.infoq.com/news/2009/09/code-quality-metric-fu&amp;lt;/ref&amp;gt; can be used to detect several types of problems including inconsistent style, long methods and repeated code.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/roodi/roodi/tree/master '''Roodi'''] (Ruby Object Oriented Design Inferometer) - this parses Ruby code and warns about design issues from the list  configured, ie: Class line count check, for loop check, parameter number check, cyclomatic checks and 10 other checks&lt;br /&gt;
*[https://github.com/troessner/reek '''Reek'''] - similar in concept to Roodi&lt;br /&gt;
*[https://github.com/devver/saikuro '''Saikuro'''] - designed to check cyclomatic complexity&lt;br /&gt;
*[https://github.com/seattlerb/flog '''Flog'''] - created by Ryan Davis, this computes a score of code written: the higher the score is, the worse your code is. ABC metrics (Assignments, Branches and Calls) are taken into account to compute the score&lt;br /&gt;
*[http://www.harukizaemon.com/simian/ '''Simian'''] - a similarity analyzer, this can be used for duplication identification (a $99 license is needed for commercial use)&lt;br /&gt;
*[https://github.com/seattlerb/flay '''Flay'''] - this is another free tool from Ryan Davis that finds structural similarities in code&lt;br /&gt;
&lt;br /&gt;
[[File:Code Analysis Outputs.png|frame|none|alt=Code Analysis Tool Results|Code Analysis Tool Results]]&lt;br /&gt;
&lt;br /&gt;
== '''Summary''' ==&lt;br /&gt;
Ruby developers should follow a certain criteria or guidelines during software development. Coding standards are set of rules, guidelines and regulations on the manner of writing a code that helps programmers and developers read and understand quickly the source code that conforms to style and help avoid introducing misunderstanding and faults.&lt;br /&gt;
&lt;br /&gt;
Particularly in Ruby development, coding standards are extremely important; therefore Ruby developers should put an importance to them. This is because these standards offer higher uniformity and consistency when writing code by different programmers. This could result in a code that's simple to know and preserve, thus reducing the project’s overall expenses.&lt;br /&gt;
&lt;br /&gt;
Some of the benefits of using coding standards are:&lt;br /&gt;
&lt;br /&gt;
*Easy to understand and maintained&lt;br /&gt;
*Boost the code’s readability&lt;br /&gt;
*Maintainable applications&lt;br /&gt;
*Eradicates complexity&lt;br /&gt;
*Separate documents look more appropriate&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://www.caliban.org/ruby/rubyguide.shtml&lt;br /&gt;
*https://github.com/styleguide/ruby&lt;br /&gt;
*http://www.ruby-doc.org/docs/ProgrammingRuby/&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78460</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w23 ph</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78460"/>
		<updated>2013-09-23T18:13:09Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* Performance Guidelineshttp://blog.monitis.com/index.php/2012/02/08/20-ruby-performance-tips/ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby Coding Guidelines''' ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] Coding Guidelines include best practices followed generally for most of the [http://en.wikipedia.org/wiki/Category:Object-oriented_programming_languages object oriented programming languages] as Ruby is entirely 'Object Oriented'. Also known as 'Ruby Coding conventions', these are a set of guidelines that recommend programming style, practices and methods for each aspect of a piece of program written in Ruby. &lt;br /&gt;
&lt;br /&gt;
Software programmers are highly recommended to follow these guidelines to help improve the readability of their source code and make software maintenance easier. Naming conventions, class and member design principles, maintainability, performance, documentation and layout are the important areas where these guidelines have to be followed. More important than the reasons for having a guideline is actually adhering to it consistently.  Having a coding guideline documented and available means nothing if developers are not using it consistently.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Types of Guidelines''' ==&lt;br /&gt;
Coding guidelines in Ruby can be defined individually for major sections that code consists of. Naming , Class Design , Member Design , Maintainability, Performance, Documentation and Layout guidelines are illustrated below. These guidelines contain sections common to all of these as well as sections which apply to each one individually.&lt;br /&gt;
&lt;br /&gt;
=== Naming Guidelines&amp;lt;ref&amp;gt;http://itsignals.cascadia.com.au/?p=7&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Ruby uses the first character of the name to help it determine it’s intended use.&lt;br /&gt;
The standard Ruby file extension is .rb, although many people working on [http://en.wikipedia.org/wiki/Unix UNIX]-like systems don't bother with it for stand-alone scripts. Whether or not one uses it for scripts is up to them, but they will need to use it for library files or they will not be found by the interpreter.&lt;br /&gt;
&lt;br /&gt;
*'''Local Variables'''&lt;br /&gt;
:Should use lowercase letter followed by other characters. Naming convention states that it is better to use underscores rather than [http://en.wikipedia.org/wiki/CamelCase camelBack] for multiple word names, e.g. average, variable_xyz&lt;br /&gt;
*'''Instance Variables'''&lt;br /&gt;
:Instance variables are defined using the single &amp;quot;at&amp;quot; sign (@) followed by a name. It is suggested that a lowercase letter should succeed @, e.g. @color &lt;br /&gt;
*'''Instance Methods'''&lt;br /&gt;
:Method names should start with a lowercase letter, and may be followed by digits, underscores, and letters. The name should possibly be a verb e.g. move, display_details&lt;br /&gt;
*'''Class Variables'''&lt;br /&gt;
:Class variable names start with a double &amp;quot;at&amp;quot; sign (@@) and may be followed by digits, underscores, and letters, e.g. @@color&lt;br /&gt;
*'''Constant''' &lt;br /&gt;
:Constant names usually start with an uppercase letter followed by other characters. Constant objects are by convention named using all uppercase letters and underscores between words, e.g. THIS_IS_A_CONSTANT&lt;br /&gt;
*'''Class and Module''' &lt;br /&gt;
:Class names are recommended to be be nouns. In the case of modules, it's harder to make a clear recommendation. The names of [http://en.wikipedia.org/wiki/Mixin mix-ins] (which are just modules), however,  should probably be adjectives, such as the standard [http://en.wikibooks.org/wiki/Ruby_Programming/Reference/Objects/Enumerable Enumerable] and [http://www.ruby-doc.org/core-2.0.0/Comparable.html Comparable] modules. Class and module names starts with an uppercase letter, by convention they are named using MixedCase, e.g. module Encryption, class MixedCase&lt;br /&gt;
*'''Global Variables'''&lt;br /&gt;
:Starts with a dollar ($) sign followed by other characters, e.g. $global&lt;br /&gt;
&lt;br /&gt;
Considering customer order information as the data being used for an application, below naming guidelines give an idea of good class/table/file names.&lt;br /&gt;
*'''Model Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Table: orders&lt;br /&gt;
Class: Order&lt;br /&gt;
File: /app/models/order.rb&lt;br /&gt;
Primary Key: id&lt;br /&gt;
Foreign Key: customer_id&lt;br /&gt;
Link Tables: items_orders&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Controller Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class: OrdersController&lt;br /&gt;
File: /app/controllers/orders_controller.rb&lt;br /&gt;
Layout: /app/layouts/orders.html.erb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''View Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Helper: /app/helpers/orders_helper.rb&lt;br /&gt;
Helper Module: OrdersHelper&lt;br /&gt;
Views: /app/views/orders/… (list.html.erb for example)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Tests Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Unit: /test/unit/order_test.rb&lt;br /&gt;
Functional: /test/functional/orders_controller_test.rb&lt;br /&gt;
Fixtures: /test/fixtures/orders.yml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Class Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A class in Ruby always starts with the keyword class followed by the name of the class. The name should always be in initial capitals. Class Customer can be displayed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Customer&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A class is terminated by using the keyword end. All the data members in the class are between the class definition and the end keyword. &lt;br /&gt;
&lt;br /&gt;
Ruby blurs the distinction between design and implementation. Ideas that have to be expressed at the design level in other languages can be implemented directly in Ruby. To help in this process, Ruby has support for some design-level strategies. These strategies can be used to design classes accordingly as suitable for different types of  applications.&lt;br /&gt;
&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Visitor_pattern The Visitor pattern]''' is a way of traversing a collection without having to know the internal organization of that collection.&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Delegation_pattern Delegation]''' is a way of composing classes more flexibly and dynamically than can be done using standard inheritance.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Singleton_pattern Singleton pattern]''' is a way of ensuring that only one instantiation of a particular class exists at a time.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Observer_pattern Observer pattern]''' implements a protocol allowing one object to notify a set of interested objects when certain changes have occurred.&lt;br /&gt;
&lt;br /&gt;
Normally, all four of these strategies require explicit code each time they're implemented. With Ruby, they can be abstracted into a library and reused freely and transparently.&lt;br /&gt;
&lt;br /&gt;
=== Member Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
While defining class members, it is very important to keep in mind the access restrictions. Scope and life-time of class members are different for different restrictions, as illustrated below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public&lt;br /&gt;
totally accessible.&lt;br /&gt;
protected&lt;br /&gt;
accessible only by instances of class and direct descendants. Even through hasA relationships. (see below)&lt;br /&gt;
private&lt;br /&gt;
accessible only by instances of class (must be called nekkid no “self.” or anything else).&lt;br /&gt;
class A&lt;br /&gt;
  # Restriction used w/o arguments set the default access control.&lt;br /&gt;
  protected&lt;br /&gt;
&lt;br /&gt;
  def protected_method&lt;br /&gt;
    # nothing&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class B &amp;lt; A&lt;br /&gt;
  def test_protected&lt;br /&gt;
    myA = A.new&lt;br /&gt;
    myA.protected_method&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Used with arguments, sets the access of the named methods and constants.&lt;br /&gt;
  public :test_protected&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
b = B.new.test_protected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Maintainability Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
Maintainability guidelines are important to programmers for a number of reasons:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
*40%-80% of the lifetime cost of a piece of software goes to maintenance.&lt;br /&gt;
*Hardly any software is maintained for its whole life by the original author. &lt;br /&gt;
*Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. &lt;br /&gt;
*If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
The following guidelines are to be followed to improve the software maintainability&lt;br /&gt;
* '''Profile your code regularly'''&lt;br /&gt;
: If you profile your code regularly you’ll be able to tell if the latest change to the code will have an adverse effect on performance.  Integrate profiling into your testing process and make it automated to ensure that it’s not forgotten.  Like unit testing and BDD([http://en.wikipedia.org/wiki/Behavior-driven_development Behavior-driven development]) profiling goes a long way.&lt;br /&gt;
&lt;br /&gt;
=== Performance Guidelines&amp;lt;ref&amp;gt;http://blog.monitis.com/index.php/2012/02/08/20-ruby-performance-tips/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
The key parameter on which a software application is rated is by its performance. It is the time taken by the application to respond to a user's request. Performance of ruby can be improved significantly by following certain coding guidelines, as below.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid nesting loops more than three levels deep'''&lt;br /&gt;
: Nesting affects the performance of the code proportionally with the increasing levels in loops. Limiting nesting to three levels is one good practice to keep the code's performance well.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary variable assignments'''&lt;br /&gt;
: New programmers, often use unwanted variables in code.  A great example is when someone defines a variable to store a return value and then returns that variable; just return the value directly.&lt;br /&gt;
&lt;br /&gt;
*'''Reduce usage of disk I/O'''&lt;br /&gt;
: Disk I/O is a very costly operation as far as computing is concerned. Keeping it to the minimal improves the application response time drastically. Using disk I/O, makes the application extremely slow. Using storage systems such as memcached reduces disk I/O operations to a great extent as lot of data is kept in memory. The speed improvement while using a memory caching system is tremendous.&lt;br /&gt;
&lt;br /&gt;
*'''Use Ruby Enterprise Edition'''&lt;br /&gt;
: Ruby Enterprise edition provides up to [http://www.rubyenterpriseedition.com/faq.html#thirty_three_percent_mem_reduction 33% lower memory] usage.  Though, to get benefited by this performance one needs to follow their guidelines.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid method calls as much as possible'''&lt;br /&gt;
: Method calls are expensive operations in ruby. They should be avoided to keep up the performance of the application.&lt;br /&gt;
&lt;br /&gt;
*'''Use interpolated strings instead of concatenated strings'''&lt;br /&gt;
: Concatenated strings calls a method to get executed. So, it affects the performance as it is one of the most frequently used operation. Its better to replace them with Interpolated strings which runs faster as it doesn't invoke a method call.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
put “Hello there, #{name}!”vs.puts “Hello there, ” &amp;lt;&amp;lt; name = “!”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Destructive operations are faster'''&lt;br /&gt;
: Ruby’s in-place methods that which modifies the actual value than working on a copy of the data are much faster. But this should be handled carefully as original data gets disturbed.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary calls to uniq on arrays'''&lt;br /&gt;
: In many cases methods are already calling uniq on an array and there’s no need for you to call it yet again.&lt;br /&gt;
&lt;br /&gt;
*'''For loops are faster than .each'''&lt;br /&gt;
: .each uses an enumeration object behind the scene which adds a delay in execution. Using for instead of .each would improve performance but for short loops only.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/6406112/why-are-ruby-method-calls-particularly-slow-in-comparison-to-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Use x.blank? over x.nil? || x.empty?'''&lt;br /&gt;
: When using ActionPack there’s no need for x.nil? or x.empty?; x.blank? checks for both of these.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid calls to parse_date and strftime'''&lt;br /&gt;
: Both these calls are very expensive. using regular expressions would improve the time.&lt;br /&gt;
&lt;br /&gt;
*'''Know your gems'''&lt;br /&gt;
: All libraries are not efficient. Many gems may need to be removed to problem to fix a problem with the code. This is a common scenario when many gems are installed. So performing bench marking and testing a gem with others that perform same task would help in picking the right gem.&lt;br /&gt;
&lt;br /&gt;
*'''Improve your algorithms before you try to improve your code'''&lt;br /&gt;
: Algorithmic improvements results in evident improvements in performance of the code. It is always ideal to design an efficient algorithm without unwanted method calls.&lt;br /&gt;
&lt;br /&gt;
*'''Test the most frequently occurring case first'''&lt;br /&gt;
: While using if statements or a case statement always test the cases that occur most frequently. This allows less code to run before a decision is made.  It may not seem like much but over several hundred or thousand runs through the decision logic you’ll notice a definite performance gain.&lt;br /&gt;
&lt;br /&gt;
*'''Optimize the way you access global constants'''&lt;br /&gt;
: While accessing the global constants one should use namespace before the constants to avoid entire library search for the constant.&lt;br /&gt;
 &lt;br /&gt;
*'''Use explicit returns'''&lt;br /&gt;
: Even though the result of last operation is returned for a method, using explicit returns would speed up the code. Explicit returns are faster, especially in older Ruby versions such as 1.8.x.&lt;br /&gt;
&lt;br /&gt;
=== Documentation Guidelines&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/api_documentation_guidelines.html&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Documentation comments&amp;lt;ref&amp;gt;http://www.jetbrains.com/ruby/webhelp/documenting-source-code-in-rubymine.html&amp;lt;/ref&amp;gt; can be created in accordance with [http://rdoc.sourceforge.net/ RDoc] and [http://yardoc.org/ YARD] syntax. Note that RDoc highlighting in documentation comments can be turned enabled or disabled in the Appearance page of the editor settings.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The most common Documentation guidelines are listed below.&lt;br /&gt;
*Write simple, declarative sentences. Brevity is a plus: get to the point.&lt;br /&gt;
*Write in present tense: &amp;quot;Returns a hash that...&amp;quot;, rather than &amp;quot;Returned a hash that...&amp;quot; or &amp;quot;Will return a hash that...&amp;quot;.&lt;br /&gt;
*Start comments in upper case. Follow regular punctuation rules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Declares an attribute reader backed by an internally-named &lt;br /&gt;
# instance variable.&lt;br /&gt;
def attr_internal_reader(*attrs)&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Communicate to the reader the current way of doing things, both explicitly and implicitly. Use the idioms recommended in edge. Reorder sections to emphasize favored approaches if needed, etc. The documentation should be a model for best practices and canonical, modern Rails usage.&lt;br /&gt;
&lt;br /&gt;
Documentation has to be concise but comprehensive. Explore and document edge cases.&lt;br /&gt;
&lt;br /&gt;
=== Layout Guidelines&amp;lt;ref&amp;gt;http://www.caliban.org/ruby/rubyguide.shtml&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Designing the layout of any application determines the readability factor for other developers.&lt;br /&gt;
Most followed order of code is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
header block with author's name, Perforce Id tag and a brief description of what the program or library is for.&lt;br /&gt;
require statements&lt;br /&gt;
include statements&lt;br /&gt;
class and module definitions&lt;br /&gt;
main program section&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Spreading Code Out and Lining it Up'''&lt;br /&gt;
:This is very important for readability. Basically the principle is to:&lt;br /&gt;
:*separate each component part by white space.&lt;br /&gt;
:*align everything meaningfully.&lt;br /&gt;
:As such one can easily scan up and down the code and see the patterns. This is very important not only for understanding the code, but also for looking for anomalies and as a tool for rationalizing and consolidating the code.&lt;br /&gt;
:Code that has a lot of 'noise' - a lot of unnecessary variation and untidiness - is code that one can waste a lot of time working on. Well written and formatted code is code that is easy and quick to work with. It is code that allows one to easily 'see the wood from the trees'.&lt;br /&gt;
&lt;br /&gt;
== '''Code Analysis Tools''' ==&lt;br /&gt;
&lt;br /&gt;
Ruby itself goes a long way towards helping developers write clear code.&lt;br /&gt;
&lt;br /&gt;
*'''The Ruby debugger''' is a library loaded into Ruby at run-time. &lt;br /&gt;
This is done as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby -r debug [&lt;br /&gt;
            options&lt;br /&gt;
            ] [&lt;br /&gt;
            programfile&lt;br /&gt;
            ] [&lt;br /&gt;
            arguments&lt;br /&gt;
            ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debugger can do all the usual things one would expect it to, such as set breakpoints, step into and over code, print out the call stack, etc.&lt;br /&gt;
&lt;br /&gt;
While tools for the mainstream languages such as Java and C++ have reached a certain maturity, tools for Ruby are still growing. And they might be needed more and more as Ruby's usage spreads from early adopters to the early majority, and SLOC (Source Lines Of Code) continues to increase. Automatic tools&amp;lt;ref&amp;gt;http://www.infoq.com/news/2009/09/code-quality-metric-fu&amp;lt;/ref&amp;gt; can be used to detect several types of problems including inconsistent style, long methods and repeated code.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/roodi/roodi/tree/master '''Roodi'''] (Ruby Object Oriented Design Inferometer) - this parses Ruby code and warns about design issues from the list  configured, ie: Class line count check, for loop check, parameter number check, cyclomatic checks and 10 other checks&lt;br /&gt;
*[https://github.com/troessner/reek '''Reek'''] - similar in concept to Roodi&lt;br /&gt;
*[https://github.com/devver/saikuro '''Saikuro'''] - designed to check cyclomatic complexity&lt;br /&gt;
*[https://github.com/seattlerb/flog '''Flog'''] - created by Ryan Davis, this computes a score of code written: the higher the score is, the worse your code is. ABC metrics (Assignments, Branches and Calls) are taken into account to compute the score&lt;br /&gt;
*[http://www.harukizaemon.com/simian/ '''Simian'''] - a similarity analyzer, this can be used for duplication identification (a $99 license is needed for commercial use)&lt;br /&gt;
*[https://github.com/seattlerb/flay '''Flay'''] - this is another free tool from Ryan Davis that finds structural similarities in code&lt;br /&gt;
&lt;br /&gt;
[[File:Code Analysis Outputs.png|frame|none|alt=Code Analysis Tool Results|Code Analysis Tool Results]]&lt;br /&gt;
&lt;br /&gt;
== '''Summary''' ==&lt;br /&gt;
Ruby developers should follow a certain criteria or guidelines during software development. Coding standards are set of rules, guidelines and regulations on the manner of writing a code that helps programmers and developers read and understand quickly the source code that conforms to style and help avoid introducing misunderstanding and faults.&lt;br /&gt;
&lt;br /&gt;
Particularly in Ruby development, coding standards are extremely important; therefore Ruby developers should put an importance to them. This is because these standards offer higher uniformity and consistency when writing code by different programmers. This could result in a code that's simple to know and preserve, thus reducing the project’s overall expenses.&lt;br /&gt;
&lt;br /&gt;
Some of the benefits of using coding standards are:&lt;br /&gt;
&lt;br /&gt;
*Easy to understand and maintained&lt;br /&gt;
*Boost the code’s readability&lt;br /&gt;
*Maintainable applications&lt;br /&gt;
*Eradicates complexity&lt;br /&gt;
*Separate documents look more appropriate&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://www.caliban.org/ruby/rubyguide.shtml&lt;br /&gt;
*https://github.com/styleguide/ruby&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78459</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w23 ph</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78459"/>
		<updated>2013-09-23T17:58:28Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* Class Design Guidelines */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby Coding Guidelines''' ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] Coding Guidelines include best practices followed generally for most of the [http://en.wikipedia.org/wiki/Category:Object-oriented_programming_languages object oriented programming languages] as Ruby is entirely 'Object Oriented'. Also known as 'Ruby Coding conventions', these are a set of guidelines that recommend programming style, practices and methods for each aspect of a piece of program written in Ruby. &lt;br /&gt;
&lt;br /&gt;
Software programmers are highly recommended to follow these guidelines to help improve the readability of their source code and make software maintenance easier. Naming conventions, class and member design principles, maintainability, performance, documentation and layout are the important areas where these guidelines have to be followed. More important than the reasons for having a guideline is actually adhering to it consistently.  Having a coding guideline documented and available means nothing if developers are not using it consistently.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Types of Guidelines''' ==&lt;br /&gt;
Coding guidelines in Ruby can be defined individually for major sections that code consists of. Naming , Class Design , Member Design , Maintainability, Performance, Documentation and Layout guidelines are illustrated below. These guidelines contain sections common to all of these as well as sections which apply to each one individually.&lt;br /&gt;
&lt;br /&gt;
=== Naming Guidelines&amp;lt;ref&amp;gt;http://itsignals.cascadia.com.au/?p=7&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Ruby uses the first character of the name to help it determine it’s intended use.&lt;br /&gt;
The standard Ruby file extension is .rb, although many people working on [http://en.wikipedia.org/wiki/Unix UNIX]-like systems don't bother with it for stand-alone scripts. Whether or not one uses it for scripts is up to them, but they will need to use it for library files or they will not be found by the interpreter.&lt;br /&gt;
&lt;br /&gt;
*'''Local Variables'''&lt;br /&gt;
:Should use lowercase letter followed by other characters. Naming convention states that it is better to use underscores rather than [http://en.wikipedia.org/wiki/CamelCase camelBack] for multiple word names, e.g. average, variable_xyz&lt;br /&gt;
*'''Instance Variables'''&lt;br /&gt;
:Instance variables are defined using the single &amp;quot;at&amp;quot; sign (@) followed by a name. It is suggested that a lowercase letter should succeed @, e.g. @color &lt;br /&gt;
*'''Instance Methods'''&lt;br /&gt;
:Method names should start with a lowercase letter, and may be followed by digits, underscores, and letters. The name should possibly be a verb e.g. move, display_details&lt;br /&gt;
*'''Class Variables'''&lt;br /&gt;
:Class variable names start with a double &amp;quot;at&amp;quot; sign (@@) and may be followed by digits, underscores, and letters, e.g. @@color&lt;br /&gt;
*'''Constant''' &lt;br /&gt;
:Constant names usually start with an uppercase letter followed by other characters. Constant objects are by convention named using all uppercase letters and underscores between words, e.g. THIS_IS_A_CONSTANT&lt;br /&gt;
*'''Class and Module''' &lt;br /&gt;
:Class names are recommended to be be nouns. In the case of modules, it's harder to make a clear recommendation. The names of [http://en.wikipedia.org/wiki/Mixin mix-ins] (which are just modules), however,  should probably be adjectives, such as the standard [http://en.wikibooks.org/wiki/Ruby_Programming/Reference/Objects/Enumerable Enumerable] and [http://www.ruby-doc.org/core-2.0.0/Comparable.html Comparable] modules. Class and module names starts with an uppercase letter, by convention they are named using MixedCase, e.g. module Encryption, class MixedCase&lt;br /&gt;
*'''Global Variables'''&lt;br /&gt;
:Starts with a dollar ($) sign followed by other characters, e.g. $global&lt;br /&gt;
&lt;br /&gt;
Considering customer order information as the data being used for an application, below naming guidelines give an idea of good class/table/file names.&lt;br /&gt;
*'''Model Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Table: orders&lt;br /&gt;
Class: Order&lt;br /&gt;
File: /app/models/order.rb&lt;br /&gt;
Primary Key: id&lt;br /&gt;
Foreign Key: customer_id&lt;br /&gt;
Link Tables: items_orders&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Controller Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class: OrdersController&lt;br /&gt;
File: /app/controllers/orders_controller.rb&lt;br /&gt;
Layout: /app/layouts/orders.html.erb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''View Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Helper: /app/helpers/orders_helper.rb&lt;br /&gt;
Helper Module: OrdersHelper&lt;br /&gt;
Views: /app/views/orders/… (list.html.erb for example)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Tests Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Unit: /test/unit/order_test.rb&lt;br /&gt;
Functional: /test/functional/orders_controller_test.rb&lt;br /&gt;
Fixtures: /test/fixtures/orders.yml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Class Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A class in Ruby always starts with the keyword class followed by the name of the class. The name should always be in initial capitals. Class Customer can be displayed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Customer&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A class is terminated by using the keyword end. All the data members in the class are between the class definition and the end keyword. &lt;br /&gt;
&lt;br /&gt;
Ruby blurs the distinction between design and implementation. Ideas that have to be expressed at the design level in other languages can be implemented directly in Ruby. To help in this process, Ruby has support for some design-level strategies. These strategies can be used to design classes accordingly as suitable for different types of  applications.&lt;br /&gt;
&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Visitor_pattern The Visitor pattern]''' is a way of traversing a collection without having to know the internal organization of that collection.&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Delegation_pattern Delegation]''' is a way of composing classes more flexibly and dynamically than can be done using standard inheritance.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Singleton_pattern Singleton pattern]''' is a way of ensuring that only one instantiation of a particular class exists at a time.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Observer_pattern Observer pattern]''' implements a protocol allowing one object to notify a set of interested objects when certain changes have occurred.&lt;br /&gt;
&lt;br /&gt;
Normally, all four of these strategies require explicit code each time they're implemented. With Ruby, they can be abstracted into a library and reused freely and transparently.&lt;br /&gt;
&lt;br /&gt;
=== Member Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
While defining class members, it is very important to keep in mind the access restrictions. Scope and life-time of class members are different for different restrictions, as illustrated below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public&lt;br /&gt;
totally accessible.&lt;br /&gt;
protected&lt;br /&gt;
accessible only by instances of class and direct descendants. Even through hasA relationships. (see below)&lt;br /&gt;
private&lt;br /&gt;
accessible only by instances of class (must be called nekkid no “self.” or anything else).&lt;br /&gt;
class A&lt;br /&gt;
  # Restriction used w/o arguments set the default access control.&lt;br /&gt;
  protected&lt;br /&gt;
&lt;br /&gt;
  def protected_method&lt;br /&gt;
    # nothing&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class B &amp;lt; A&lt;br /&gt;
  def test_protected&lt;br /&gt;
    myA = A.new&lt;br /&gt;
    myA.protected_method&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Used with arguments, sets the access of the named methods and constants.&lt;br /&gt;
  public :test_protected&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
b = B.new.test_protected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Maintainability Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
Maintainability guidelines are important to programmers for a number of reasons:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
*40%-80% of the lifetime cost of a piece of software goes to maintenance.&lt;br /&gt;
*Hardly any software is maintained for its whole life by the original author. &lt;br /&gt;
*Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. &lt;br /&gt;
*If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
The following guidelines are to be followed to improve the software maintainability&lt;br /&gt;
* '''Profile your code regularly'''&lt;br /&gt;
: If you profile your code regularly you’ll be able to tell if the latest change to the code will have an adverse effect on performance.  Integrate profiling into your testing process and make it automated to ensure that it’s not forgotten.  Like unit testing and BDD([http://en.wikipedia.org/wiki/Behavior-driven_development Behavior-driven development]) profiling goes a long way.&lt;br /&gt;
&lt;br /&gt;
=== Performance Guidelines&amp;lt;ref&amp;gt;http://blog.monitis.com/index.php/2012/02/08/20-ruby-performance-tips/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
The key parameter on which a software application is rated is by its performance. It is the time taken by the application to respond to a user's request. Performance of ruby can be improved significantly by following certain coding guidelines, as below.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid nesting loops more than three levels deep'''&lt;br /&gt;
: Nesting affects the performance of the code proportionally with the increasing levels in loops. Limiting nesting to three levels is one good practice to keep the code's performance well.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary variable assignments'''&lt;br /&gt;
: New programmers, often use unwanted variables in code.  A great example is when someone defines a variable to store a return value and then returns that variable; just return the value directly.&lt;br /&gt;
&lt;br /&gt;
*'''Reduce usage of disk I/O'''&lt;br /&gt;
: Disk I/O is a very costly operation as far as computing is concerned. Keeping it to the minimal improves the application response time drastically. Using disk I/O, makes the application extremely slow. Using storage systems such as memcached reduces disk I/O operations to a great extent as lot of data is kept in memory. The speed improvement while using a memory caching system is tremendous.&lt;br /&gt;
&lt;br /&gt;
*'''Use Ruby Enterprise Edition'''&lt;br /&gt;
: Ruby Enterprise edition provides up to [http://www.rubyenterpriseedition.com/faq.html#thirty_three_percent_mem_reduction 33% lower memory] usage.  Though, to get benefited by this performance one needs to follow their guidelines.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid method calls as much as possible'''&lt;br /&gt;
: Method calls are expensive operations in ruby. They should be avoided to keep up the performance of the application.&lt;br /&gt;
&lt;br /&gt;
*'''Use interpolated strings instead of concatenated strings'''&lt;br /&gt;
: Concatenated strings calls a method to get executed. So, it affects the performance as it is one of the most frequently used operation. Its better to replace them with Interpolated strings which runs faster as it doesn't invoke a method call.&lt;br /&gt;
put “Hello there, #{name}!”vs.puts “Hello there, ” &amp;lt;&amp;lt; name = “!”&lt;br /&gt;
&lt;br /&gt;
*'''Destructive operations are faster'''&lt;br /&gt;
: Ruby’s in-place methods that which modifies the actual value than working on a copy of the data are much faster. But this should be handled carefully as original data gets disturbed.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary calls to uniq on arrays'''&lt;br /&gt;
: In many cases methods are already calling uniq on an array and there’s no need for you to call it yet again.&lt;br /&gt;
&lt;br /&gt;
*'''For loops are faster than .each'''&lt;br /&gt;
: .each uses an enumeration object behind the scene which adds a delay in execution. Using for instead of .each would improve performance but for short loops only.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/6406112/why-are-ruby-method-calls-particularly-slow-in-comparison-to-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Use x.blank? over x.nil? || x.empty?'''&lt;br /&gt;
: When using ActionPack there’s no need for x.nil? or x.empty?; x.blank? checks for both of these.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid calls to parse_date and strftime'''&lt;br /&gt;
: Both these calls are very expensive. using regular expressions would improve the time.&lt;br /&gt;
&lt;br /&gt;
*'''Know your gems'''&lt;br /&gt;
: All libraries are not efficient. Many gems may need to be removed to problem to fix a problem with the code. This is a common scenario when many gems are installed. So performing bench marking and testing a gem with others that perform same task would help in picking the right gem.&lt;br /&gt;
&lt;br /&gt;
*'''Improve your algorithms before you try to improve your code'''&lt;br /&gt;
: Algorithmic improvements results in evident improvements in performance of the code. It is always ideal to design an efficient algorithm without unwanted method calls.&lt;br /&gt;
&lt;br /&gt;
*'''Test the most frequently occurring case first'''&lt;br /&gt;
: While using if statements or a case statement always test the cases that occur most frequently. This allows less code to run before a decision is made.  It may not seem like much but over several hundred or thousand runs through the decision logic you’ll notice a definite performance gain.&lt;br /&gt;
&lt;br /&gt;
*'''Optimize the way you access global constants'''&lt;br /&gt;
: While accessing the global constants one should use namespace before the constants to avoid entire library search for the constant.&lt;br /&gt;
 &lt;br /&gt;
*'''Use explicit returns'''&lt;br /&gt;
: Even though the result of last operation is returned for a method, using explicit returns would speed up the code. Explicit returns are faster, especially in older Ruby versions such as 1.8.x.&lt;br /&gt;
&lt;br /&gt;
=== Documentation Guidelines&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/api_documentation_guidelines.html&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Documentation comments&amp;lt;ref&amp;gt;http://www.jetbrains.com/ruby/webhelp/documenting-source-code-in-rubymine.html&amp;lt;/ref&amp;gt; can be created in accordance with [http://rdoc.sourceforge.net/ RDoc] and [http://yardoc.org/ YARD] syntax. Note that RDoc highlighting in documentation comments can be turned enabled or disabled in the Appearance page of the editor settings.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The most common Documentation guidelines are listed below.&lt;br /&gt;
*Write simple, declarative sentences. Brevity is a plus: get to the point.&lt;br /&gt;
*Write in present tense: &amp;quot;Returns a hash that...&amp;quot;, rather than &amp;quot;Returned a hash that...&amp;quot; or &amp;quot;Will return a hash that...&amp;quot;.&lt;br /&gt;
*Start comments in upper case. Follow regular punctuation rules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Declares an attribute reader backed by an internally-named &lt;br /&gt;
# instance variable.&lt;br /&gt;
def attr_internal_reader(*attrs)&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Communicate to the reader the current way of doing things, both explicitly and implicitly. Use the idioms recommended in edge. Reorder sections to emphasize favored approaches if needed, etc. The documentation should be a model for best practices and canonical, modern Rails usage.&lt;br /&gt;
&lt;br /&gt;
Documentation has to be concise but comprehensive. Explore and document edge cases.&lt;br /&gt;
&lt;br /&gt;
=== Layout Guidelines&amp;lt;ref&amp;gt;http://www.caliban.org/ruby/rubyguide.shtml&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Designing the layout of any application determines the readability factor for other developers.&lt;br /&gt;
Most followed order of code is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
header block with author's name, Perforce Id tag and a brief description of what the program or library is for.&lt;br /&gt;
require statements&lt;br /&gt;
include statements&lt;br /&gt;
class and module definitions&lt;br /&gt;
main program section&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Spreading Code Out and Lining it Up'''&lt;br /&gt;
:This is very important for readability. Basically the principle is to:&lt;br /&gt;
:*separate each component part by white space.&lt;br /&gt;
:*align everything meaningfully.&lt;br /&gt;
:As such one can easily scan up and down the code and see the patterns. This is very important not only for understanding the code, but also for looking for anomalies and as a tool for rationalizing and consolidating the code.&lt;br /&gt;
:Code that has a lot of 'noise' - a lot of unnecessary variation and untidiness - is code that one can waste a lot of time working on. Well written and formatted code is code that is easy and quick to work with. It is code that allows one to easily 'see the wood from the trees'.&lt;br /&gt;
&lt;br /&gt;
== '''Code Analysis Tools''' ==&lt;br /&gt;
&lt;br /&gt;
Ruby itself goes a long way towards helping developers write clear code.&lt;br /&gt;
&lt;br /&gt;
*'''The Ruby debugger''' is a library loaded into Ruby at run-time. &lt;br /&gt;
This is done as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby -r debug [&lt;br /&gt;
            options&lt;br /&gt;
            ] [&lt;br /&gt;
            programfile&lt;br /&gt;
            ] [&lt;br /&gt;
            arguments&lt;br /&gt;
            ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debugger can do all the usual things one would expect it to, such as set breakpoints, step into and over code, print out the call stack, etc.&lt;br /&gt;
&lt;br /&gt;
While tools for the mainstream languages such as Java and C++ have reached a certain maturity, tools for Ruby are still growing. And they might be needed more and more as Ruby's usage spreads from early adopters to the early majority, and SLOC (Source Lines Of Code) continues to increase. Automatic tools&amp;lt;ref&amp;gt;http://www.infoq.com/news/2009/09/code-quality-metric-fu&amp;lt;/ref&amp;gt; can be used to detect several types of problems including inconsistent style, long methods and repeated code.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/roodi/roodi/tree/master '''Roodi'''] (Ruby Object Oriented Design Inferometer) - this parses Ruby code and warns about design issues from the list  configured, ie: Class line count check, for loop check, parameter number check, cyclomatic checks and 10 other checks&lt;br /&gt;
*[https://github.com/troessner/reek '''Reek'''] - similar in concept to Roodi&lt;br /&gt;
*[https://github.com/devver/saikuro '''Saikuro'''] - designed to check cyclomatic complexity&lt;br /&gt;
*[https://github.com/seattlerb/flog '''Flog'''] - created by Ryan Davis, this computes a score of code written: the higher the score is, the worse your code is. ABC metrics (Assignments, Branches and Calls) are taken into account to compute the score&lt;br /&gt;
*[http://www.harukizaemon.com/simian/ '''Simian'''] - a similarity analyzer, this can be used for duplication identification (a $99 license is needed for commercial use)&lt;br /&gt;
*[https://github.com/seattlerb/flay '''Flay'''] - this is another free tool from Ryan Davis that finds structural similarities in code&lt;br /&gt;
&lt;br /&gt;
[[File:Code Analysis Outputs.png|frame|none|alt=Code Analysis Tool Results|Code Analysis Tool Results]]&lt;br /&gt;
&lt;br /&gt;
== '''Summary''' ==&lt;br /&gt;
Ruby developers should follow a certain criteria or guidelines during software development. Coding standards are set of rules, guidelines and regulations on the manner of writing a code that helps programmers and developers read and understand quickly the source code that conforms to style and help avoid introducing misunderstanding and faults.&lt;br /&gt;
&lt;br /&gt;
Particularly in Ruby development, coding standards are extremely important; therefore Ruby developers should put an importance to them. This is because these standards offer higher uniformity and consistency when writing code by different programmers. This could result in a code that's simple to know and preserve, thus reducing the project’s overall expenses.&lt;br /&gt;
&lt;br /&gt;
Some of the benefits of using coding standards are:&lt;br /&gt;
&lt;br /&gt;
*Easy to understand and maintained&lt;br /&gt;
*Boost the code’s readability&lt;br /&gt;
*Maintainable applications&lt;br /&gt;
*Eradicates complexity&lt;br /&gt;
*Separate documents look more appropriate&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://www.caliban.org/ruby/rubyguide.shtml&lt;br /&gt;
*https://github.com/styleguide/ruby&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78458</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w23 ph</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w23_ph&amp;diff=78458"/>
		<updated>2013-09-23T17:50:58Z</updated>

		<summary type="html">&lt;p&gt;Pyadla: /* Naming Guidelineshttp://itsignals.cascadia.com.au/?p=7 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Ruby Coding Guidelines''' ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] Coding Guidelines include best practices followed generally for most of the [http://en.wikipedia.org/wiki/Category:Object-oriented_programming_languages object oriented programming languages] as Ruby is entirely 'Object Oriented'. Also known as 'Ruby Coding conventions', these are a set of guidelines that recommend programming style, practices and methods for each aspect of a piece of program written in Ruby. &lt;br /&gt;
&lt;br /&gt;
Software programmers are highly recommended to follow these guidelines to help improve the readability of their source code and make software maintenance easier. Naming conventions, class and member design principles, maintainability, performance, documentation and layout are the important areas where these guidelines have to be followed. More important than the reasons for having a guideline is actually adhering to it consistently.  Having a coding guideline documented and available means nothing if developers are not using it consistently.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Types of Guidelines''' ==&lt;br /&gt;
Coding guidelines in Ruby can be defined individually for major sections that code consists of. Naming , Class Design , Member Design , Maintainability, Performance, Documentation and Layout guidelines are illustrated below. These guidelines contain sections common to all of these as well as sections which apply to each one individually.&lt;br /&gt;
&lt;br /&gt;
=== Naming Guidelines&amp;lt;ref&amp;gt;http://itsignals.cascadia.com.au/?p=7&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Ruby uses the first character of the name to help it determine it’s intended use.&lt;br /&gt;
The standard Ruby file extension is .rb, although many people working on [http://en.wikipedia.org/wiki/Unix UNIX]-like systems don't bother with it for stand-alone scripts. Whether or not one uses it for scripts is up to them, but they will need to use it for library files or they will not be found by the interpreter.&lt;br /&gt;
&lt;br /&gt;
*'''Local Variables'''&lt;br /&gt;
:Should use lowercase letter followed by other characters. Naming convention states that it is better to use underscores rather than [http://en.wikipedia.org/wiki/CamelCase camelBack] for multiple word names, e.g. average, variable_xyz&lt;br /&gt;
*'''Instance Variables'''&lt;br /&gt;
:Instance variables are defined using the single &amp;quot;at&amp;quot; sign (@) followed by a name. It is suggested that a lowercase letter should succeed @, e.g. @color &lt;br /&gt;
*'''Instance Methods'''&lt;br /&gt;
:Method names should start with a lowercase letter, and may be followed by digits, underscores, and letters. The name should possibly be a verb e.g. move, display_details&lt;br /&gt;
*'''Class Variables'''&lt;br /&gt;
:Class variable names start with a double &amp;quot;at&amp;quot; sign (@@) and may be followed by digits, underscores, and letters, e.g. @@color&lt;br /&gt;
*'''Constant''' &lt;br /&gt;
:Constant names usually start with an uppercase letter followed by other characters. Constant objects are by convention named using all uppercase letters and underscores between words, e.g. THIS_IS_A_CONSTANT&lt;br /&gt;
*'''Class and Module''' &lt;br /&gt;
:Class names are recommended to be be nouns. In the case of modules, it's harder to make a clear recommendation. The names of [http://en.wikipedia.org/wiki/Mixin mix-ins] (which are just modules), however,  should probably be adjectives, such as the standard [http://en.wikibooks.org/wiki/Ruby_Programming/Reference/Objects/Enumerable Enumerable] and [http://www.ruby-doc.org/core-2.0.0/Comparable.html Comparable] modules. Class and module names starts with an uppercase letter, by convention they are named using MixedCase, e.g. module Encryption, class MixedCase&lt;br /&gt;
*'''Global Variables'''&lt;br /&gt;
:Starts with a dollar ($) sign followed by other characters, e.g. $global&lt;br /&gt;
&lt;br /&gt;
Considering customer order information as the data being used for an application, below naming guidelines give an idea of good class/table/file names.&lt;br /&gt;
*'''Model Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Table: orders&lt;br /&gt;
Class: Order&lt;br /&gt;
File: /app/models/order.rb&lt;br /&gt;
Primary Key: id&lt;br /&gt;
Foreign Key: customer_id&lt;br /&gt;
Link Tables: items_orders&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Controller Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class: OrdersController&lt;br /&gt;
File: /app/controllers/orders_controller.rb&lt;br /&gt;
Layout: /app/layouts/orders.html.erb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''View Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Helper: /app/helpers/orders_helper.rb&lt;br /&gt;
Helper Module: OrdersHelper&lt;br /&gt;
Views: /app/views/orders/… (list.html.erb for example)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Tests Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Unit: /test/unit/order_test.rb&lt;br /&gt;
Functional: /test/functional/orders_controller_test.rb&lt;br /&gt;
Fixtures: /test/fixtures/orders.yml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Class Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A class in Ruby always starts with the keyword class followed by the name of the class. The name should always be in initial capitals. Class Customer can be displayed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Customer&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A class is terminated by using the keyword end. All the data members in the class are between the class definition and the end keyword. &lt;br /&gt;
&lt;br /&gt;
Ruby blurs the distinction between design and implementation. Ideas that have to be expressed at the design level in other languages can be implemented directly in Ruby. To help in this process, Ruby has support for some design-level strategies. These strategies can be used to design classes accordingly as suitable for different types of  applications.&lt;br /&gt;
&lt;br /&gt;
*'''The Visitor pattern''' is a way of traversing a collection without having to know the internal organization of that collection.&lt;br /&gt;
*'''Delegation''' is a way of composing classes more flexibly and dynamically than can be done using standard inheritance.&lt;br /&gt;
*The '''Singleton pattern''' is a way of ensuring that only one instantiation of a particular class exists at a time.&lt;br /&gt;
*The '''Observer pattern''' implements a protocol allowing one object to notify a set of interested objects when certain changes have occurred.&lt;br /&gt;
&lt;br /&gt;
Normally, all four of these strategies require explicit code each time they're implemented. With Ruby, they can be abstracted into a library and reused freely and transparently.&lt;br /&gt;
&lt;br /&gt;
=== Member Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
While defining class members, it is very important to keep in mind the access restrictions. Scope and life-time of class members are different for different restrictions, as illustrated below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public&lt;br /&gt;
totally accessible.&lt;br /&gt;
protected&lt;br /&gt;
accessible only by instances of class and direct descendants. Even through hasA relationships. (see below)&lt;br /&gt;
private&lt;br /&gt;
accessible only by instances of class (must be called nekkid no “self.” or anything else).&lt;br /&gt;
class A&lt;br /&gt;
  # Restriction used w/o arguments set the default access control.&lt;br /&gt;
  protected&lt;br /&gt;
&lt;br /&gt;
  def protected_method&lt;br /&gt;
    # nothing&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class B &amp;lt; A&lt;br /&gt;
  def test_protected&lt;br /&gt;
    myA = A.new&lt;br /&gt;
    myA.protected_method&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Used with arguments, sets the access of the named methods and constants.&lt;br /&gt;
  public :test_protected&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
b = B.new.test_protected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Maintainability Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
Maintainability guidelines are important to programmers for a number of reasons:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
*40%-80% of the lifetime cost of a piece of software goes to maintenance.&lt;br /&gt;
*Hardly any software is maintained for its whole life by the original author. &lt;br /&gt;
*Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. &lt;br /&gt;
*If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
The following guidelines are to be followed to improve the software maintainability&lt;br /&gt;
* '''Profile your code regularly'''&lt;br /&gt;
: If you profile your code regularly you’ll be able to tell if the latest change to the code will have an adverse effect on performance.  Integrate profiling into your testing process and make it automated to ensure that it’s not forgotten.  Like unit testing and BDD([http://en.wikipedia.org/wiki/Behavior-driven_development Behavior-driven development]) profiling goes a long way.&lt;br /&gt;
&lt;br /&gt;
=== Performance Guidelines&amp;lt;ref&amp;gt;http://blog.monitis.com/index.php/2012/02/08/20-ruby-performance-tips/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
The key parameter on which a software application is rated is by its performance. It is the time taken by the application to respond to a user's request. Performance of ruby can be improved significantly by following certain coding guidelines, as below.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid nesting loops more than three levels deep'''&lt;br /&gt;
: Nesting affects the performance of the code proportionally with the increasing levels in loops. Limiting nesting to three levels is one good practice to keep the code's performance well.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary variable assignments'''&lt;br /&gt;
: New programmers, often use unwanted variables in code.  A great example is when someone defines a variable to store a return value and then returns that variable; just return the value directly.&lt;br /&gt;
&lt;br /&gt;
*'''Reduce usage of disk I/O'''&lt;br /&gt;
: Disk I/O is a very costly operation as far as computing is concerned. Keeping it to the minimal improves the application response time drastically. Using disk I/O, makes the application extremely slow. Using storage systems such as memcached reduces disk I/O operations to a great extent as lot of data is kept in memory. The speed improvement while using a memory caching system is tremendous.&lt;br /&gt;
&lt;br /&gt;
*'''Use Ruby Enterprise Edition'''&lt;br /&gt;
: Ruby Enterprise edition provides up to [http://www.rubyenterpriseedition.com/faq.html#thirty_three_percent_mem_reduction 33% lower memory] usage.  Though, to get benefited by this performance one needs to follow their guidelines.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid method calls as much as possible'''&lt;br /&gt;
: Method calls are expensive operations in ruby. They should be avoided to keep up the performance of the application.&lt;br /&gt;
&lt;br /&gt;
*'''Use interpolated strings instead of concatenated strings'''&lt;br /&gt;
: Concatenated strings calls a method to get executed. So, it affects the performance as it is one of the most frequently used operation. Its better to replace them with Interpolated strings which runs faster as it doesn't invoke a method call.&lt;br /&gt;
put “Hello there, #{name}!”vs.puts “Hello there, ” &amp;lt;&amp;lt; name = “!”&lt;br /&gt;
&lt;br /&gt;
*'''Destructive operations are faster'''&lt;br /&gt;
: Ruby’s in-place methods that which modifies the actual value than working on a copy of the data are much faster. But this should be handled carefully as original data gets disturbed.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary calls to uniq on arrays'''&lt;br /&gt;
: In many cases methods are already calling uniq on an array and there’s no need for you to call it yet again.&lt;br /&gt;
&lt;br /&gt;
*'''For loops are faster than .each'''&lt;br /&gt;
: .each uses an enumeration object behind the scene which adds a delay in execution. Using for instead of .each would improve performance but for short loops only.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/6406112/why-are-ruby-method-calls-particularly-slow-in-comparison-to-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Use x.blank? over x.nil? || x.empty?'''&lt;br /&gt;
: When using ActionPack there’s no need for x.nil? or x.empty?; x.blank? checks for both of these.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid calls to parse_date and strftime'''&lt;br /&gt;
: Both these calls are very expensive. using regular expressions would improve the time.&lt;br /&gt;
&lt;br /&gt;
*'''Know your gems'''&lt;br /&gt;
: All libraries are not efficient. Many gems may need to be removed to problem to fix a problem with the code. This is a common scenario when many gems are installed. So performing bench marking and testing a gem with others that perform same task would help in picking the right gem.&lt;br /&gt;
&lt;br /&gt;
*'''Improve your algorithms before you try to improve your code'''&lt;br /&gt;
: Algorithmic improvements results in evident improvements in performance of the code. It is always ideal to design an efficient algorithm without unwanted method calls.&lt;br /&gt;
&lt;br /&gt;
*'''Test the most frequently occurring case first'''&lt;br /&gt;
: While using if statements or a case statement always test the cases that occur most frequently. This allows less code to run before a decision is made.  It may not seem like much but over several hundred or thousand runs through the decision logic you’ll notice a definite performance gain.&lt;br /&gt;
&lt;br /&gt;
*'''Optimize the way you access global constants'''&lt;br /&gt;
: While accessing the global constants one should use namespace before the constants to avoid entire library search for the constant.&lt;br /&gt;
 &lt;br /&gt;
*'''Use explicit returns'''&lt;br /&gt;
: Even though the result of last operation is returned for a method, using explicit returns would speed up the code. Explicit returns are faster, especially in older Ruby versions such as 1.8.x.&lt;br /&gt;
&lt;br /&gt;
=== Documentation Guidelines&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/api_documentation_guidelines.html&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Documentation comments&amp;lt;ref&amp;gt;http://www.jetbrains.com/ruby/webhelp/documenting-source-code-in-rubymine.html&amp;lt;/ref&amp;gt; can be created in accordance with [http://rdoc.sourceforge.net/ RDoc] and [http://yardoc.org/ YARD] syntax. Note that RDoc highlighting in documentation comments can be turned enabled or disabled in the Appearance page of the editor settings.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The most common Documentation guidelines are listed below.&lt;br /&gt;
*Write simple, declarative sentences. Brevity is a plus: get to the point.&lt;br /&gt;
*Write in present tense: &amp;quot;Returns a hash that...&amp;quot;, rather than &amp;quot;Returned a hash that...&amp;quot; or &amp;quot;Will return a hash that...&amp;quot;.&lt;br /&gt;
*Start comments in upper case. Follow regular punctuation rules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Declares an attribute reader backed by an internally-named &lt;br /&gt;
# instance variable.&lt;br /&gt;
def attr_internal_reader(*attrs)&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Communicate to the reader the current way of doing things, both explicitly and implicitly. Use the idioms recommended in edge. Reorder sections to emphasize favored approaches if needed, etc. The documentation should be a model for best practices and canonical, modern Rails usage.&lt;br /&gt;
&lt;br /&gt;
Documentation has to be concise but comprehensive. Explore and document edge cases.&lt;br /&gt;
&lt;br /&gt;
=== Layout Guidelines&amp;lt;ref&amp;gt;http://www.caliban.org/ruby/rubyguide.shtml&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Designing the layout of any application determines the readability factor for other developers.&lt;br /&gt;
Most followed order of code is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
header block with author's name, Perforce Id tag and a brief description of what the program or library is for.&lt;br /&gt;
require statements&lt;br /&gt;
include statements&lt;br /&gt;
class and module definitions&lt;br /&gt;
main program section&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Spreading Code Out and Lining it Up'''&lt;br /&gt;
:This is very important for readability. Basically the principle is to:&lt;br /&gt;
:*separate each component part by white space.&lt;br /&gt;
:*align everything meaningfully.&lt;br /&gt;
:As such one can easily scan up and down the code and see the patterns. This is very important not only for understanding the code, but also for looking for anomalies and as a tool for rationalizing and consolidating the code.&lt;br /&gt;
:Code that has a lot of 'noise' - a lot of unnecessary variation and untidiness - is code that one can waste a lot of time working on. Well written and formatted code is code that is easy and quick to work with. It is code that allows one to easily 'see the wood from the trees'.&lt;br /&gt;
&lt;br /&gt;
== '''Code Analysis Tools''' ==&lt;br /&gt;
&lt;br /&gt;
Ruby itself goes a long way towards helping developers write clear code.&lt;br /&gt;
&lt;br /&gt;
*'''The Ruby debugger''' is a library loaded into Ruby at run-time. &lt;br /&gt;
This is done as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby -r debug [&lt;br /&gt;
            options&lt;br /&gt;
            ] [&lt;br /&gt;
            programfile&lt;br /&gt;
            ] [&lt;br /&gt;
            arguments&lt;br /&gt;
            ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debugger can do all the usual things one would expect it to, such as set breakpoints, step into and over code, print out the call stack, etc.&lt;br /&gt;
&lt;br /&gt;
While tools for the mainstream languages such as Java and C++ have reached a certain maturity, tools for Ruby are still growing. And they might be needed more and more as Ruby's usage spreads from early adopters to the early majority, and SLOC (Source Lines Of Code) continues to increase. Automatic tools&amp;lt;ref&amp;gt;http://www.infoq.com/news/2009/09/code-quality-metric-fu&amp;lt;/ref&amp;gt; can be used to detect several types of problems including inconsistent style, long methods and repeated code.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/roodi/roodi/tree/master '''Roodi'''] (Ruby Object Oriented Design Inferometer) - this parses Ruby code and warns about design issues from the list  configured, ie: Class line count check, for loop check, parameter number check, cyclomatic checks and 10 other checks&lt;br /&gt;
*[https://github.com/troessner/reek '''Reek'''] - similar in concept to Roodi&lt;br /&gt;
*[https://github.com/devver/saikuro '''Saikuro'''] - designed to check cyclomatic complexity&lt;br /&gt;
*[https://github.com/seattlerb/flog '''Flog'''] - created by Ryan Davis, this computes a score of code written: the higher the score is, the worse your code is. ABC metrics (Assignments, Branches and Calls) are taken into account to compute the score&lt;br /&gt;
*[http://www.harukizaemon.com/simian/ '''Simian'''] - a similarity analyzer, this can be used for duplication identification (a $99 license is needed for commercial use)&lt;br /&gt;
*[https://github.com/seattlerb/flay '''Flay'''] - this is another free tool from Ryan Davis that finds structural similarities in code&lt;br /&gt;
&lt;br /&gt;
[[File:Code Analysis Outputs.png|frame|none|alt=Code Analysis Tool Results|Code Analysis Tool Results]]&lt;br /&gt;
&lt;br /&gt;
== '''Summary''' ==&lt;br /&gt;
Ruby developers should follow a certain criteria or guidelines during software development. Coding standards are set of rules, guidelines and regulations on the manner of writing a code that helps programmers and developers read and understand quickly the source code that conforms to style and help avoid introducing misunderstanding and faults.&lt;br /&gt;
&lt;br /&gt;
Particularly in Ruby development, coding standards are extremely important; therefore Ruby developers should put an importance to them. This is because these standards offer higher uniformity and consistency when writing code by different programmers. This could result in a code that's simple to know and preserve, thus reducing the project’s overall expenses.&lt;br /&gt;
&lt;br /&gt;
Some of the benefits of using coding standards are:&lt;br /&gt;
&lt;br /&gt;
*Easy to understand and maintained&lt;br /&gt;
*Boost the code’s readability&lt;br /&gt;
*Maintainable applications&lt;br /&gt;
*Eradicates complexity&lt;br /&gt;
*Separate documents look more appropriate&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://www.caliban.org/ruby/rubyguide.shtml&lt;br /&gt;
*https://github.com/styleguide/ruby&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pyadla</name></author>
	</entry>
</feed>