rcorlew Posted April 23, 2007 Share Posted April 23, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/48212-how-big-is-that-code/ Share on other sites More sharing options...
roopurt18 Posted April 23, 2007 Share Posted April 23, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/48212-how-big-is-that-code/#findComment-235765 Share on other sites More sharing options...
Daniel0 Posted April 23, 2007 Share Posted April 23, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/48212-how-big-is-that-code/#findComment-235766 Share on other sites More sharing options...
roopurt18 Posted April 23, 2007 Share Posted April 23, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/48212-how-big-is-that-code/#findComment-235849 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.