Lance Wicks
Kiwi,
Judoka,
Geek,
Husband
Daddy!

JudoGeek Blog

The Matrix Parody. 

You've probably seen this one, but in case you haven't this is a really sharp piece of satire. What if the Matrix was running on Windows XP?



I came across it via Popey's blog (who found it here)and the original is here. Like the man says, hang in there till the punchline at the very end.
[ view entry ] ( 3003 views ) permalink
TDD with Perl, Episode 2 - Getting Started. 

Test Driven Development or TDD is a increasingly common phrase and idea that you need to get your head around. The concept here is that you write pieces of software that tests the actual software you are writing.

The idea is that for every subroutine you write, you write a test (or several tests actually) that proves it works. In the purest methodology you write the test first, then the code. But for someone new to it, this is not realistic. That said, the sooner you start writing tests, the more sense it makes and the easier the process.

So how do you begin? Well that is what we cover here, Basically what we will do is create a "Smoke Test" script and a bunch of generic tests and also start of testing some of your subroutines. What I include here is based heavily on .......

What is a smoke test?
Okay, here is my take on what smoke testing is. A smoke test is basically a script that runs a bunch of other tests. The idea being that it'll test all your other tests and come back saying all is well. Your smoke test will be run all the time just to give you confidence that everything is well with your project. Think of it as a summary of all your other tests.

How do I start smoke testing?
Basically you need a smoketest script (mine is called smoke_test.pl) and some .t test scripts. So lets start with the smoketest script, heres mine as an example:

#!/usr/bin/perl
use File::Find::Rule;
use Test::Harness qw(&runtests);

my $rule = File::Find::Rule->new;
$rule->or(
$rule->new->directory->name('CVS')->prune->discard,
$rule->new->file->name( '*.t' )
);
my @start = @ARGV ? @ARGV : '.';
my @files;
for ( @start ) {
push( @files, (-d) ? $rule->in($_) : $_ );
}

runtests(@files);


You "should" be able to cut and paste this into a file and save it as smoke_test.pl. Next you need a test script, here is one I have:

#!/usr/bin/perl
use File::Find::Rule;
use Test::More qw(no_plan);

sub check {
my $filename = shift;
local $/ = undef;
open( my $fh, $filename ) or
return fail( "Couldn't open $filename: $!" );
my $text = <$fh>;
close $fh;
like( $text, qr/use strict;/,
"$filename uses strict" );
} # check()


my $rule = File::Find::Rule->new;
$rule->file;
$rule->name( '*.pm', '*.pl' );


my @files = $rule->in( './');
for (@files){
check($_);
}


You can cut and paste this into a file called say use_strict.t and save it.

Run you smoke_test.pl script (perl smoke_test.pl) and it should run the use_strict.t test on every .pm file in that and sub directories. Now, if the only code you have in this directory, your smoke test will fail... that's ok, its what should happen at this point.

If you look at the output of the smoke test you should be able to see that smoke_test.pl failed the use_strict test, which is right as at the moment it does not have "use strict;" near the top. Go add it just above use "File::Find::Rule;" and re-run the smoke test. Hopefully it will now pass.

