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 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?

Related Posts
  • Code
    Web Development
    PHPStorm: When the IDE Really MattersPhpstorm preview
    The IDE that you choose to use day in and day out, can make a big difference in your web dev workflow. PHPStorm offers many wonderful features to improve this process, let's take a look!Read More…
  • Code
    Web Development
    Test Code Coverage: From Myth to RealityXdebug wide retina preview
    Learn the myths about test code coverage and how to use it to analyze how much of your production code has been tested.Read More…
  • Code
    Web Development
    Testing Your Ruby Code With Guard, RSpec & PryRuby wideretina preview
    Learn the basics of test-driven development in Ruby along with many common web development tools such as Guard, RSpec, and Pry, among others. Read More…
  • Code
    Creative Coding
    Creating a TextMate Bundle to Easily Package Your WordPress ProjectTextmate bundle 400
    If you've developed a WordPress theme or plugin, then you know how fast your codebase can grow in just a short amount of time. You start off with just a few PHP, JavaScript and CSS files. Then you find yourself creating image assets and adding them to your codebase together with their Photoshop file counterparts. After a while you'll be including other third-party PHP libraries as well. Then when you're finally ready to ship your WordPress project, you'll end up having a web of multiple file types like *.php, *.css, *.scss, *.js, *.min.js, *.png and *.psd, maybe you'll have some hidden files like .DS_Store. You would eventually need to clean your codebase up before zipping them all up for your users. Normally, this just means that you duplicate your files, then scan each and every directory deleting all the unwanted files. You'd then archive your project then perhaps use a third party app to remove the hidden files. This article will teach you on how to automate this packaging process by building a TextMate Bundle that would do everything for us with a single shortcut key. [tip]This article teaches about some tips regarding TextMate, an awesome code editor for Macs. You can find more information on TextMate from MacroMate's website[/tip]Read More…
  • Code
    Interview With Jeffrey WayJeffrey way retina preview
    If you've been reading this site for awhile, then you know who Jeffrey Way is. He's the man, the myth and the legend behind the stellar growth of Nettuts+ and an influential voice in the web development community. And now he's tackling online education full steam via Tuts+. We wanted to catchup with Jeffrey to see how his next great adventure is going. Let's check it out.Read More…
  • Code
    What Are You Using? - Nettuts+ Authors EditionCsaba
    I previously asked several top developers the following four simple questions: What's your primary development focus? What hardware are you using for development? Which editor or IDE do you use? What software can you not live without on a daily basis? The article generated a lot of interest and discussion about the tools the community is using which was really great! We love to motivate discussions with our topics. Well, this also motivated us to ask the question, "Why don't we post about what we, the Nettuts+ authors use every day?" So we did just that. We chose ten Nettuts+ authors and asked them the same four questions. And like before, you'll find the answers they gave below and hopefully discover some tools that could make your development much easier. Read More…