Log in

View Full Version : Most efficient way to use includes



tbronson
04-06-2009, 03:11 PM
A real beginner question about presentation templates for various web apps:

Is there a significant performance difference between separating PHP and HTML code into lots of separate files, as opposed to concentrating them in a few files?

For example, templates by different authors for the same application can run the range, from a minimum number of separate files, to...many!

For example, one template may call a function in a separate file to check the user login state, and then call appropriate login code from two separate files (login or loggedin). Another template may include the logic (IF logged in) and the different code snippets all on the main page.

I realize there are many factors involved, like separating logic and presentation, code clarity, templating systems, and so forth.

I'm just wondering if there's a broad coding rule of thumb for when to separate out something into a new file, as opposed to keeping it all in one place.

I guess the broader question is, how do you monitor and test for coding efficiency, and does that even matter much in the real world, for things like web presentation templates?

Thanks!

Twey
04-06-2009, 06:49 PM
No, no significant difference in performance. The difference in organisation and clarity, however, is considerable.

There should not be any serious logic in template files, and a decent templating language (e.g. Smarty (http://www.smarty.org/)) will not even provide constructs for such things. Code should be entirely in the controllers.

Yes, it matters an awful lot in the real world — far more than when developing toy applications. Real-world applications tend to be big, which is why organisation becomes a priority.

tbronson
04-08-2009, 12:35 PM
That makes sense. Thanks!