Comment driven development

There is quite a handful of programming techniques out there; TDD, BDD, YAGNI, DRY to name a few. This post will be about something many people might already be doing but don’t know it has a name: Comment-driven development or comment programming.

CDD is helpful for:

  • prototyping,
  • spitting out your thoughts in code editor, so you don’t forget anything later (good for brainstorming sessions),
  • explaining what needs to be done if someone else is going to be writing the code itself,
  • commenting the code :). Comments could remain, so your code is documented from the get-go

I often start the new PHP file or class or even method with the layout in comments. Here’s an example:

// Get the needed models
// Collect todo items
// Get lists that the todo items belong to
// Send to View

Ok, everything is clear. After the real code sets in it looks like this:

public function someAction()
    // Get the needed models
    $todoTable  = new TodoTable();
    $listTable  = new ListTable();
    // Collect todo items
    $todos      = $todoTable->findByAuthor($author);
    // Get lists that the todo items belong to
    foreach ($todos as &$todo) {
        $todo['lists'] = $listTable->find($todo['list_id']);
    // Send to View
    DIC::get('View')->todos = $todos;

As you can see, the comments can stay in place. Even for this simple example, it is good practice to document your code.

The Wikipedia article states:

In comment programming the comment tags are not used to describe what a certain piece of code is doing, but rather to stop some parts of the code from being executed. The aim is to have the commented code at the developer’s disposal at any time he might need it.

And later on:

However, comment programming is used instead of a real implementation. The idea is that many functions can be written like this, and then the design can be reworked and revisited without having to refactor a lot of source code.

So, Wikipedia article is somewhat contradictory to itself. The aspect of comment programming I am writing about here is the “comments instead of a real implementation” part.

Do you write your code with comments first approach? Do you use some other technique?

MySQL Workbench 5.2.35 on Ubuntu 11.10 64bit (Oneiric Ocelot)

Well, if no one is gonna do it, you have to do it yourself. I had the need for latest MySQL Workbench – 5.2.35, but I also upgraded to the latest Ubuntu, the Oneiric Ocelot (11.10). As with most of new things, I couldn’t get it to work out of the box, so little compiling session was in order. If you need the package, you can download the deb. It is for 64bit (amd64) architecture. This is the first time I have created a deb package, so I apologize in advance if I didn’t follow some basic rules.

MySQL Workbench 5.2.35 for Ubuntu 11.10 (64bit)

Test projects viewer

I have a couple of test projects in my test directory. This is where I usually put the latest wordpress, phpBB or any other script or web software I would like to test out or develop and play with. Until recently I had to access those by writing the virtual host path (www.test.local) and then append the directory name ( /drupal). I got tired of it, and coded a nifty little “browser” which displays all of the directories and files. Combined with the DNS wildcards, you can have unlimited virtual domains without having to configure them in vhosts, setting the /etc/hosts and restarting apache server. I have included this in the zip file found at the end of this post.

We are using bind dns server to resolve everything that comes to the “test” domain to your machines IP address. After that, Apache takes care of the rest. And what he does is kinda cool. The .htaccess file has a set of rules to test weather the index.php exists in the requested directory (via subdomain), and if it does, he redirects us to that directory. If the index.php doesn’t exist, our “main” index.php shows the contents of that directory, so you can select any other file and run it. Let’s start.

Continue reading “Test projects viewer” »

I got the (mt) hosting

I’ve seen a lot of hosting servers. Really a lot, I’m a developer. 99% of the time, they had cpanel, 99% of the time, one couldn’t optimize and setup his hosting place to meet his needs. That’s not because of the cpanel, of course, but because of the hosting company. My appetite for features and freedom of configuration got bigger over the years, so I got myself the  (gs) Grid-service hosting plan on Mediatemple. Upon sighting the /etc directory in my root, I got excited.

Continue reading “I got the (mt) hosting” »

Not enough time

5 or so years ago I wanted to make an audio amplifier. This year I finaly came around to doing that, only to be stopped, again, because of my schedule. We never have enough time. A day could have 48 hours, you’ll still be late for something, would forget to do some things you had to do. I don’t know. Where’s the catch? Do less?

Ubuntu + Palm = Something Completely Useless


Palm showing my CPU usage
Palm showing my CPU usage

If you, like me, own a Palm III and also use Linux for your OS, then you are a complete geek. My excuse of owning a Palm is that my friend gave it to me, what’s yours? But that’s not the point of this post. The point of it is to show what ELSE is Palm good for. It is hard to take notes, people look at you as a complete stranger, you can’t connect it to the internet (it’s Palm IIIc we’re talking about), there’s no GPS, so what’s it good for? Well, let’s assume you have a program and want to see the CPU and memory usage while you play use your program. One way to do that is to load System Monitor. But that’s not geeky enough. No, that’s for people who still have a life, not to mention a girlfriend. For us, über-geeks, with no life, external display is the way to go. And Palm is a really good looking external display :). Let’s start.

