Learning Design Patterns – Command Pattern

This week I'll be taking charge of the Command Pattern in my series on design patterns plucked from this book and from examples on the Internet.

What is it?

A simple analogy for the Command Pattern is a remote control. When you are clicking through your 637 channels looking for something in English that isn't tying to sell you something or change your political or religious point of view, you're giving commands to your remote, which then tells the system to increment the channel by one.

And when you use a universal remote and set your TV to channel 3, your VCR to channel F1, your sound system to Video, and then turn on your DVD player to watch a movie you rented from Blockbuster because nothing is on TV; your remote is issuing commands like "On" to each device, and the device is responsible for taking care of the details of turning itself on. If your remote was hardwired to turn on each component, you would have to open it up and add more code each time you switched out one TV for another – that's tightly coupled!

The Command Pattern can include more than just the ability to encapsulate requests; it can also queue up commands and log them, and support an "Undo" operation. By extending the pattern slightly, you can also create the ability to run a macro command that executes several commands at once – imagine a universal remote that has an "all-on" button that turns all of your devices on at once.

Sharing my cool toys

I was berated the other day by Keith. He told me about PLEAC and I said yeah, I know!! He said no fair you didn't share your cool toys! So for all you remaining coders out there, I'm sharing! Here's a few handy code snippet sites and I'll review for you today.

This site uses the Perl Cookbook as the basis (which has the Perl source freely available) and volunteers rewrite the snippets in other languages where possible. Very handy, if you know one language and wonder how you would do it in another language.

Learning Design Patterns - Decorator Pattern

This week I'll be hanging the Decorator Pattern in my series on design patterns plucked from this book and from examples on the Internet.

What is it?
An important design rule is to design your code to be open for extension, but closed for modification, and the Decorator Pattern is one way to go about extending existing code. The decorator wraps up an existing object and then adds functionality to it; and since the decorator is of the same type as the object it wraps, the effect should be seamless for client code (unless client code is relying on the concrete type of the original object).

Learning Design Patterns - Factory Pattern

This week I'll be manufacturing the Factory Pattern in my series on design patterns plucked from this book and from examples on the Internet.

Master Plan v0.2

CodeSnipers has been growing pleasantly over the past few months and I believe it's reaching a critical tipping point. After the holidays, there are going to be a series of announcements about new functionality, areas, and ideas that will be coming about in this little community. If all goes well, some of them may happen when they're announced.

Anyway, towards this goal, I'm looking for a few brave people to share their thoughts, bare their souls, and generally start a discussion with the community. I'm not looking for just any people, but people with particular skills:

First, I need a .htaccess/mod_rewrite wizard. I'm not looking for any work to be done, but just to get some questions answered and bounce some opinions around.

Interview: Tom Copeland of PMD & Rubyforge

This is the first in a series of interviews we're making available to the CodeSnipers community. We have been working to track down people who we thought had something valuable to say about the software development community, tools, practices, or direction. Some of the names you will recognize immediately, others you've probably never heard of, but all of them have made an impact in one way or another. Without further delay... our first victim... er... is Tom Copeland of the PMD project.

Some of our community may be familiar with the Java tool PMD, but many are not. Could you tell us a bit about PMD and your role in the project?

Sure! PMD is a utility for finding various "opportunities for improvement" in Java source code. It uses static analysis, meaning that it parses and analyses the source code without actually running the program, to find unused code, unnecessary object creation, and bad practices. You can run it using Ant/Maven/command line/various IDEs and generate text, HTML or XML reports.


Wow, what a productive week!

No, I'm not kidding. I'm on fire, kids. Just having a good week, cranking out lots of good, working code. I've been kickin' ass and chewin' gum, and I'm almost out of gum. You know how it is: sometimes you're on and sometimes you're not. This week I was on.
Something I'm feeling good about: I have a large degree of autonomy on my latest project. I gathered a pile of requirements and went to town. Just for kicks, I decided to try a development approach I've read about but never got to try in a production environment: refactoring to patterns.

For those of you who are old hands at this, accept my apologies, stop reading this, and go watch Arrested Development instead. The rest of you, if you're still awake, finish reading, then go watch A.D.

Is Java worth it?

I'll admit it: I never bothered to learn Java. I've never needed Java. It seems like there are lots of catchy words that the Java community uses: Struts, Beans, Tomcat. In passing, I understand what these words mean, but I will never know the full impact of what they provide, because I've never bothered to learn it.

And yet, I've done okay. I know Ruby and Perl and Python, so I can script my way through many projects. For more advanced stuff, I can use C or C++ to get the job done.

It seems like I've got my dynamic and static bases covered. So dear readers, tell me: do I need to learn Java? Am I missing out something great? Or has the Java fad passed?

How I saved my company one penny

Somedays as a developer you really know that your work affects the bottom line, and other days you are putting lipstick on a pig. This is my story of how I once saved my company a whole penny through a day of in the trenches code sleuthing. Money machine or hog hairdresser? You decide.

Book Review: Java Extreme Programming Cookbook

Since I've been talking about Unit Testing quite a bit recently, I thought I'd offer up a review on a book I read a while back. I thought it was a solid roundup of both the principles and the tools used to support Extreme Programming in Java. Overall, I'd give it a 9/10 and I deduct a point solely due to the fact that since it details the usage of numerous Open Source projects, it's halflife could be very short. Regardless, this is more than enough to get you started and will teach you the basics to be able to do even more interesting things.

Just to make this clear right off the bat, if you're not working in Java, only pages 11-27 are going to be of any use. These pages go over the different pillars that make up Extreme Programming (XP). Whether you're using XP or not, you can pick and choose the pillars you need and customize them to your project pretty easily. The principles are: Pair Coding, Unit Testing, Refactoring, Iterative/Minimal Upfront Design, and Regular Builds. I have yet to see a project that cannot benefit from having Unit Testing and Regular Builds in place. These two items serve as a great safety net for current and future development efforts by detecting errors soon after insertion.