Beyond Clean Code

This is the fourth post in my “Beyond” series. The previous three posts focused on re-imagining OOP and questioning some of the core beliefs that we have come to take for granted. This one is going to be slightly different, in that I want to talk about another angle of writing code: the process itself. We always talk about how code should be clean, but how do you write clean code?

On Templating

I’ve been playing around with tempting engines a lot lately. For a recent project, I needed the ability to re-use the same template set in both JS and PHP (coupled with the History API, providing seamless dynamic behavior, yet still having raw content pages). Realistically today, there’s only one choice for that sort of requirement: Mustache. I’ve learned a lot while playing with Mustache, and it’s really changed my entire viewpoint on presentation layer construction.

Unit Testing When You Have File-System Interaction

While working on testing out my new Cryptography library (appropriately called PHP-CryptLib), I ran into a rather interesting problem. How do you unit test a method that interacts with the file-system? Traditionally, this problem has been solved by either not testing the method or creating temporary directory structures, testing, and then deleting the temporary directories. There has to be a better way. And as it turns out there is!