Congratulations!
You have now done your first bit of test driven development TDD. Your use_strict test pointed out a flaw in your code (you didn't have "use strict;" in your smoke test). You corrected the error and now you test passes.

So whats next?
Best practise says we should use "Use warnings;" in our code too, so lets test that we are doing that. Here is my example use_warnings.t file, feel free to cut and paste:

#!/usr/bin/perl
use File::Find::Rule;
use Test::More qw(no_plan);

sub check {
my $filename = shift;
local $/ = undef;
open( my $fh, $filename ) or
return fail( "Couldn't open $filename: $!" );
my $text = <$fh>;
close $fh;
like( $text, qr/use warnings;|perl -w/,
"$filename uses warnings" );
} # check()


my $rule = File::Find::Rule->new;
$rule->file;
$rule->name( '*.pm', '*.pl' );


my @files = $rule->in( './');
for (@files){
check($_);
}


Now run your smoketest script again. Oh no! It fails again right? Similar issue, your smoke_test.pl script hasn't goy "use warnings;" in there has it, go ahead and add it. Hopefully your smoketest should pass now.

You are now a TDD developer!!!
You wrote your test first, it failed, you altered your code, the test passed.
This is basically what TDD is all about, you decide on something you want to write/add, before you add it, you write a test to prove the feature worked. You run your test, which fails. You THEN write the code to do whatever you wanted, then test again, hopefully it passes. Then you repeat this for every change to your project. Write test, run test, write code, run test....

But I have not tested my code?
True, so lets do an example of that now...
We are going to write a little module that tests if testing is cool.
Start of by creating a file called tdd_is_cool.pm and a file called tdd_is_cool.t
Inside tdd_is_cool.t lets write some stuff to let us get started testing using Perl's Test::More (which we have already been using):

#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 2;


So hopefully you get the first three lines already, they are basically just normal for Perl code ok. Now, line three... Line three loads the Test::More module and tells it that we are going to run two tests.
Next we add:

use_ok( 'tdd_is_cool' );

This tests that you can load your tdd_is_cool.pm file ok. You can run your smoketest now and it will fail.

now add this line:

is( tdd_is_cool::test_cool(),'1','TDD is cool!');

This line calls a subroutine in our (unwritten) module and checks if it returns '1', if so then testing is cool. You can again run your test (and your smoketest and they will both fail).

So lets write our module, heres a bare minimum for you to cut and paste into tdd_is_cool.pm:

#!/usr/bin/perl
use strict;
use warnings;
package tdd_is_cool;


sub test_cool {
return('1');
}
1;



Now run your tests and hopefully they should pass!! You are now well down the path of TDD.

Remember, its as simple as deciding what you want to write, writing a test for what you are going to write, then writing the code that does it.
[ view entry ] ( 2159 views ) permalink
Freshbooks continues to impress me. 

Freshbooks is, to use their own words:

an online invoicing and time tracking service that saves you time and makes you look professional


To use my words, Freshbooks is darned impressive!

With my recent departure from paid employment to working for myself, I needed to sort something out to do billing and I had heard of Freshbooks so I gave it a go. Which is really easy to do as it's free to start off with.

Once you are in, you can customise the setup and start creating invoices etc. I in fact started off by doing an estimate for someone. It emails it to them and they can accept it online. Very cool, you get an email confirmation that they have approved it too.

Then, as you do work you can track your time spent. Which is pretty cool. Especially for iPhone users like me as they have a native application you can install on your iPhone that has a stop watch and lets you log time against projects.

From that time logged, or form the estimate you can create your invoices. The invoices are delivered by email AND by snail mail if you want. Which is really cool! Although being American they do send to the UK/internationally and the rate is reasonable and easy to understand.

I think this is so great! It just takes the hassle away from me. The moment I finish a job I create the invoice electronically and the invoice gets printed, stuffed in an envelope and sent by someone else. And it's pretty quick, couple of days to arrive, pretty much the same as if it was sent from the UK. Sure it's a bit more expensive (argueably), but there is ZERO hassle!

Once payment is received you can tell the system... or Freshbooks also allows your clients to pay online via PayPal. Then it records the payment for you.

They provide reporting of aged debtors and that sort of thing too, so that is great.

It is still early days with Freshbooks, and I am sure their is competitors out there (actually I'd like to check them out if you like to recommend one). But to date I have been blown away by Freshbooks. And in fact it's so great a client of mine actually commented on how cool Freshbooks is.

When was the last time someone commented about how cool your billing software was??

Anyway... I thoroughly recommend Freshbooks at this stage, and totally think they are worth a shot for your small business or "side project" billing.

Signing up is free and easy, all the features are available free, and you only start paying when you send invoices by snail mail or when you have enough clients to need to.

So go give them a try, you can sign up at https://lancewicks.freshbooks.com/signup/ and get started. (and yes there is a referral system so if you sign-up via the links in this post I'd appreciate it. :-)

Lance.

[ view entry ] ( 2303 views ) permalink related link
A quick Kiwi post... 

As most people who read this blog will know, I am from New Zealand, this post is a quick summary of some things relating to N.Z. I wanted to share.

Firstly and it is even more relevant given Obama's vistory in the USA; this weekend New Zealand goes to the polls too. Despite the fact I now live outside of New Zealand I (and you fellow ex-pat kiwi) are eligible to vote... and should do so.

It's pretty easy to do, and you can still get you name registered, even now! Just hit http://www.everyvotecounts.co.nz/ and sign up.

Voting is a really powerful thing to do, I think it was a friend of mines father who said something along the lines of
"..if you don't vote, you have no place moaning.."
. So get your butt in gear and get registered... it is not too late!

Speaking of friends, (and I think it was his father I mentioned above) my very very close friend Regan Morgan has a blog that I have started following. Regan is a photographer (amongst other things) and it's actually the only blog I follow that is so visual. In each post he puts a photo he has taken with a little snippet of text about it. It's a fascinating RSS feed. So far my favourites have been the Red Baron photos.
The other awesome little feature of his site I have found and think is genius is the "About Me" area. It is really fun, really informative and mostly (I think) really effective.

I don't think Regan and I have ever really sat down and discussed the web, blogging, online reputation, etc. But if we had, I would have suggested he tackle his website just like he has! In fact, I think I see some changes to my sites coming based on what he is doing.

Now the other thing I wanted to post about was NZEdge.com and the NZedge Blog I get their email newsletter and really enjoy doing so as it updates me to the great things we Kiwi's are up to and have done in history. So I do recommend hitting http://www.nzedge.com/register/ and signing up for the emailnewsletter which comes in every few weeks.

So there you have it, a Kiwicentric blog post for once.

Lance
[ view entry ] ( 2528 views ) permalink
Update... business coming together. 

So first up, my MacBook Pro is back and working lovely, thanks for asking.

It was interesting to spend a few days on the Zonbu. The Zonbu is a Everex laptop, running a optimised version of Gentoo Linux. What differentiates the Zonbu is what they call a "Cloud assisted OS" meaning that it utilizes Amazon's S3 storage to store your files and basically the laptop only holds a cache of the latest files you are using.

The machine works really well, and the battery life is awesome. Luckily for me, I also use cloud based backup as part of my personal backups. So I was able to get to all my files. Now the Zonbu has a limited range of applications on it.

All this said, I write this on my MacBook Pro and it's just a vastly superior piece of engineering. And OSX is wonderful. Very pleased to be back on my MBP.

Whilst in the Apple store I looked at the new MacBook Pro. And... I don't actually think I like it. Looks nice, I guess. But it's got the old MacBook keyboard. And I am not sure I like that. For a start, the enter key is the same as on the old 17" MacBook Pro (roughly a 7 shape). I went with the 15" MBP basically because the enter key is a nice large rectangular key. Hard to miss, and given how often you press it, I think that matters. I dunno, what do you think?
UPDATE - Nov 12, 2008: Apparently Ovid agrees with me about the awful enter/return key on the new MBP. http://use.perl.org/~Ovid/journal/37844

What did look tempting though is the MacBook Air. It is just too sexy! Of course so is the iMac. Almost grabbed a wireless Apple keyboard too, they are sexy also. Maybe that's the migration path? Wireless keyboard first to get used to the layout and then onto the new MBP.

All that said, DAMN they cost alot!
The Zonbu is only $479 and too be frank it works fine. If they came out with a laptop that looked as good as a MBP, I might go that way. Or perhaps I'd just buy a sexy looking Laptop and put Ubuntu on it?

Anyway, quick update on life/work... now I am out of the world of being a wage slave, I am a man under my own steam, and it's coming along pretty well. I have clients, which is always a bonus!

I spent today getting my business affairs in order, so sat down with accountant, sorted out business banking etc. I got some great business administration advice and basically had a good day.


[ view entry ] ( 1855 views ) permalink

<<First <Back | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | Next> Last>>