Replies: 3 comments 1 reply
-
First I think about who is using that script: Admins are far and few, so I tend to over-complicate those Admin files in order to automate the forms as much as I can, making the experience "nicer" for those admins. My Real Estate plugin is extremely heavy in both PHP and JavaScript (9500+ lines in one JS file alone!) but it automates nearly all functions a Real Estate Agent needs to do when adding or editing a Property Listing. The files that a visitor gets should be as light-weight as possible. Splitting your code into multiple files is only advantageous when you need to divide what gets processed (maybe for security reasons) or there is a need to have different URL (View Forum vs Post Forum). In the end it really doesn't matter is you have 10 files with 100 lines of code in each or 1 file with 1000 lines of code: the benefit of multi-file setup is when doing that removes lots of code that most users do not need. |
Beta Was this translation helpful? Give feedback.
-
I am the one who is splitting code into several files. Reason? Easier coding, easier copying, easier finding problems, easier finding the correct place to change. Splitting code on front end is good for e_url settings, it is a nightmare to set regex correctly sometimes. Smaller files are loaded quicker or not? Look at news.php - load this all file for category only? Mess in parameters, queries. Try to find issue there. Why I am splitting admin files? Don't repeat the code. One class extends admin_ui class with all general settings, next file uses child class of this class and only changing fields, init() or something like that. With new plugin it is easier just copy stuff I need from other plugin... For example... I am not able to understand the code of Vodhin RE plugin. My mind is just not working that way :) So everything is about personal preferences. PS. Are you working on your collection plugin? |
Beta Was this translation helpful? Give feedback.
-
Ok, i got the point, but sometimes splitting code can be real tricky. For instance, if plugin reuses a lot of the same code in each page, it's a bit of a chimera.... @Jimmi08 You're quite right, smaller files load faster. And yes, my question was about the collection plugin(s). I have code reused among both collection plugins, so i was thinking what should i do... |
Beta Was this translation helpful? Give feedback.
-
Once more, sorry for bothoring again, but i wonder what would be the best practices when designing a plugin, ie for webserver performance and stress.
There's some plugins that split the code along several PHP files, and anothers have all the code in a single PHP file.
For instance, the forum plugin has several PHP files for diferent areas of the plugin (forum.php for the main area, forum_viewforum.php, forum_viewtopic.php) but plugin download has all the areas in the same php file (download.php).
So what would be the best practice for plugin code writing? Separated files or all in one file?
Beta Was this translation helpful? Give feedback.
All reactions