Tips for developers

Hello,

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:

PHP:
$iUserId = (int)$iUserId


7. Make sure parameters to a function are not empty:
PHP:
public function doSomething($sString)
{
  if (empty(
$sString))
  {
    return 
false;
  }
  
/*... more code ...*/

This helps if you accidentally pass an empty string to that function:
PHP:
$sUserName '';
if (
$bSomething == true)
{
  
$sUserName 'John';
}
else if(
$bSomethingElse == true)
{
  
$sUserName 'Jane';
}
$this->doSomething($sUserName); 


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.

Comments
Only verified clients can post comments on our community. If you have any questions feel free to contact us here.
PleaseCloseThisAccount wrote at May 9, 2011, 1:08 pm
0 Votes

As the self-appointed resident documentation critic I suggest the contents of this article are too random and unrelated.

A large chunk just belongs with the existing coding guidelines.

Item 5 is offensive and false. The advice is good. Don't ignore notices. The implication (you are a bad programmer) does not necessarily follow. Nor are all notices are memory leaks.

Item 12 is mildly annoying. There will always be contention over this. Account for your own limitations and the pressures facing developers. I guess I'm unhappy it is a "tip". Have a rule or don't. How about this: "modifications to the core may only be in the form of a single line which calls a plugin".

Move the coding guidelines in the appropriate places, change the title to "Really stupid things we have seen", er ah perhaps "Pitfalls to avoid".

Anticipating this knowledgebase will grow hugely with the success of phpFox, a random list of "what came off the top of my head today" might be better placed as a blog entry. Let's try to keep this data focused and professional.

Glad for this thank you. Kingly don't take my comments as personal or negative.

PleaseCloseThisAccount
TheFurryDrifter wrote at May 8, 2011, 6:36 pm
0 Votes

now we just need to direct 95% of the third party developers to this post

TheFurryDrifter