Breaking up code

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Breaking up code

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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).
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post 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.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Additionally, if you have right or left columns on your page I keep those separate too.
User avatar
Trenchant
Forum Contributor
Posts: 291
Joined: Mon Nov 29, 2004 6:04 pm
Location: Web Dummy IS

Post 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.
Post Reply