[Phpmyadmin-devel] GSOC 2012 - Refactoring: Insert/edit, Privileges, Operations, Structure

Marc Delisle marc at infomarc.info
Sat Mar 24 16:26:00 CET 2012

Le 2012-03-24 09:43, prakul agarwal a écrit :
> Hello sir,
> Im new to PHP code refactoring. Going through this thread i worked out for
> tbl_structure.php (line 199-209):
>  <?php
>     $a
> =array("column","type","collation","attributes","null","default","extra","view");
>     $b =
> array("Name","Type","Collation","Attributes","Null","Default","Extra","View");
>     for($i=0;$i<8;$i++)
>     {
>       echo " <th id=\"th$i\" class=\"$a[$i]\" > __('$b[$i]') </th>" ;
>     }
>     ?>
>     This code has the same output as the already existing code, plus this
> removes redundancy and makes maintenance easier. Does this qualifies as
> good refactoring?
> thank you.

yes, this is good refactoring, but better refactoring would be:
- avoid generic names like $a, $b
- avoid using the constant 8, instead counting the elements in the array

Using a loop, like you did, is what I had in mind when I proposed this
challenge. Technically, after refactoring, the code had to produce the
same output, as I suspect your example does.

In this discussion, however, code improvement was gained not just by
refactoring, but by examining the reasons behing the code and
simplifying it.

Marc Delisle

More information about the Developers mailing list