Community Documentation

v3 Knowledgebase

Tips for developers


Today I want to share just some tips that I believe would help many implement better add-ons, this is not a complete list and only based on my experience, it is also not ordered in any special fashion other than whatever pops first into my head:

1. Use a subversion repository, there are even free hosting services for this. This helps specially after releasing a product and patches need to be created or new features implemented

2. Do not use Phpfox::getService('user')->get() unles you really really have to. Specially do not use it in a loop. This function pulls a lot of information from the database and unless you are going to need every single column then it doesn't make sense to waste resources, it is not like it will pull a few extra columns, it may pull a lot more than you need.

3. Benchmark the site before and after the add-on you're working on, ideally no page should need more than 20MB (the dashboard in a default script uses around 14MBs).

4. Always work with debug mode enabled

5. Do not ignore Undefined Indexes and other warnings and notices from PHP. These are memory leaks and directly show that you are a bad programmer.

6. In your functions when you expect something to be an integer make sure it is by casting it:
$iUserId = (int)$iUserId

7. Make sure parameters to a function are not empty:
public function doSomething($sString)
  if (empty(
/*... more code ...*/

This helps if you accidentally pass an empty string to that function:
$sUserName '';
if (
$bSomething == true)
$sUserName 'John';
else if(
$bSomethingElse == true)
$sUserName 'Jane';

8. Consider implementing caching. Some things need to be cached, others may decrease performance by caching them.

9. The best sale is a satisfied customer. Even if you are right, if the customer is not satisfied you are losing. So take preventive actions and if you foresee that you can't please a specific client stay away from that project. Providing constant feedback about the project keeps customers at ease since they know you are not wasting their time. (In this subject the SVN server would let your clients know automatically what you are doing).

10. Try loading things in ajax, renders the initial page earlier and provides a better user experience.

11. Do not load the entire user table (this goes aimed at a specific case I saw once), or any large table for that matter, if your project needs to load the entire user table re-think your logic.

12. Do not edit core files unless a core developer tells you so. Editing core files means a lot of problems when the client upgrades and all those problems can be avoided. Less problems for your clients mean less problems for you.