Friday, December 30, 2005

Semco and Ricardo Semler - Agile Industry?

Some Semco links:

CNN, 2004:

Excerpt from Semler's 2004 book "The Seven-Day Weekend"

Wikipedia entry on Ricardo Semler:

An excellent interview with Semler by CIO Insight, unfortunately dated April 1, 2004:,1217,a=124700,00.asp
Very good stuff about corporate email privacy, among other issues, here's an excerpt from Semler:
...we searched far and wide for anybody who could tell us what kind of software or system could be installed on our [server] that would make it impossible for our own IT people to spy on people's e-mail. We did not find one. We had to customize one.

Friday, December 23, 2005

Working Effectively With Legacy Code

I'm preparing for a new contract (with Barclays Global Investors) where I'll be helping to improve a software developemnt process in a group that has many years of existing code, so I've been reading Michael Feathers new book "Working Effectively with Legacy Code" (

So far, I really like the book - it quite modern, coming from an agile/XP approach and consistently emphasizes that the basic task is to get the legacy code under a test harness, so that changes can be made with fewer ulcers.

The book goes into many different examples of how existing code is resistant to being testable, and then shows (usually two or more) approaches for overcoming or workign around those problems.

Another reason I like that the book is that Feathers consistently emphasizes how hard this is - no magic solutions, ugly compromises often required, etc. but that you can make big progess out of many small steps.

Sunday, November 27, 2005

Unit Testing in Perl with Test::Unit

I've come to prefer Test::Unit over Test::More. The main reason is that in Test::Unit you define each test as a separate subroutine, so the variables used for one test cannot pollute another test.

Test::More is a widely used module for Unit Tests in Perl. With Test::More your tests look like this:
# Test method_a()
my $expected_1 = 23 * $CONSTANT; # some value we expect;
is( $expected_1, $object->method_a(23),
"method_a(23) returned expected value.");

my $expected_2 = 17 * $CONSTANT; # A new expected value
is( $expected_2, $object->method_a(17),
"method_a(17) returned expected value"

# Test another_method()
my $expected_3 = _get_favorite_color();
is( $expected_3, $object->another_method('favorite'),
"another_method('favorite') returned proper color.");

my $expected_4 = _get_recent_color();
is( $expected_4 $object->another_method('recent'),
"another_method('recent') returned proper color.");

See how we need to come up with many versions of the $expected variable?

We could also just reuse it, but that can cause trouble if there are many tests and you forget to reset it.

It is better practice to use a different variable name for each test, but in many situations there are a couple dozen tests in that one file where it makes sense to use the same basic variable name for many different tests. That could lead to variable names like $expected_100. Also, there is always the risk that some temporary variables used for one test end up "polluting" a later test where the programmer didn't realize a variable was already defined earlier in the file.

The best solution is to isolate the code for each test, or small group of related tests into their own block, so that temporary variables for one test cannot interfere with another test or tests.

In Test::Unit each test is a subroutine, which can contain any number of assertions - so all the temporary variables and other setup for a particular group of tests are kept isolated from all the other tests. In addition, if you provide a subroutine called set_up() it is automatically called before running each test subroutine, and likewise, tear_down() is called after each test, this is useful for populating objects and test data structures, so that each test gets a clean set of test data to work with.

In Test::Unit the tests above might look like this:
sub test_method_a {
my $self = shift;

my $expected_1 = 23 * $CONSTANT; # some value we expect;
$self->assert_equals( $expected_1, $object->method_a(23));

my $expected_2 = 17 * $CONSTANT;
$self->assert_equals( $expected_2, $object->method_a(17));

sub test_another_method {
my $self = shift;

my $expected_1 = _get_favorite_color();
$self->assert_equals($expected_1, $object->another_method('favorite'));

my $expected_2 = _get_recent_color();
$self->assert_equals($expected_2, $object->another_method('recent'));
Test::Unit provides a bunch of assertion methods:
assert_equals / assert_not_equals

Tries to guess what kind of comparison to make. Usually works fine. If the first argument (the 'expected') is an object it checks if the == operator has been overloaded and will use it if so.


Force numeric/string comparison.

assert_matches(qr/PATTERN/, STRING, [, MESSAGE]), assert_not_matches

Assert that the regular expression matches.

assert_deep_equals(expected_ref, ref_to_test [, MESSAGE ])

Used to compare complex data strucrtures, like hashes of arrays of hashes. Assert that the the data pointed to by ref_to_test matches the data structure pointed to by expected_ref

See also:

Tags: ,,

Friday, November 04, 2005

Perl Best Practices

Damian Conway's new book, Perl Best Practices is a very good, thought provoking, and useful addition to any Perl programmer's collection.

From my point of view, the best thing about the book is that it provides a lot of food for thought - even if one disagrees with particular recommendations I think all the suggestions in the book areworth thinking about, and I am certain almost any reader will discover improvements they can make in their code and approaching to coding.

Tags: , perl

Sunday, October 23, 2005

PHP Comes to Eclipse

Martin Brown blogged about PHP coming to the Eclipse platform (back on Oct. 18th.) This interests me because I find that currently is the best cross-platform for , a language I like very much. (See my article at, "Perl Needs Better Tools")

Wargaming - another way of modeling the universe

I found a reference to myself in Kevin Trainor's blog, Wombat Rampant. The posting is about the decline of paper-based combat simulation games. Back in the 1970's I used to design and play , which to me, are part of my lifelong involvement with building things.

Saturday, October 22, 2005

Take Control of Permissions in Mac OS X

My long-time friend and colleague Brian Tanaka has written a new eBook "Take Control of Permissions in Mac OS X" that provides a bunch of help for the average Mac user in dealing with the often mysterious subject of "permissions" and "ownership" of files and folders in .

Permissions and ownership of files and folders are a tough subject.

Part of the reason, I think, is that there isn't a really good physical-world analogy - objects in the physical world don't have -rwxr-xr-x attached to them, so it's a pretty alien concept - in the physical world, if you can touch it you can write on it, now maybe you shouldn't write on it, because of laws, social custom, etc. but there are no attached permission settings, and no operating system to enforce permissions. Ownership is an easier concept for people to grasp, because of the extensive real-world analogs.

Brians' eBook is a good, searchable, handy guide to dealing with these issues, and it's only ten bucks. You do not need to know, or care about Unix to benefit from his guide, and even experienced users will find stuff they didn't know - for example what "Repair Permissions" and "Ignore Ownership" actually do.

If you want to really dive into learning the Unix layer of Mac OS X, and can handle a higher price-tag, and dealing with a paper book, then I recommend my book (shameless plug, I know) "Unix for Mac OS X Tiger", but to focus on just Permissions and Ownership, Brians' book is a fine place to start.

Wednesday, October 12, 2005

How to estimate memory usage for a large hash?

I had a conversation recently about how to estimate the size of storage for hash keys when processing a huge data set.

Let's say you are gonna process 100,000,000 name/value pairs and you want to estimate how much memory is needed to store the list of unique names - is there a current "best practice" for this?

Problems with log files and daemontools

Daemontools is a software suite for Unix that makes it easy to run any program or script as a daemon.

I recently ran into an interesting problem with - none of the STDOUT output from my daemon was showing up in the log file.

It turns out that your daemon must use unbuffered STDOUT or it won't go into the log file. In my case the daemon is a Perl script so I added automatic flushing of output buffers to the script, and it works. That means I added this:

$| =1;

to the Perl script.

Saturday, September 24, 2005

Unix for Mac OS X Tiger - book released

My book "Unix for Mac OS X" is now out in a new edition, completely revised for OS X 10.4 (Tiger).

This book is a very complete beginner's guide to Unix. The book assumes no prior Unix experience and yet provides more detail than any other beginning Unix book of which I am aware. In my not-so-humble-opinion the book is probably the best beginners guide to Unix on the market.

The book is over 500 pages and provide great detail on the Unix layer of (aka Darwin.)

The book teaches you how to get to the command line, to edit files using a command line editor, to deal with Unix permissions (an entire chapter on that), and so on. I'll post a table of contents in a later posting.

Buying it:

Saturday, September 17, 2005

Unit Testing in Perl

I've been using the Test::Unit module for creating unit tests and I like it.

The most common module for creating Unit Tests is probably Test::More. For me, there are two important advantages to Test::Unit

1. In Test::Unit each test is actually a subroutine, so the variables etc. you create for one test are isolated from those created for other tests.

2. Test::Unit automatically runs a method called setup() before each test,a nd teardown() after each test, which is useful for things like populating a test database, etc.

Friday, August 26, 2005

Perl Needs Better Tools

My article on better tools for just came out on

I describe many of the features available in modern Integrated Development Environments (IDE) and talk about what a good Perl IDE should have.

I'll be able to respond to comment there and here for the next dayt or so, then I'll be offline for over a week.

Sunday, August 07, 2005

Unix commands unique to Darwin/OS X

I'm in the process of finishing the revised edition of my book, "Unix for Mac OS X" to cover OS X 10.4, Tiger), and am hoping to include a list of Unix commands that appear pretty much only in Darwin/OSX. Here's a pre-release version of the list:

Dispatches from Blogistan - a travel guide in the making.

Long-time friend Suzanne Stefanac is on the case at creating a new book for Peachpit Press.

Given Suzanne's experience with media and facility with people, this should be a friendly, intelligent and insightful work. I hear she is going to include a chapter on Good Writing, something we could all use some help with.

Monday, August 01, 2005

Ruby-on-Rails looking interesting

OK, I admit the momentum is getting to me.
I started looking into Ruby several years ago, but never built anything with it.

Now, thing like this post showing how little code can be needed are making me itch to try again.

Sunday, July 31, 2005

Progress on Perl tools Article

I finally finished a complete first draft of my article for on better development tools for Perl. It's been sent off to chromatic at O'Reilly and hopefully I'll hear back soon.

VIP - New Perl Editor Project

Kaare Rasmussen told me about a new CPAN project led by Nadim Ibn Hamouda El Khemir called VIP:

The goal of the VIP project is to produce a first class Perl editor that
can be used as a component in a (yet to be developed) IDE. We will try
to write vip so it will build on the strong points of of Perl 5 and 6.

Our first step is to provide the editor itself. It will consist of the
core engine and have (at first) three interfaces; used from Perl itself,
a text based (curses) and a graphic (gtk) interface.

Apart from the usual features, such as syntax coloring and
templates/wizards, we plan to include innovative features, like support
for Pair Programming, and to make it extremely configurable and
pluggable (integration with Sprog ( will
be one way to extend Vip).

The project is currently in the initial phase and we expect to have a
working draft within the next couple of months.

We can always use help. To test it out, find bugs, propose features and
write documentation, plugins and code.

The project has a name on CPAN:, a home page
(http://...) and a discussion forum (

Problem installing MySQL 4.1.13 on Mac OS X 10.4.2

Bug report filed with :

Here's the bug description:
Trying to compile MySQL 4.1.13 on  10.4.2
gcc_select show gcc 4.0.0:
$ gcc_select
Current default compiler:
gcc version 4.0.0 20041026 (Apple Computer, Inc. build 4061)

$ locate gcc_s

The build fails with:
Making all in sql
if g++ -DMYSQL_SERVER -DDEFAULT_MYSQL_HOME="\"/usr/local/mysql\""
-DSHAREDIR="\"/usr/local/mysql/share/mysql\"" -DHAVE_CONFIG_H -I. -I. -I..
-I../innobase/include -I../include -I../include -I../regex -I. -O3
-DDBUG_OFF -fno-implicit-templates -fno-exceptions -fno-rtti
".deps/gen_lex_hash.Tpo" -c -o gen_lex_hash.o; then mv -f ".deps/gen_lex_hash.Tpo" ".deps/gen_lex_hash.Po"; else rm -f
".deps/gen_lex_hash.Tpo"; exit 1; fi
/bin/sh ../libtool --preserve-dup-deps --mode=link g++ -O3 -DDBUG_OFF
-fno-implicit-templates -fno-exceptions -fno-rtti -DHAVE_DARWIN_THREADS
-DIGNORE_SIGHUP_SIGQUIT -o gen_lex_hash gen_lex_hash.o ../myisam/libmyisam.a
../myisammrg/libmyisammrg.a ../heap/libheap.a ../vio/libvio.a
../mysys/libmysys.a ../dbug/libdbug.a ../regex/libregex.a
../strings/libmystrings.a -lz -lm
mkdir .libs
g++ -O3 -DDBUG_OFF -fno-implicit-templates -fno-exceptions -fno-rtti
-Wl,-bind_at_load ../myisam/libmyisam.a ../myisammrg/libmyisammrg.a
../heap/libheap.a ../vio/libvio.a ../mysys/libmysys.a ../dbug/libdbug.a
../regex/libregex.a ../strings/libmystrings.a -lz -lm
/usr/bin/ld: can't locate file for: -lgcc_s
collect2: ld returned 1 exit status
make[2]: *** [gen_lex_hash] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

How to repeat:
Use source distribution mysql-4.1.13.tar.gz

$ tar xfvz mysql-4.1.13.tar.gz
$ cd mysql-4.1.13
$ ./configure --prefix=/usr/local/mysql
$ make

Build fails.

Suggested fix:
None known yet.

Monday, July 11, 2005

Access Control Lists (ACLs) in Mac OS X

Powerful but complex, and hard to understand.

chmod +a "dancers allow list,directory_inherit" dropbox

should allow anyone in group dancers to list the contents of dropbox and any subdirectories, but the inheritence doesn't seem to happen.

Saturday, July 09, 2005

New refactoring book in the works?

I heard from a reliable source yesterday that O'Reilly is considering doing a book on Refactoring. Maybe they'll include Perl in it.

Saturday, June 25, 2005

Perl IDE's

Two of the most sophisticated graphical Integrated Development Environments (IDE) for Perl are probably EPIC and Komodo.

Two command-line IDE's are emacs and vi/vim. There are a variety of extensions that people have created for these two venerable text editors that provide many of the capabilities of graphical IDE's.

Better Development Tools for Perl, or Perl is Dead

I'm working on an article for O'Reilly's wherein I assert that what Perl needs is few great Integrated Development Environments that equal or exceed the features currently available for Java.

An early rough set of notes on the subject is online at

The fully developed article should be on in a month or two.

A related an valuable article is Adam Kennedy's article on his new PPI module.