Less is better

July 30, 2008  | 
8 Comments

Ron R is half of the well known duo also comprised of Andrea R, the team behind WPMU Tutorials – James.

This week James announced the first WPMU plugin competition and included an offer to express interest in sponsoring and/or judging. Andrea & I discussed it briefly and decided that we would like to be a sponsor for the event. Because I do most of the custom coding, I tend to pay more attention to how well a plugin is written while Andrea is interested in whether it meets the need of the client.

If I were looking for a well written plugin, I would base my assessment on the following 4 things:

Loops: Loops are what make programming practical. They are used everywhere: database engines, string processing functions, capturing keystrokes, etc. Almost all processing time is consumed within loops. One of the keys to good programming is to only include code inside of a loop that needs to be in the loop. For example, if you were outputting a number of items from a blog that use the blog’s url:

foreach($items as $item) {
echo '<a href=”'. get_option('siteurl') . “path/{$item}\”>description</a> “;
// more code
}

Instead of calling the get_option function inside the loop, call it first and store the results in a variable

$siteurl = get_option('siteurl');
foreach($items as $item) {
echo “<a href="\”{$siteurl}path/{$item}\”">description</a> “;
// more code
}

Efficient queries: Databases are the heart of most content management systems. WordPress and WordPress MU are no different. A plugin that uses the database(s) poorly can substantially eat away at site performance. Here are some simple guidelines that can be used when writing database queries:

  • Don’t use SELECT * unless you need all of the columns in the table(s). Only retrieve the columns you need. Yes, it takes more time to write the query but resources are chewed up retrieving and including the unused columns in the result set.
  • Use the LIMIT clause to select only the rows you need. The reasoning is the same as for selecting only the columns you need.
  • Use aggregate functions to reduce processing. If you want a count of something, you could retrieve a column from the table and use the php count() function. But, there is a MySQL COUNT function which will do this. The MySQL engine is optimized to do this type of processing and the result set that it creates to return to WPMU is a single value.
  • When creating tables include a PRIMARY KEY index on each table at a minimum. Depending on the content of a table, other indexes may be appropriate.
  • Try to use as few queries as possible while maintaining query efficiency. This is a cost/benefit type of deal that can be worked through by trying different variations and seeing how it affects processing time. JOINs enable a query to retrieve data from more than 1 table. If matching rows are required from 2 tables, a JOIN can eliminate a second query.

Short: Development for WPMU has never been a far step from development for the WP Standalone. The standalone version is forgiving of poorly written code due to the difference in the number of page loads and it can absorb cut and paste code. But, if a WPMU install is parsing and tokenizing an extra few hundred lines of code 10, 20, 50 or 100,000 times a day, it adds up. Write reusable functions to reduce the size of the code.

Simple: I include this to balance what I said in the previous item. The pendulum can swing to far the other way. Reducing the footprint of the code shouldn’t be taken to the extreme of making the code hard to read. Code should be readable without requiring detailed comm ents explaining what the code is doing.

In summary, sometimes LESS is better. When I sit down to do some programming I don’t think of these as hard and fast rules, but a good basis to start with.

Would you like to share your WPMU story on WPMU.org? Register and let us know!

Featured Plugin - Add bottom corner (or anywhere else) chat to your site

No javascript required, no third part chat engine, just fully featured chat right in your own database on your own WP sites - couldn't be easier.
Find out more

Featured Plugin - Turn any WordPress page into a fully featured wiki!

To get a wiki up and running you used to need to install Mediawiki and toil away for days configuring it... not any more! This plugin gives you *all* the functionality you want from a wiki, in WordPress!!!
Find out more

Featured Plugin - Open an Online Store with MarketPress

Out of all the WordPress ecommerce plugins available, this has got to be the winner - easy to configure, powerful functionality, multiple gateways and more. A simply brilliant plugin!
Find out more

Featured Plugin - Start Your Own Powerful Membership Site

If you're thinking about starting a paid, or just private, membership site then this is truly the plugin you've been looking for. Easy to use, massively configurable and ready to go out of the box!
Find out more

Featured Plugin - Every great SEO tweak you need, in one snazzy bundle

Fully integrated with the SEOMoz API, complete with automatic links, sitemaps and SEO optimization of your WordPress setup - this is the only plugin you need to help you rank your site number 1 on Google - nothing else compares.
Find out more

Featured Plugin - WordPress + Google Maps = Perfect

Simply insert google maps into posts, sidebars and pages - show directions, streetview, provide image overlays and do it all from a simple button and comprehensive widget.
Find out more

Featured Plugin - Easily integrate your WordPress site with Facebook

Would you like to add Facebook comments, registration, 'Like' buttons and autoposting to your WP site? Well, The Ultimate Facebook plugin has got that all covered!
Find out more

Featured Plugin - Host sites, get paid, just like WordPress.com

If you've ever wondered how you could offer a paid site management and hosting service, then this is the plugin for you. Offer a freemium or paid service, for any niche you like, it's powered Edublogs.org to success already!
Find out more

Featured Plugin - Send beautiful html email newsletters, from WordPress!

Now there's no need to pay for a third party service to sign up, manage and send beautiful email newsletters to your subscriber base - this plugin has got the lot.
Find out more

8 Responses to Less is better

  1. Great information Ron_r, something for me to aspire to;)

  2. Pingback: WPMU Tutorials » Introducing Ron

  3. not a programmer myself but its good to understand a good plugin and its well explained here. thanks

  4. Nice work, honey. :)

  5. wordpress for me works better than dupral6 I like all the themes a little bit more and for the work i do its much easier to navigate around wordpress because i use it also for the iphone, which makes working form home and the road easier not to mention the possible overtiem.

  6. Plugin good, but I have some questions, you can learn to read more about his work. Thanks in advance.

  7. not a programmer myself but its good to understand a good plugin and its well explained here.

  8. I like all the themes a little bit more and for the work i do its much easier to navigate around wordpress because i use it also for the iphone, which makes working form home and the road easier not to mention the possible overtiem.

Click on a tab to select how you'd like to leave your comment

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting