Template Method Trap

Inheritance is often a trap. Its starts off like an adorable lion cub but grows up to be a man-eater. One common use of inheritance is within the Template Method Pattern. It is the Jekyll and Hyde of patterns; half pattern, half anti-pattern. What is Template Method? Let me step … Read full article

On the outside looking in

Programmers tend to look at software design from the inside out, but that approach has many pitfalls. Looking at software development from the outside in provides us with some real advantages including ease of integration and ease of concurrent development. Read full article

If Programming is an Art

If you accept the premise "programming is an art" where does that leave you? I believe we are better served by defining our goals by objective measures instead of subjective measures such as beauty. Read full article

PCI DSS compliance and spaghetti code, Part 3

(Be sure to read Part 1 and Part 2 first!) When writing new code I find its a good idea to start at your integration point and then write that client code, whether just by psuedo-coding or writing some test cases. For my payment gateway code I need code that … Read full article

PCI DSS compliance and spaghetti code, Part 2

(Be sure to read Part 1 first!) The first iteration of my Command objects could continue to use our existing payment gateway code, but this would not be acceptable by the end of this project. This old payment gateway code relied heavily on global state to get configuration options and … Read full article

PCI DSS compliance and spaghetti code, Part 1

Anyone taking a substantial amount of credit card payments will eventually stumble onto the Payment Card Industry Data Security Standard (PCI DSS). Meeting this standard likely adds significant complexity to your application, comes at fairly great expense, and will leave your developers and sysadmins with at least a few head-scratching … Read full article

Exceptions as part of "regular" control flow

I've heard this rule a lot: "Never use exception for control flow." Its an interesting statement to parse. We know what an exception is, but the definition of control flow is a little fuzzy, so lets clarify things a bit. In computer science, control flow (or alternatively, flow of control … Read full article

Exceptions vs Null

Plenty of developers agree that returning mixed-type results is not a good practice. It leads to conditional statements wherever the method returning the result is used. Everbody agrees thats bad, and then Null walks in, and we're not sure anymore. Null is suppose to be magical value which can passed … Read full article

Durable, readable tests

Anyone who has written tests is familiar with our friend the setUp() fixture method. We use setUp() to do all that work that's common across all our tests. It can be used to reduce repetition within our tests, making them simpler, and more readable. Unfortunately testing can get a little … Read full article

Code smell: Too many private methods

I mentioned this in my last post so I figured I'd add some examples to clarify. Consider the following code: class Cache { public function set($key, $data) { if($this->_useMemcache()) { $this->_setInMemcache($key, $data); } elseif($this->_useFilesystem()) { $this->_setInFilesystem($key, $data); } else { $this->_setInMemory($key, $data); } } } Its part of a … Read full article