Image 01 Image 02

Less is better

Posted on 30th July 2008 by admin and
8



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:

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!

If you enjoyed this post, make sure you subscribe to our RSS feed!



8
Responses to.. Less is better

1

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



2

[...] If you’ve read any of my posts here or in the forums, at some point I’ve mentioned my husband Ron. Sometimes he’s known as my in-house programmer, my code monkey, or even Mr. Andrea. Now you too can be elucidated by his introductory post over at WPMU.org, entitled Less is Better. [...]



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.



WPMU DEV Premium - WordPress MU plugins, themes, videos and support


Instalation, configuration and hosting for WordPress MU


Blogs.mu - white label wordpress mu bnlog network provider


siteadminbook