Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

separate scripts vs a few larger general ones

Posted on 2014-09-05
7
Medium Priority
?
193 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:J N
  • 3
  • 3
7 Comments
 
LVL 111

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:J N
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 84

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 111

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:J N
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 111

Accepted Solution

by:
Ray Paseur earned 2000 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:J N
ID: 40307938
Thanks a lot !!!!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

963 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