Page 1 of 1

Breaking up code

Posted: Fri Dec 02, 2005 10:15 am
by Charles256
Just a general curiousity question...at what point do you decide.."this is too much code in one place, I'm going to throw it in another file and include it." or does that point ever happen? I find myself doing it for anything more than 50 lines long..just starts to look..i dunno.cluttered:-D

Posted: Fri Dec 02, 2005 10:18 am
by Weirdan
It's a matter of preference, I believe. Personally I start to split files when there is identical code shared between several files, or code belongs to different application layers (javascript should not be in php files).

Posted: Fri Dec 02, 2005 10:54 am
by Grim...
We had a pretty long chat about this (sort) of this a few weeks ago.

I split files up into common, header, main and footer sections, and, Weirdan, keep JS away from PHP with include files.

Posted: Fri Dec 02, 2005 10:58 am
by neophyte
Additionally, if you have right or left columns on your page I keep those separate too.

Posted: Fri Dec 02, 2005 10:32 pm
by Trenchant
Grim... wrote:We had a pretty long chat about this (sort) of this a few weeks ago.

I split files up into common, header, main and footer sections, and, Weirdan, keep JS away from PHP with include files.
I would have to agree with you. I also break up my coding in a very similar way. I break it up into a header and footer however, I put them into functions. So inc.function-layout.php would be my function file for all layout functions. This way I can use my function like this: layout('header/footer', 'page definition(ex. 1-2 main system, second page - login for example)', 'full/separate/null');

Why do I do this? I find I can easily change all my pages at once while still allowing portability and adaptability. For example. If I want to add a user monitoring script that determines where a user is I can easily do that. That third parameter in my layout function is for different layout setups btw. It allows me to have one layout that can perform multiple tasks.

I also separate my code into separate files when I have a script I want to use somewhere else. Shoutbox's are a prime example of something I would put in a separate page.

Things like login forms and process's I normally just put in a functions file. This way I can include them in multiple places and be able to easily keep track of them.