Choosing the Wrong Rule Number 1

I was reading through Textpattern support forum and found mention of a weird Rule Number 1 TXP developers are sticking to:

Rule Number 1: Never promise a release date.

I was going to reply directly in the forum, but then I figure this would be a better place.

The Rule Number One is so old-school development process.

Just look at Gnome, Fedora, Ubuntu or others that have adopted the “stable release every six months” policy, they are all healty projects, rapidly gaining traction and respect in the community and growing as stable, solid solutions.

Now look at Debian that instead still follows the rule number 1: nobody uses its stable version, wich is three years old now and many people are getting tired of the development version and are migrating to other distributions.

Well, I also think (and hope) everybody writing code for a living breaks that rule almost every day. You can’t say to your customer you’re going to release “when you’re done”. You say: “on 36 setnuary 2036 we will release a stable release” if by that date you have some feature which isn’t stable, you delay that single feature not the entire project.

A better Rule Number One could be for example ”release early, release often”.

By using this rule, you could avoid the problems Alex mentions to explain why Rule Number One is correct:

[…] The things left till last are likely to be intermittent bugs, issues that only occur on certain platform configurations, Heisenbugs, and all of the minor niggling problems that you’ve forgotten about. They are, by definition, elusive and unpredictable, and hence impossible to estimate.

Right. I totally agree, but my conclusion is different: just because those bugs are elusive and unpredictable, you can never fix them all, so just release, quickly fix them when they come up and release a bugfix.

This way everybody has the latest code without playing with the Subversion repository or other weird tricks, and third-party developers don’t need to worry about giving support to people installing their plugin in last week’s revision.

PHP ain’t that funny after all

I don’t like PHP. I use it on the web because it’s everywhere and you can find a busload of code to do pretty much whatever you want. But I really dislike how it’s designed. It’s inconsistent, you’ll never know what might happen when you call that new function you just found.

Take my Technorati Cosmos Textpattern plugin for example. Sometimes Technorati returns duplicated results and I wanted to filter them: when looping over the list of links received from the Cosmos API call, I added them to an array and then looked there before printing the other links.

I looked PHP documentation and found the nice array_search() function. The documentation says:

mixed array_search (mixed needle, array haystack [, bool strict])

Searches haystack for needle and returns the key if it is found in the array, FALSE otherwise.

nice, the function returns FALSE if the item is not in the array, so I went and wrote my check:

if (!empty($cosmo->permalink) and array_search($cosmo->permalink, $items)) {
    // Skip the item if we have already seen it
    continue;
}

where’s the problem with that? Let’s see some examples.

$a = array(1, 2, 3, 4, 5);

var_dump(array_search(3, $a));
var_dump(array_search(1, $a));
var_dump(array_search(8, $a));

this prints, as expected:

int(2)
int(0)
bool(false)

but what happens if we put this in an if statement?

if (array_search(3, $a))
    echo "3 found\n";
else
    echo "3 not found\n";
if (array_search(1, $a))
    echo "1 found\n";
else
    echo "1 not found\n";
if (array_search(8, $a))
    echo "8 found\n";
else
    echo "8 not found\n";

the result is:

3 found
1 not found
8 not found

Why? Because 0 == FALSE and the second test doesn’t pass. Ok, let’s make it more specific.

if (array_search(1, $a) != FALSE)
    echo "1 found\n";

Wrong again, because 0 is still the same as FALSE. Don’t despair, a solution isn’t that far, any of these will work:

if (array_search(1, $a) !== FALSE)
    echo "1 found\n";
if (array_search(1, $a) >= 0)
    echo "1 found\n";
if (is_int(array_search(1, $a)))
    echo "1 found\n";

Functions that returns different data types are just evil, and they are everywhere in PHP. In this case, for example, they force you to use and grasp datatypes in a language which shouldn’t care much about them.

I just uploaded a new release of the Cosmos plugin to fix the duplicates detection.

PHP ain’t that funny, after all.

Technorati Cosmos in Textpattern

How do you get trackbacks without the spam and at the same time routing around your blogging software lack of that functionality?

Answer: you use some other tool, wich requires an even lower effort both on your and on other people’s side: Technorati Cosmos.

I started with a simple piece of code from Weblog Tools Collection, kept only the clever XML parsing trick and expanded it to a full Textpattern plugin. There was no license attached to that code, so I hope they are fine with me redistributing this.

So here is my Texpattern Technorati Cosmos plugin.

The plugin needs some easy configuration, in form of a Technorati Key and a cache directory wich must be writable by the web server.

To use it just place the tag <txp:mic_technorati_cosmos /> in your article form and you’re mostly done. With the default settings, the generated code will be like this:

<!-- Technorati Cosmos for http://currenturl -->
<h3 class="cosmos_label">Technorati Cosmos <a href=""><img src="bubble"></a></h3>
<ul class="cosmos_list">
    <li><a href="" title="">Cosmo title</a> &mdash; Cosmo excerpt</li>
    <li><a href="" title="">Cosmo title</a> &mdash; Cosmo excerpt</li>
</ul>

The label, the image and the excerpt can be customized and completely removed, please refer to the plugin’s help for more information. rel="nofollow" support is an attribute away, too.

You can see it at work in some of my articles and projects pages. Enjoy.

Update: New version with better duplicates detection

Textpattern WYSIWYG editor 0.3

I just released a new version of my Textpattern WYSIWYG editor plugin.

This new version adds a Toggle editor link beside the Title field in the left sidebar of the article’s edit page, which allows you to disable (and re-enable) the editor for a single post. When the editor is disabled Textile is enabled again for that post’ body and the article will behave as if the plugin wasn’t there.

I moved the initialization code inside the plugin, so you don’t need to download my TinyMCE code again if you already downloaded it before. Just update the plugin, activate it and you should be good to go.

The plugin is now smart about activating the fancy editor. If mic_tinymce is active, you’ll have a WYSIWYG editor in all new articles. If you disable the editor and write a post using Textile, the editor will not be activated when you edit that post again.

As you can see in the previous article’s comments, people are having troubles which I can’t nail down. I suspect those are problems with some browser. I’ll try to test it in IE as soon as I can, but remember that the plugin will not work in either Safari or Opera, and there’s nothing I can do about that, because they miss some necessary functions.

Update: in version 0.5 the plugin is completely disabled if you are editing an entry previously created with Textile – or equivalent – formatting.

You read it right: Textpattern WYSIWYG editor

It’s not that I don’t like Textile (altough I actually prefer Markdown and I use its PHP version in TXP), but a lot of people asked for a WYSIWYG editor in Textpattern and, whatever the nice guys at the forum will tell you, it is actually useful. Moreover, if a customer explicitily asks for it, you will just have to give it to him.

This plugin adds TinyMCE to TXP’s articles editor and is a modified version of the nice Wysi WordPress plugin. I modified it to use TXP’s setting, so you don’t even need do configure it: install, activate and use it.

Update: new version with post-specific Toggle editor function.

Here is a screenshot, installation instructions follow.

Textpattern WYSIWYG editor

The installation is a bit different than usual TXP plugins, but should be fairly easy:

That’s it. You should now have a new and improved article editor with integrated image browsing and upload.

Update: new release that automatically disables Textile in the article body.