Jump to content

How big is that code??


rcorlew

Recommended Posts

I was wondering what kind of methods people employ to help to limit the size of their scripts.

 

What is the highest number of lines they would let be in one page before splitting them off into different pages for different functions?

 

I know that some people perfer to try to keep it all in one page, and others perfer many different pages.

 

I guess that it is personal prefernece and related to speed of functions and sript maintainability.

 

I am just curious as to the methods that others employ.

Link to comment
Share on other sites

I don't worry about the size of my individual files.  Computers are fast.  Very fast.  You would have to have an extremely large source file, probably over the 1MB mark, for it to make a notable impact IMO.

 

What you want to do is try and organize your code so that only the required files are included in each script.  There's no sense in including 3 or 4 .php files for DB stuff if the current script doesn't interact with the DB.

 

The things I'd look for optimizing before I started worrying about the size of my files would be my algorithms and database set up.  Adding the proper index to a sluggish query can be the difference in your query requiring 10 seconds to execute or .03 seconds to execute.  The same thing holds for algorithms, which are the steps you take to accomplish your programs task.  I.e. instead of looping over a set of 250 items three times, you'd be better off re-organizing your code so that you loop over the set at most once or instead cut the set down to only the items you need.

 

:D

Link to comment
Share on other sites

I'd let it grow as big as needed. I use a lot of classes and each class generally has its own file.

 

Example:

/include/database.php

/include/database/mysql.database.php

/include/database/mysqli.database.php

...

/include/functions.php

/include/error_handler.php

/index.php

Link to comment
Share on other sites

Another factor to consider is the site's purpose and audience.  If the site is for a hobby or your audience is friends and / or family, then people will be more patient.  Which is to say it is acceptable if some of your pages take a little longer to reload.

 

Now if the site is for paying customers and you expect traffic to be heavy, then it's really worth spending more time optimizing.  But you never, ever, go about optimizing willy-nilly without a purpose.  When you optimize code you need to target specific areas.  If the average time for a page to generate is 2.3 seconds (which is a long time mind you) and you have a couple that are taking as long as 10 seconds, then it's worth looking at those couple pages that are taking a long time.

 

There is usually a trade-off between code optimization and readability and maintainability; often, the more optimized a portion of code is the harder it becomes to easily read and maintain later.  The common practice when optimizing is to target a specific area that is performing poorly, isolate the segment that is causing the poor performance, and then to optimize the Hell out of just that one segment of code.

 

Hope that helps.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.