Author Archive

Pattern Traps

October 7th, 2009

Design patterns are ideas for solving problems that commonly occur in software development. Patterns provide a language framework for programmers, helping us to discuss abstract concepts in an efficient manner.

If you’re not familiar with design patterns, I highly recommend reading the seminal work by the Gang of Four: Design Patterns: Elements of Reusable Object-Oriented Software. Its a bit dry but an excellent read. I remember when Joshua Storck recommended the book to me many years ago; it opened my eyes to a higher level of programming and helped me grow from a task implementer to a software designer.

Patterns are helpful for structuring thought around problems and forming elegant solutions. However, there are a few things to keep in mind: Patterns have consequences, and patterns are not best-practices. Programmers must still apply thought. Terry Chay describes this in his article, Challenges and Choices.

I just came across an article by Amy Hoy in which she describes the dangers of over relying on patterns. She’s spot on:

People no longer treat patterns as the shared wisdom of experts, however. They are inclined less to bang their heads against a problem and then consult the Book of Wisdom to see what it says about their particular problem. Instead, they treat patterns as Wal-Mart for decisions. They don’t know what they want, exactly, but hey, this little item here on the shelf looks like a potential candidate.

They start with a pattern and see how to make it fit.

This is bassackwards.

We all build our own patterns around problems we’ve encountered. But just as with design patterns, its important that we force ourselves to think through problems creatively before jumping to more commonly treaded paths.

Fun with Rewrite rules and Zend Framework

April 25th, 2009

I ran into a problem with Apache’s mod_rewrite module this afternoon while setting up a Zend Framework web application. I had just setup a virtual host for my app and was setting up rewrite rules to forward requests to ZF’s front controller. However, I wanted requests for existing filesystem resources (such as CSS, JS, and image files) to be served directly by Apache, bypassing the Zend Framework.

 

Loosely following the ZF Quick Start Guide, I copied these rules into my VirtualHost configuration:
» Read more: Fun with Rewrite rules and Zend Framework

Identifying function usage in PHP code

July 24th, 2008

Its important for programmers to be able to quickly identify all usage of a function. Knowing where and how a function is called helps greatly in understanding the intent of the code and allows the programmer to refactor with confidence.

There aren’t any tools for PHP that identify function usage, the way one might do with Java using Eclipse. The recent release of Zend 6 for Eclipse comes closer with its refactor feature, but only refactors within a single file and not across a project.

I solve this need with a handy grep call. The following grep finds all usage and definitions of a PHP function, and omits results from .svn directories. Just replace FUNC_NAME with the name of the function you’re investigating.

» Read more: Identifying function usage in PHP code

Bike for Breath

July 18th, 2008

This is the 50 mile cycling route I rode with Lan, Dennis, and Jill during the “Bike for Breath” event on July 12, 2008. The route consists of moderate rolling hills, with the only steep climb being the short jaunt up Edgewood. The official ride map indicates 1,887 ft. of climbing – not much for a 50 mile route.

Bib, Bike for Breath 2008
» Read more: Bike for Breath

Installing MacFusion

July 17th, 2008

I recently setup a new MacBook Pro for web development. While trying to mount a samba share I discovered MacFusion, an application that lets you treat various remote storage mechanisms as if they were folders on your local hard drive. MacFusion is built on top of MacFuse, which is the OSX port of the Linux based FUSE that facilitates building filesystems that run in userspace.

» Read more: Installing MacFusion

SVN notifications

July 9th, 2008

I’ve been investigating how to send notification emails when changes are committed in a Subversion repository. Two interesting options I found are svnnotify and svnmailer.

» Read more: SVN notifications

Organizing log files into date based directories

April 10th, 2008

I recently had to grep through a few hundred thousand log files in a single directory. The logs dated back several years and had never been organized into directories. In fact, there were so many log files that grep’ing the directory resulted in an “argument list too long” error. This error is described clearly here, and the quickest solution is to use find to pipe the filenames into grep using xargs:

find . -name "*.log" -print0 | xargs -0 grep "xyz"

» Read more: Organizing log files into date based directories

The new VCR

April 3rd, 2008

The garage door opener is to me what the VCR was to my parents. After struggling with the garage door for a few hours, I decided I better write down some instructions.

I have a Craftsman garage door opener with three buttons on the controls. It uses rolling codes but aside from that all I can tell you is it sucks, its loud, and it never seems to do what I want it to, like opening.

» Read more: The new VCR