Thursday 7 August 2014

Code Quality = Save Processor + Save Memory + Optimize Storage

Is anyone having a justifiable definition of Code Quality? We don't think there is a good definition, and We see plenty of bad definitions. There are many definitions for Correctness. But don’t be nervous we have correct examples of code ethics.


Our definition of code ethics is term used to depict the speed and programming methodology used in developing codes for software. Code is directly linked with algorithmic efficiency and the speed of run-time execution for software.


Let’s make it simple, in simple words code must be Economical. No worries we will elaborate you more.

The code should make reasonable use of system resources: Storage, Memory and Processor. To run any software system must require Storage, Memory and Processor resources. What we mean by code ethics or code quality is code which use less resource of system. A code which less occupy system resource in order to Processor, Memory, Storage is a code of ethics.

Please have a look at simple two PHP conditions examples both conditions perform same operations and same result. But both conditions occupy different bundle of system resource. Let’s have a look.

  •  Normal Case 
 $num = mysql_num_rows($qResult);  
 $i=0;  
 echo "<table>"  
 while($i < $num)  
 {  
 if ($i % 2 == 0){  
 echo "<tr class='style1'>";  
 }  
 else{  
 echo "<tr class='style2'>";  
 }  
 echo "<td>" . mysql_result($qResult,$i,"lastName") . "</td>";  
 echo "<td>" . mysql_result($qResult,$i,"firstName") . "</td>";  
 echo "</tr>";  
 $i++;  
 }  
 echo "</table>";  

This condition occupies more system resource in order to Processor, Memory, Storage so as structure and result wise code is been good while as a run-time execution speed of software is not well as second condition.
  •  Quality Case 
 $nTotalRecord = mysql_num_rows($qResult);  
 $nCount=0;  
 $aRowClass = array('style1'=>'style2','style2'=>'style1')  
 $sRowClassName = 'style1';  
 echo "<table>"  
 while($nCount < $nTotalRecord)  
 {  
      echo "<tr class='$sRowClassName'>";  
      echo "<td>" . mysql_result($qResult,$nCount"lastName") . "</td>";  
      echo "<td>" . mysql_result($qResult,$nCount,"firstName") . "</td>";  
      echo "</tr>";  
      $nCount++;  
      $sRowClassName = $aRowClass[$sRowClassName];  
 }  
 echo "</table>";  

This condition occupies less system resources in order to Processor, Memory, and Storage so run-time execution speed of software will be faster than first condition. This is what we mean by Economical code.

Good quality code, especially in the final product, can sometimes mean the difference between success and failure. Simply "fast" is also a measure of quality

I hope that this post has given you an insight how to write conditions into your own projects.

Like it or not you are what you code!

Stepin Solutions is a community of people passionate about quality. We use our experience and ideas to make over work better.

To know more interesting things  and about Stepin Solutions please visit us.

 www.stepin-solutions.com


No comments:

Post a Comment