Test-Driven Development - A Win!

I’ve been working on a set of Java classes to parse meteorological reports. I also decided to use the Eclipse Java Development environment for the first time to write these classes, and I can say that I’m very pleased with the integration of smart features such as:
  • “Quick Fix” which suggests code amendments on request – such as adding class imports, declaring new classes, and the like.
  • “Refactor” which lets me rename a class and automatically rename the class file as well, since Java wants it that way. Lots more capabilities in refactoring – will be looking at that soon!
  • Java debugging with breakpoints in Eclipse – I came from the “old school” way of gdb and text based debugging. Printf statements anyone? I still use printf’s to output tracing statements even when there’s debugging capabilities in XCode or Visual Studio.
But the most important feature I’ve realised is that of Test-Driven Development. In the old days, we’d write test cases to exercise our code. This was quite cumbersome as developers had to write code to do the test, including comparisons to make sure that the result of the test was correct. This took lots of time and you tend to spend just as much time writing the test code and test support functions as the actual code itself.

With the advent of Test-Driven Development and the plethora of tools supporting that methodology, testing becomes easy, almost fun! Key mantra:

Make something easy to use, it becomes an enabler



In my case, I used the built-in JUnit integration which Eclipse provides. I can right click on a class file, ask for a JUnit test to be created, and designate which Java package the resulting JUnit test class file is to be added to. What you do to write a test case is to simply write a Java function to exercise the function being tested.

I started using JUnit 3 and finally settled on JUnit 4 which uses annotations – part of Java 5.0 – to designate which test case functions are to be run by JUnit.

JUnit example after the break – more...

RapidWeaver Local Exports

RapidWeaver has an “Export Site...” menu item which lets you export your entire site to a local directory. That got me thinking – what if I could use the Mac OS X web server (which just happens to be Apache) to preview the site and test out tweaks to the theme CSS files? Turning on the web server is really easy:
  1. Go to System Preferences
  2. Select Sharing
  3. Click on the Web Sharing checkbox
That’s all there is to it. The contents of the Site folder in your user folder are used as the root of the website. To access your local web site, simply open Safari and type in http://localhost/~your_user_name - and voilà the default web page (index.html in Sites) comes up. In fact anyone on your local home network can access your website using Bonjour in Safari. What could be simpler!

The RapidWeaver theme I’m using for Free Range Coder is Unity 2.0 from NimbleHost. It’s a really nice simple theme which automagically adapts itself for the iPhone / iPod sized devices. It also uses PHP and the default configuration file for Apache in Snow Leopard does not have PHP enabled. I found this site which walks you through the configuration file changes for Apache and setting up the PHP initialisation file. In a nutshell:

To enable PHP in Apache - uncommenting the line below in /etc/apache2/httpd.conf:

LoadModule php5_module libexec/apache2/libphp5.so

Copying the default php.ini file from php.ini.default file in /etc:

cd /etc
sudo cp php.ini.default php.ini


The article goes on to show how to fix a warning in phpinfo() by setting the timezone in php.ini.

Back to RapidWeaver... So I dilligently exported the Free Range Coder website into frc in Sites within my Home directory. Launched Safari and typed in http://localhost/~kirschen/frc in Safari’s location bar and the page came up. But... It wasn’t what I had expected – the Unity theme style had not been applied.

And then I remembered what I had heard at the end of the Nosillacast Episode 301 - I’ll just check the Console Logs! I fired up Console (which we all know lives in the Utilities folder under Applications) and switched to All Logs. I typed in “apache” in the search bar in the upper right. And I saw bajillions (and that’s a technical term) of errors, all similar, one of which read:

[Sat Mar 05 12:43:41 2011] [error] [client ::1] (13)Permission denied: file permissions deny server access: /Users/kirschen/Sites/rw_common/themes/unity_v2.0/scripts/extracontent.js, referer: http://localhost/~kirschen/index.php

Aha! The plot thickens! This told me that some files were not readable by the Apache server, and where the files resided. Yes - the Unity theme. I whipped up a Terminal window and cd’ed over to /Users/kirschen/Sites/rw_common/themes/unity_v2.0 and listed the files therein using the ls -al command. The errant files had the same Unix permissions, an example – the one referenced in the Console Log – was:

-rw------- 1 kirschen staff 217 Mar 5 2009 extracontent.js

The rw indicated that the user (myself) had read and write permissions on the file, the dashes showed that members of my group (staff) and other users had no access permissions at all. So how does one fix permissions like this? No, you cannot use the Disk Utility “Repair Permissions” as Mac OS X knows nothing about what the correct permissions for these files should be. We’ll have to make the permissions changes ourselves from the Terminal. I could change the permissions in the frc directory but the next time an export was made from RapidWeaver, the Unity theme files would be overwritten and I’d be back changing permissions again. No, I had to make the change in the RapidWeaver theme directory. So, here are the steps from the Terminal:

cd “~/Library/Application Support/RapidWeaver” – This brings us to the RapidWeaver application support directory in which the Unity theme is installed

chmod -R go+r Unity-v2.0.rwtheme – The Unity theme shows up as a file in the Finder but it’s actually a file bundle. The chmod command will change the permissions so that the group (g) and others (o) get read permission (+r) and the -R option tells chmod to recursively go down the directory structure within the Unity-v2.0.rwtheme directory.

Re-exported the Free Range Coder site into frc – and it works as advertised! So now I can tweak the CSS files to my hearts content before committing the changes to the theme directly.

Review of MailTags

Here’s the review of MailTags from indev software which I did for Allison Sheridan at the Nosillacast Podcast hosted at podfeet.com. This is a follow up to the review of their Mac OS X Mail application plug-in Mail Act-On. Mail Act-On lets you go through your e-mails and process them quickly - filing, copying, tagging. Did I say tagging? Well, here’s where their plug-in MailTags comes into the picture.

MailTags is a Mac OS X Mail application plug-in much like Mail Act-On. It’s from indev software at indev.ca. What MailTags does is it lets you add tags to your mail messages, and much much more.

So - as always, what’s the problem to be solved? more...

Review of Mail Act-On

Here’s the review of Mail Act-On from indev software which I did for Allison Sheridan at the Nosillacast Podcast hosted at podfeet.com. But first, as always, there's a problem to be solved...

You like to be able to triage your e-mail inbox in your quest to attain inbox zero nirvana. My problem always has been that in order to get that inbox to zero, I had to move the e-mail to a folder to file it away. This of course meant either dragging the mail item to the appropriate folder - many times inadvertantly filing into the wrong folder.

Alternatively you could use the menu command Move To or Copy To and scroll down to pick the folder - not terribly useful if you had several bills to file away and you had to pop the menu, scroll, and click to select the same folder.

Of course you could create rules to automagically file the items away but for me, that meant “out of sight, out of mind” and I didn’t get to look at that e-mail anyway. And what's more you'd have to tweak the rules time and again when new e-mails need to get categorised.

more...

Prompt Puppy review

Sent Allison Sheridan over at the Nosillacast Podcast my review of Prompt Puppy. Hear and read all about it at Nosillacast #292.

Markdown and "Little Languages"

David Sparks @macsparky and Katie Floyd @katiefloyd in their MacPowerUsers 37 podcast talked about Markdown and MultiMarkdown. I actually used Markdown - see John Gruber’s Daring Fireball Markdown Syntax - in a project at work in which I had to generate documentation formatted as docbook. Fortunately there was a Markdown to docbook translator called Pandoc and it performed (almost) flawlessly - I had to add in a small macro in (ugh) UltraEdit to clean up the generated documentation so the Eclipse postprocessor would be happy with it.

This led me to recall a chapter I had read in Jon Bentley’s highly recommended programming book “More Programming Pearls: Confessions of a Coder” (ISBN 0-201-11889-0). Jon talks about what he calls “little languages” in Column 9, in which he describes a language as ‘any mechanism to express intent’ - thus the linkage to Markdown. Notations or languages such as LaTex, TROFF, and Markdown are akin to other “programming” languages such as C and FORTRAN in that they instruct the computer to process input and generate output. It’s just that these little languages hide a huge amount of complexity in their brevity and let us get on with the things we want to do instead of worrying about the actual syntax of the final output (docbook XML, HTML, instructions to a typesetting system…)

PS This post is written in Markdown within the RapidWeaver application for Mac OS X. The Markup Plug-In for RapidWeaver comes courtesy of André Pang, source code hosted at GitHub.

PromptPuppy: A cute little teleprompter

Just purchased PromptPuppy - it’s the little brother to PromptDog. It might be a “puppy” in name but PromptPuppy is no lightweight application though - it has one thing which I haven’t seen in a low cost teleprompter application - the cue arrow. This helps you focus on where you are reading from in the narration text. I’ve read from a text file when doing reviews and sometimes have found myself hopelessly lost in the mass of onscreen text characters, leading to multiple takes for a review. I’ve used PromptPuppy (10 day free trial) and did the review in one take.

Another neat thing is using the scrollwheel to control the speed at which the text scrolls - neat. The spacebar is used to toggle prompt mode on and off. Send a suggestion to allow you to save the window size, line spacing and font settings - this would make it so much easier to set up.

The folks at DVCreators.net, who make PromptPuppy and PromptDog, really take care of their users’ questions - got a couple of very quick responses. Got pointed to PromptDog / PromptPuppy by Cali Lewis (GeekBeat TV) in her “Behind the Scenes” episode in which she mentions PromptDog.

