Practical refactoring

I read about refactoring and probably did it before I even found out about it, however I really don't know much about what it really did and what it really means.

  • What do you think refactoring?
  • How and when do you do this?
+3
source share
9 answers

What do you think refactoring?

As a purely academic definition, refactoring is a significant change to existing code that (theoretically) does not affect behavior or outcome.

In terms of practical implications, this can be a lot of things. As a small sample:

  • Moving repeating blocks of code to highlighted functions
  • , ( )

, , ; - , , , (, , ).

?

"" : .

, , , , ( ) . , , . " ", , , , ;)

, , , : " , , ( ), , , ". , , ; ( ), , , () . , , " " .

, ( , ). , , (, , ) .

, ( )

+6

- , . :

  • /, ?
  • ?
  • ?

. , , . , .. , , .

+3

, Wikipedia, " ".

, , , . , , . , , .

+1

, .

, , .

+1

, :

  • (- , )
  • ... (, )
  • ... , ,
  • ... , , , .
+1

, , ?

, , .

?

. , . , , , , , . , , .

0

. - , .

, , - , , , , .

IDE, Visual Studio, , , . , , ++, .

0

- -.

.. - , , :

function show_movies($num=10, $maxpages=10, $order_by="M.produced DESC", $rand=0)
{
  global $template, $off, $cat, $cat_long, $cat_field, $lang, $mid, $cat_long2, $sfm;
  global $sea, $seaquery, $lng, $sub, $aff, $spe, $da, $cat_not, $PHP_SELF, $HTTP_HOST;
  global $q, $_SESSION, $VC_LANG, $john;
  [... snip 356 lines of code that works with all those variables ...]
}

( , , , ... , - , $john GET register_globals... )

, , " , ". , .

, () , . ( ) , , , , . , , , , .

0

- , .

, . . , " , ". , .

0

Source: https://habr.com/ru/post/1738030/


All Articles