Solved

separate scripts vs a few larger general ones

Posted on 2014-09-05
7
162 Views
Last Modified: 2014-09-06
Hi,

I would like to know if it is more advantageous to have a singular script that contains either one or very few (1-3) functions / classes  or have a larger scripts that contain more functions / classes. in each instance the functions / classes would be related and likely be required in the same documents but with the larger ones i would not nessecarily use everything within them where as the smaller ones i could just include the ones i need.

thoughts?

thanks in advanced?
0
Comment
Question by:M. Jayme Nagy
  • 3
  • 3
7 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40307077
This question is a little like, "Should I date a blonde or a brunette?"  It depends on personal preference.  Here are my thoughts...

1. Disk I/O operations take a lot of time -- up to 3 orders of magnitude more than in-memory operations.  It follows that autoloaders, numerous include() statements, and the like are expensive in deployed applications.  Visit any WordPress web site to see the effect.

2. Web sites that are built out of parts, but are deployed in combined scripts, can be much faster to load, but require more steps to maintain.  You have to make a "build" yourself -- the automation from autoloaders is not there.

Which do you want?  Fast or easy?
0
 
LVL 6

Author Comment

by:M. Jayme Nagy
ID: 40307084
Thanks!


fast vs easy is not really what im after im more concerned with efficiency. If a method is faster but requires me to cut corners than i am not interested. However, if fast means more efficient than that is exactly what i am looking at
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40307127
In loading time, fast always means more efficient.  However, putting common routines in 'include' files makes it much easier to maintain because you don't have to forget where you are using them.  Every time you edit or change the include file, the changes are automatically 'include'd in every page that uses it.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40307482
fast vs easy is not really what im after
Grab a copy of YSlow and use it to analyze a couple of sites.  I recommend you analyze http://sscce.org and https://www.healthcare.gov to see and compare the behavior of each.  I'm not suggesting that you avoid all include() statements; I'm suggesting that one include() that loads many classes is w-a-a-a-y more efficient than having individual class autoloaders.  If you're not familiar with class autoloaders, read this and also look up Composer.  This is the way many high-level developers are organizing their work today.  I do not think a deployed application should be organized that way, and I think when you do your homework with YSlow you'll come to the same conclusion.
https://addons.mozilla.org/en-US/firefox/addon/yslow/
0
 
LVL 6

Author Comment

by:M. Jayme Nagy
ID: 40307782
Thanks Ray!

Im not loading very many libraries so i dont think i need to worry about composer. The only libraries i really use is jquery and bootstrap.


from what i gather you are suggesting i write a larger resource script and include it rather than individual classes and creating an autoloader function?
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40307856
Here's the thing as I see it.  If I can have 10 classes in a single script and use include() (really, require_once() but they are essentially the same thing) in a deployed application, I will have better performance than if I have 10 auto-loaders.  OTOH, if I have 10 employees working in different locations on different classes, the auto-loaders will help ensure that the development environment always uses the latest versions of their classes.  The "build" process can usually leave the auto-loader in place, because once the large include() script is built, all of the classes will be declared when they are included, and the auto-loaders will not have to do numerous extra disk searches.

Does that make sense?  Really, I think once you see the output from YSlow you will see the concept very clearly.
0
 
LVL 6

Author Closing Comment

by:M. Jayme Nagy
ID: 40307938
Thanks a lot !!!!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now