PHP in Action Rotating Header Image

Posts under ‘Clean code’

Bad code is good for you?

Image by Balakov via Flickr

In The importance of bad code (or, WordPress and why I am a psychic), Marco Tabini proposes the idea that we need bad code. Or at least that we should be tolerant of bad code in open source projects because that invites participants that might otherwise not contribute.
This is an interesting [...]

Don’t refactor without unit tests

Image by niallkennedy via Flickr

Brandon Savage is writing a series on code improvement using a code example (starting with Peer Review: Taking Code And Making It Better). In other words, it’s about refactoring, which is practically my favorite subject. Although I don’t agree with all of it, it’s mostly good advice. I recommend it.
That said, [...]

Real programming with PHP 5.3 (part 3): Links

Image via Wikipedia

After the previous post in this series, additional independent implementations of the idea of JavaScript-style classes have turned up. So I’m going to list them and comment briefly on the differences. I hope this will be helpful to anyone who actually wants to use this in practice and needs to decide on the [...]

One behavior != one assertion

Image by libbyrosof via Flickr

The debate on the “one assertion” principle continues. Pádraic Brady and I agree on the general principle, but since he is so categorical in his second article, I needed to inspect his reasoning more closely. It’s clear that our disagreement is more than superficial. The more I think about it, the [...]

One assertion per test—always?

Image via Wikipedia

Pádraic Brady pleads for the principle that a unit test method should have only one assertion. His point is perfectly valid; there are several good reasons why one assertion per method is a smart guideline when writing unit tests. But since he drags up the term “lazy”, I feel the need for soul-searching [...]

Smart return values

Image by cackhanded via Flickr

Davey Shafik discusses return values from functions. In the specific case of a function that returns values from a database, he wants to return false on error and an empty array if the data set is empty. He also has a reason for that:
“However, it’s very rare that I care about [...]