views:

121

answers:

4

Hey!

I am going to start working on a website that has already been built by someone else.

The main script was bought and then adjusted by the lead programmer. The lead has left and I am the only programmer.

Never met the lead and there are no papers, documentation or comments in the code to help me out, also there are many functions with single letter names. There are also parts of the code that are all compressed in one line (like where there should be 200 lines there is one). There are a few hundred files.

My questions are: Does anyone have any advice on how to understand this system? Has anyone had any similar experiences? Does anyone have a quick way of decompressing the lines?

Please help me out here. This is my first big break and I really want this to work out well.

Thanks

EDIT: On regards to the question: - Does anyone have a quick way of decompressing the lines?

I just used notepad++ (extended replace) and netbeans (the format option) to change a file from 1696 lines to 5584!!

This is going to be a loooonnngggg project

+8  A: 

For reformatting the source, try this online pretty-printer: http://www.prettyprinter.de/

For understanding the HTML and CSS, use Firebug.

For understanding the PHP code, step through it in a debugger. (I can't personally recommend a PHP debugger, but I've heard good things about Komodo.)

Start by checking the whole thing into source control, if you haven't already, and then as you work out what the various functions and variables do, rename them to something sensible and check in your changes.

If you can cobble together some rough regression tests (eg. with Selenium) before you start then you can be reasonably sure you aren't breaking anything as you go.

RichieHindle
... and good luck! +1
alex
Eclipse also has a pretty good debugger. I have also used xdebug.
jimiyash
+6  A: 

Ouch! I feel your pain!

A few things to get started:

  1. If you're not using source control, don't do anything else until you get that set up. As you hack away at the files, you need to be able to revert to previous, presumably-working versions. Which source-control system you use isn't as important as using one. Subversion is easy and widely used.

  2. Get an editor with a good PHP syntax highlighter and code folder. Which one is largely down to platform and personal taste; I like JEdit and Notepad++. These will help you navigate the code within a page. JEdit's folder is the best around. Notepad++ has a cool feature that when you highlight a word it highlights the other occurrences in the same file, so you can easily see e.g. where a tag begins, or where a variable is used.

  3. Unwind those long lines by search-and-replace ';' with ';\n' -- at least you'll get every statement on a line of its own. The pretty-printer mentioned above will do the same plus indent. But I find that going in and indenting the code manually is a nice way to start to get familiar with it.

  4. Analyze the website's major use cases and trace each one. If you're a front-end guy, this might be easier if you start from the front-end and work your way back to the DB; if you're a back-end guy, start with the DB and see what talks to it, and then how that's used to render pages -- either way works. Use FireBug in Firefox to inspect e.g. forms to see what names the fields take and what page they post to. Look at the PHP page to see what happens next. Use some echo() statements to print out the values of variables at various places. Finally, crack open the DB and get familiar with its schema.

  5. Lather, rinse, repeat.

Good luck!

Val
+1  A: 

Could you get a copy of the original script version which was bought? It might be that that is documented. You could then use a comparison tool like Beyond Compare in order to extract any modifications that have been made.

Tom Haigh
Nope, can't get the original. It was a bought a while back.
AntonioCS
A: 

If the functions names are only one letter it could be that the code is encoded with some kind of tool (I think Zend had a tool like that - Zend Encoder?) so that people cannot copy it. You should try to find an unencoded version, if there is one because that would save a lot of time.

jimiyash
Don't think there was any encoding done. I think this was done by the programmer
AntonioCS