Breaking up code
Moderator: General Moderators
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
Breaking up code
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
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 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');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.
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.