Chatting With The Grumpy PHP Programmer

I recently had the chance to catch up with Chris Hartjes, or, as some of you may know him, ""The Grumpy Programmer." Because he recently released a new ebook on test-driven development in PHP, I wanted to pick his brain a bit!


Q You're widely known as "The Grumpy Programmer." How'd this title come about?

I'm not really that grumpy in real life. Okay, maybe a little.

While I am pretty grumpy when sitting in front of a computer coding, "The Grumpy Programmer" is more of a brand; a marketing tool more than anything else. As I gained experience as a programmer, I wanted to share my ideas to help other people and myself at the same time. I felt one of the ways to make that happen was to build up my own personal brand, hence the birth of The Grumpy Programmer.

Of course, you need to have some skills to back yourself when you start playing what is essentially a cartoon version of yourself online. I wouldn't be yelling so loudly about all this testing stuff if I didn't actually know how to do it.

I'm not really that grumpy in real life. Okay, maybe a little.


Q You recently self-published "The Grumpy Programmer's Guide to Building Testable Applications." What made you want to write this specific title?

The Grumpy Programmer's Guide to Building Testable Applications

As I dug deeper into the world of testing in PHP, I discovered that what was missing was information on how to actually write code that you could test. There is plenty of stuff out there on how to write tests, but that stuff doesn't matter if your application is a mess.

Writing code that is decoupled and allows you to inject dependencies into it isn't particularly hard, it just takes time and discipline. Those things are in short supply in the programming world these days.


Q Why do you think that TDD, in general, hasn't become as ubiquitous in the PHP community as it has in other languages, like Ruby and Python? Do you think that's beginning to change?

"I don't have time to test" is a refrain spoken by the vast majority of programmers in the PHP world.

Python programmers care about how their code looks and the Zen of Python is written right into the interpreter.

Rubyists have been exposed to the concept of test-driven development since the first release of Ruby on Rails.

PHP still lets you smash your request handling, database access and HTML output into one file that can be deployed in more environments than all other language combined.

I think it's pretty obvious why TDD is still a hard sell in PHP.

"I don't have time to test" is a refrain spoken by the vast majority of programmers in the PHP world. I guess they have time to work late nights debugging their applications instead of catching those problems earlier. It is getting better, though. Every major PHP framework has comprehensive test suites, and every day I hear from someone on Twitter that they have started writing tests for their PHP code. That makes me feel good.


Q In your opinion, what is the single biggest advantage to testing your applications?

I test my applications so I know they are working correctly instead of guessing (or hoping) they are working correctly.


Q Do you exclusively use PHPUnit, or do you prefer some of the smaller alternatives, such as Behat?

I use PHPUnit for writing unit tests and Behat (along with Mink and various web browser drivers) for user acceptance tests.

There are some other unit / integration / functional testing tools out there, but PHPUnit is my preferred tool because so many other tools integrate with it really well.


Q Testing applications is a bit odd, in that, overall, the idea is a simple one. Ironically, though, getting started with it requires a fairly steep learning curve. Was there a specific article or video that suddenly made you "get" it all those years ago?

I've been poking around the edges of testing code since 2003. When I saw SimpleTest and was introduced to TDD, something in my head clicked and I understood the value of these practices.

Being a testing evangelist is a lonely, frustrating job. People don't realize the value of tests until they have them in place and see how easy it was to add some new functionality and discover they broke something else before their customers found out.


Q Would you recommend that newcomers to the development world dive into testing, or wait a while before learning how to do it? I think there's merit to both arguments. Perhaps, if you sneak the "medicine into the dogfood" from the start, they won't have any concept of never not testing their applications!

I think that you can teach someone programming using TDD, but PHP might not be the best tool for that. The lack of a good built-in Read-Evaluate-Print Loop (REPL) means there is a lot more setup work required to create an environment for people to write and run tests in.

Python and Ruby, having not been born on the web, make it a lot easier to import modules that handle testing and experiment on the command line.


Q What are your thoughts on the vitriol toward PHP lately - referring to various viral blog posts on the subject? Is it warranted?

Every language sucks in their own way. Don't like PHP? Don't use it. Don't work at places that use it. Use languages and tools that resonate with you.

The people I admire in the world of programming use multiple languages and multiple tools as they are invested in solving problems, not wearing their language preference like a cheap tattoo.


Q Where can we go to keep up with what's new from you?

Of course, I encourage people to buy a copy of my book, which is available at http://grumpy-testing.com. I am currently contemplating an all-new second edition of the book, or a book on how to use PHPUnit and Behat to test your PHP applications. Maybe I will combine the two!

If you like to be entertained, I suggest you follow me on Twitter. Also, I blog here.


Thanks again to Chris for chatting with us. So, now, it's over to you, John Q. Reader. What are your thoughts on testing? A requirement for web application development, or an over-hyped time waster?

Tags:

Comments

Related Articles