View Single Post

  #2 (permalink)  
Old 09-29-2003
Burhan Khalid
 
Posts: n/a
Default Re: [PHP] Cleaning up my messy code

Chris wrote:

> I am working on a fairly large scale (for myself anyway) project using PHP
> and MySQL. I am victim of teaching myself to program, not separating
> presentation from my code-- all the things that lead to masses of spaghetti
> code so atrocious even I can't figure out what I was doing an hour ago.
>
> I'm not looking for an IDE or code generator so much as some practical
> advice for organization and framework when developing a larger app. I know
> of PHP Fusebox, having programmed with Cold Fusion fusebox for a while, but
> it seems like that might be too much. Maybe I just need a sensical,
> practical approach to application layout. What do you all do? How can I
> learn to be a better PHP programmer in this regard?


Chris, I'm glad that you have realized that your programming practices
are leading your into trouble. That's a big step. A lot of people refuse
to believe that.

Getting rid of spaghetti code can easily be done if you start using a
template engine ( smarty from smarty.php.net is my favorite ). This
allows you to atleast on some level, separate your presentation from
your logic.

The old mantra about documentation also holds true here. If you document
your code as you write it, it will help you try to figure out what you
were doing an hour ago.

Compartmentalizing your code and separating it into logical components
(not necessarily classes, but those help) will allow you to organize
your code better. Arranging these components into separate files will
lead to better managability of code.

As far as frameworks are concerned, I don't use any "formal" or
"published" framework, but rather have my own application skeleton that
is comprised of some PEAR classes along with a sprinkling of my own
modules. It has served me well, especially since all of the grunt work
is taken care of by PEAR.

Good luck, and I hope this helps.
--
Burhan Khalid
phplist[at]meidomus[dot]com
http://www.meidomus.com
Reply With Quote