Best of all, you can install PromptPuppy on two computers - how neat is that! It runs under Mac OS X and Windows as well, and the two computer license covers either (or both) operating systems.

PS Do remember to note down the special referral code shown on the PromptPuppy site so that you get a discount when you decide to purchase it - every little bit helps!

OO Coding and Software Principles

Tim Barcz tweeted:

Agree or NO? "Interestingly with the influx of developers moving into OO coding there seems to be a revival of software principles"

Agree wholeheartedly! Here are some considerations:
  • OO coding brings in rigour in coding practices - leading to implicit adoption of good coding methodology.
  • Starting on learning something different and new, such as OO methodologies, may lead to developer to explore and learn good software principles, especially when OO methodologies are closely associated with software principles.
  • OO practitioners are by and large well founded in software principles - so a developer moving to the OO coding methodology would be motivated to adopt good software principles.

AADL Musings

Just got back from a course on the Architecture Analysis and Design Language (AADL) in Huntsville, AL. Stayed right next to the U.S. Space & Rocket Centre but didn’t get a chance to go visit. The Saturn V stands proudly and is visible from my hotel room window.

The AADL lets you model systems as a hierarchy of components, themselves systems. Systems are interconnected via data and event flows. You can also specify properties such as latencies, power consumption, execution time, heat, and weight - both expected and nominal values for each component. Analysis tools, such as those implemented in OSATE, can take these properties and check if the end-to-end latencies, power consumption etc. meet the expected values. Realisations of systems take the form of system implementations and it is possible to try out several different system implementations (e.g. multiprocessor, multicore, uniprocessor) and make several analyses to see which one works best. On top of that the AADL has a very well defined set of semantics for how threads are scheduled, how processes interact, the life cycle of a process, and so on. The AADL is also a standard maintained by the SAE.

I think there’s a place for the AADL in the software development realm - we haven’t done much in the way of rigorous analysis of throughput, many times only as an afterthought. I strongly encourage software system designers and developers to take a hard look at the AADL and see where we all can use the notation and properties to help us better analyse the throughput, latency, and other key performance factors in our systems.

QuickTime Development in Windows XP

Sometimes we just have to do Windows... One of the tasks at work was to design and implement a video player that would synchronise video playback across a number of computers (under Windows XP of course...). Naturally the video player engine would be QuickTime, of course! Fortunately Apple’s Windows implementation of QuickTime came with a number of ActiveX components and controls. However, I’m still using Microsoft’s (ugh) Visual Studio .NET 2003 (VS 2003) - because it works... There is little or no information in the Microsoft documentation or website about how to install controls onto the Toolbox so I can drag and drop them into my Form.

Did some judicious websearching and came up with this link: “The easy way to add controls to the VS2005 Toolbox” - which also works for VS 2003. Just drag and drop the DLLs into the Toolbox and voila - they appear! Easy yet quite obscure... Apparently the “Add Item” command works with VS 2005 but I haven’t tried it in VS 2003.

Programmer's Cheat Sheets

Check out these two sites for programmer cheat sheets:

http://devcheatsheet.com/

and

http://www.cheat-sheets.org/

I sourced the two Objective-C cheat sheets from the first site:

Objective-C Reference Card for Java Programmers (PDF)

and

Beginners iPhone Objective-C 2.0 Cheat Sheet V4 (PDF)

More on Things

I’m glad to say that keeping with the Getting Things Done mindset has been working beautifully. Firstly, it’s remembering to keep track of all my projects and actions using Things for the iPhone and Mac. When I can’t do that, I jot the task or action down in my Livescribe notebook or a small 3x5 flip notebook which I keep in my purse. Later when I have the iPhone or Mac, I transfer the task items into the electronic brain.

I’ve also emptied my e-mail inboxes for home and work - yes, there are NO messages in ANY of my inboxes! I triage my inbox each time mail comes in and move things to @Action, @ReadReview or @Reference mail folders, as mentioned by David Allen in his book. Then when it comes time to take action, I sweep through my @Action folder and dispatch them. Any e-mails which I need a response to, get filed into @WaitingFor - which I review regularly to keep track of the response.

It’s been almost 2 months since I started on my voyage with GTD, prompted by articles in ATPM (About This Particular Macintosh). It takes discipline to focus, organise references, gather tasks and determine next actions but the result has been worth it. My brain feels a whole lot less stressed since I’ve started putting all my project tasks and actions into Things - even home chores! I still need to sort out my filing system at home and at work - I’ve bought a Brother P-touch PT-2700 labeller (which works with Mac OS X) for home, and use the Brother labeller from my lab at work.