Solved

separate scripts vs a few larger general ones

Posted on 2014-09-05
7
161 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 82

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
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…

747 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

7 Experts available now in Live!

Get 1:1 Help Now