Continue reading “Ubuntu + Palm = Something Completely Useless” »

How I Learned to Stop using Windows and Love the Linux


Ok, not windows, I have used DOS 6.2, great OS. Move to dir, type command, play game. That’s it. Then installed Win 3.1. Lol. Nice windows. Now what? Windows 95 came out, and I thought “Great, now we’ll have the abilities of DOS and nice interface of Windows”. Errrr. Soon the 98 came out, and the ME. Nope, not there yet. With XP things changed. It worked, was stable (kinda), but ever so often, I had to reinstall my system. Then Vista came out, and after installing it, I was content. Not all programs worked, but that’s normal. I hoped for it to be more compatible, more lightweight.

Past month I decided to let go of the MS operating systems, and go for Linux. Linux always intrigued me. I downloaded my first “flawor”, Red Hat 9, a couple of years ago. Downloaded, burned, installed. Didn’t recognize all my hardware, installing new software was a pain in the ass, and finding good software that was alternative to windows platform was hard. I learned to compile stuff, search for dependencies, uninstall, this, that, but that was not something a normal kid would go for. No games. Sorry. Fedora came out. Ok, nice. A couple more encounters with Linux (System rescue cd was a good find) couldn’t convince me to turn over to open-source. Well, Microsoft did. Vista is just too hungry for RAM. And I don’t wanna buy more RAM. I think 1 gig is enough (if you’re not gaming). The latest Ubuntu was downloaded, burned and ready for install.

Continue reading “How I Learned to Stop using Windows and Love the Linux” »

PHP and template engines (and some other stuff)

I’m developing web sites for quite some time now, started when i was… Young? Yellow? Well, started a long time a go in a galaxy… AARGH! Can’t get Star Wars out of my life! Anyway. In the beginning i was using the good old php mess approach:

echo 'ul';
foreach($array as $item) {
    echo '<li>Some $item here</li>';
echo '<ul>';

And so on. For onepagers this was enough. So i stumbled accross mambo (former Joomla) and saw the raw power of cms and, well for me, good coding. K, let’s make ourselves a content management system. But how? What do we need? The neccesary ingridients where these:

  • Apache with php (obvious)
  • MySQL database (oh, what’s this database thing for?)
  • foresight

What’s the most important? No, wrong, not coffee. Foresight! Without analyzing and planning the outcome can’t be good. I started to code. Heavily. Took a good number of different approaches, all ended bit dull and like they couldn’t take on serious tasks.

Continue reading “PHP and template engines (and some other stuff)” »

WordPress SVN upgrade

Update: no need for this plugin anymore, the new WordPress handles updates on his own :( .

Usually when the new version of WordPress is out, you have to download the latest zip (or tar.gz), unpack it, upload everything, and run upgrade. You can help yourself with uploading the zip file to the server and unpack it there, but you have to have shell account and know a bit of console commands.

There is another way of upgrading to the latest version, and that involves usage of Subversion. This gets the latest of files but you still need the console. The command is:

svn co

So, to help with the upgrading process, I’ve developed the SVN upgrade plug-in. It uses the phpSVNclient and some other classes by Cesar, who posted it on PHP Classes. I took it and made the plug-in firstly for my CMS, and it works great. Than I saw that the WordPress can be obtained via Subversion, so I decided to make svn upgrade available to all.

SVN upgrade uses database (wp_svn table) in which it stores the latest repository revision. If a new revision is out, you can do the upgrade, otherwise it will tell you that it is on the latest version.

Oh, and I have just tested it, again. 8061 is out! Bleeding edge! wp-login.php just got debugged, or something, and i have it! With just one click! Great!

Continue reading “WordPress SVN upgrade” »