Is The Code Clean and Readable
Is The Code Clean and Readable
{Arhen Devlops;}
Martin Fowler
Here we Go!
#Issues1
(Variable and method name)
This is good:
protected $elapsedTimeInDays;
protected $daysSinceCreation;
protected $daysSinceModification;
protected $fileAgeInDays;
This is good:
public $generationTimestamp;
public $modificationTimestamp;
This is good:
class Part {
private $description;
}
#Issues2
(Better Function)
Is better than
function makeCircle($x, $y, $radius);
#Issues3
(Comments)
Ex:
$r = $n / 2;
while ( abs( $r - ($n/$r) ) > $t ) {
$r = 0.5 * ( $r + ($n/$r) );
}
echo
Rewrite it!!
// square root of n with Newton-Raphson approximation
private SquareRootApproximation($n) {
$r = $n / 2;
while ( abs( $r - ($n/$r) ) > $t ) {
$r = 0.5 * ( $r + ($n/$r) );
}
return $r;
}
echo
important,
in
most
cases
the
* @param
* @param
* @return [string]
*/
public static function create($algo, $data, $salt)
#issue4
(Avoid 'shity' code!)
Much Better!
<html>
<body>
<table>
<tr>
<td>
<?php echo
"Hai welcome to php";
?>
</td>
</tr>
</table>
</body>
</html>
The same can be coded this way, in order to reduce the execution time:
$res = mysql_query("select * from tbl_products");
while($obj = mysql_fetch_object($res)){
echo $obj->column_name1;
}
switch ($checking_value){
case value1 :
}else if($checking_value2==$value){
echo "result1";
echo "result2";
break;
}else if($checking_value3==$value){
echo "result3";
}else{
echo "result 4";
}
More Suggestion!
www.upanastudio.com