Chatting With The Grumpy PHP Programmer

Chatting With The Grumpy PHP Programmer

This entry is part 10 of 12 in the Test-Driven PHP Session
« PreviousNext »

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: tdd
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://twitter.com/asad Asad

    While it was really difficult to learn tdd along with development while I was going through one of the dev academies, I’m glad I was exposed to it. There are a number of positions out there that require people to be able to tdd or have some understanding of how to tdd and it helped me be prepared for those. Also, I think it helped me conceptualize programming better, because I was forced to be able to isolate pieces of my code and make sure they individually did what they were supposed to.

  • http://brianswebdesign.com Brian Temecula

    You guys have officially burnt me out with all these TDD posts. Please do something else. For a while you guys had some good CodeIgniter, Fuel, and Laravel posts, and lately its TDD TDD TDD. Maybe if you need to do more TDD you should have tdd.tutsplus.com?

    • kankaro

      Chill it out… there just explaining there opinion of how important TDD is. We should be thankful that nettuts+ covers it here. :D

    • Alchemication

      Heh, that’s some grumpy comment…

    • ian

      The reason they are doing php tdd posts is because plenty of people asked for it. Some of use could use these tutorials.

      • http://www.jeffrey-way.com Jeffrey Way
        Author

        Besides – we’re just about done with the session.

    • Jesus Bejarano

      Por gente como este tipo es que la comunidad de PHP esta tan rayada.

    • Fratyr

      Damn I so agree with you. I’m pretty new here, started with some interesting advanced topics, but then when I use their internal search for something that interests me – I get only TDD results… TDD, Agile, Unit testing… Come on Nettuts! You might be attracting all kind of hipsters that love to trash talk about all this new trends, but you can lose some seniors here that do not follow your agitation to use this and that. Be more liberal please.

  • Sergey

    TDD is a very big topic, and I’m glad nettuts are dedicating more posts on it. Please keep it up.

    • begs

      yes that’s true. keep ‘em comin :)

    • Willian

      I totally agree! Let’s TDD!

  • http://codeception.com Davert

    Yep, TDD is must have trend for PHP. Because anyone thinks it’s unimportant we get shitty software and myth that PHP developers are not following the common quality standards.

    In my opinion, the problem is: no one really needs to start with TDD. Before testing classes, you need to test that your application simply works on common scenarios: login, registration, user update, material publish, etc. That’s functional and acceptance testing, not unit.

    For those cases I recomment to start with Codeception or Behat – they are cool with acceptance testing. When you really understand the need of unit testing – use it. But not do TDD, just because anyone says it’s cool.

  • http://defaulttricks.com Mohit Bumb

    hahaha lol

  • hokus

    php is a programming language? From when…?

    • mpmedia

      from when you stopped using it , you were a disgrace to the language…
      Php is a scripting langage just like ruby ,perl or python. it’s very close to c/c++ , that’s why most of high level langage developpers hate it, they cant handle the low level stuf.

      • Cutlas

        +1

  • nrauni

    very nice questions and anwers!

  • http://twitter.com/Nick_Johnsn Nick Johnson

    Its nice to read interview of a ” Grumpy PHP Programmer ” …… Some very nice questions and interesting answers, came out in this article…..