Results 1 to 3 of 3

Thread: Most efficient way to use includes

  1. #1
    Join Date
    Apr 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Most efficient way to use includes

    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!

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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) 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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. The Following User Says Thank You to Twey For This Useful Post:

    tbronson (04-08-2009)

  4. #3
    Join Date
    Apr 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    That makes sense. Thanks!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •