Forum Moderators: coopster

Message Too Old, No Replies

Finding redundant code

Suggestions for logical method?

         

vincevincevince

1:49 am on Sep 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It seems to be becoming ever more common that we are given immense heaps of code which the original programmer doesn't seem keen on working with for one reason or another. Redundant code has always been a problem, but some of these have gone OOP and the problem is now even worse: dozens of classes in separate files each with dozens of methods. It seems some developers are just throwing in every class they've ever written 'just in case'.

Needless to say, we need to clean out all the redundant code to make the MountainOfCodetm possible to understand and handle.

Types of redundant code which I've noticed in many cases:

  • Deactivated clauses (blocks which always boil down to
    if (false)
    )
  • Repeated operations (check login and read user data for $_SESSION[userid], do some general header output, check login and read user data for $_SESSION[userid], output the main structure, check login and read user data for $_SESSION[userid].)
  • Classes containing methods / members which are never used
  • Classes which are never used
  • Columns in databases which are never used
  • Stray functions which never get used
  • Functions which duplicate built-in PHP functionality for no real reason at all
  • Homespun 'database wrappers' which actually do nothing but slow things down and make things look complex! << very common
  • Translation files which contain entries which are no longer used
  • Configuration file entries which are never used or get overwritten dynamically
  • Unused images << major problem
  • Unused CSS classes
  • .bak and ~name files
  • Filenames duplicated with .html and .php suffixes (index.html AND index.php)

    My question is:
    What is the fastest (programmer time efficient) way to remove all of these?

    I'd love it if there was some kind of PHP / Zend functionality to weed these out.

  • Habtom

    5:52 am on Sep 26, 2007 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    I'd love it if there was some kind of PHP / Zend functionality to weed these out.

    It probably would have been nice to have one of those with suggestions that something unwanted is left somewhere. I haven't extensively searched for it, but I don't believe there is one.

    But I would use your list, when I need to clean the code in a project completed. I normally try to make the code I write to be very structured reducing the amount of time spent in understanding and debugging the code at later times.

    The thread is flagged, tnx.

    jatar_k

    12:34 pm on Sep 26, 2007 (gmt 0)

    WebmasterWorld Administrator 10+ Year Member



    I hate doing this and I have had to do it many times

    The process has always been the same

    rebuild underlying libraries, without changing functionality.
    mass greps to find unused functions
    slow rebuilding of each individual section

    I have always tried to assess performance as the number one priority and keep in mind how difficult teach portion of the clean up is. Some things just never get changed because they don't matter.

    henry0

    12:41 pm on Sep 26, 2007 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Before uploading from my test bed I always del all those " .back " files

    I am wondering if there is a way to do that
    (My test bed is a LAMP on XP)
    In one shot, for this is a tedious process

    Further in a manageable way all includes (used and re re used again)
    Could they be included in one line (Guess it was mentioned a few months ago)

    henry0

    12:57 pm on Sep 26, 2007 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Forms:
    I had an idea since a while; but no time yet to dev it
    We all use tons of forms
    Forms do have many similar fields
    I mean for example fields that could only be alphanumerical char with or without space; there are many other fields with other similitude.
    So I thought about creating some sort of index id for each similar field
    Reading the form inputs in an array, grab the indexes of same value
    And then using $counter in one shot filter user input by using a class function
    Instead of having to repeat the same lines over and over.

    Hmmm not sure I defined it well :)