Coldfront Labs

08/03/2010 - story

Drupal Quick Tip #10: Avoid critical errors when demoing development code

Inevitably during your development process, the client is going to want to see how things are going. And typically in these cases you don't want to demo on the actual development environment. So you setup a test site to demo everything which may or may not contain all those lovely Drupal development modules (i.e. coder, devel, etc...). And if that's true, what if there are stray 'dsm' calls in your committed code? I mean it's safe to assume you grabbed a copy from your repo which is still under active development so it's safe to assume there's some dev code in there. And that code will cause critical errors with those dev modules missing. The last thing you want is to show big error pages during a demo!

Now I know this is a lot of if's but it could happen (trust me...). Here's how to avoid it:

What you'll need: Your fingers and cooperative developers

How to do it: Anytime development code is committed to your repository, get your devs to wrap any development function calls in a ternary operator with the 'function_exists' function call.

Example:

  1. function_exists('dsm') ? dsm($node) : '';

Now if 'dsm' is missing, your code will execute just fine. But don't leave all those 'function_exists' calls in your production copies since they do slow down the PHP execution (especially if you've got a lot of them). But it can save you some embarrassment during early demos.

Until next time!

Latest Tweets

  • #dcsf picture time! 19 weeks 4 days ago
  • What kind of team building stuff do you do remotely? (since not everyone is local) #magicteams 19 weeks 4 days ago
  • Really enjoying Drupalcon, learning so much! Need time to digest the info....and the awesome food! 19 weeks 5 days ago
  • Holy crap! http://tinyurl.com/yycqls6 Live NHL games on Boxee :-D #iamcanadian 19 weeks 6 days ago
  • Just getting to my second session at #dcsf and I've already lost my pen :-S 19 weeks 6 days ago

Poll

Do you plan on switching to Drupal 7 when it's released?:
Copyright © 2010