Testing and Debugging the easy way: The debug flag

Setting and accomodating for a debug flag is one of the easiest ways to turn your script or application into "debug mode". One such method is to allow for a dedicated query string parameter, say debug, where in it's presence, your script runs in "debug mode".

Using a ColdFusion example, let's say we want to alter the conditions of a query based on the presence or lack-of the query string debug parameter. The example query selects a list of all users in a database table, in preparation for a mass email. In this situation, a system for simple debugging is crucial.

<cfquery name="users">
    SELECT fname, lname, email
    FROM user
    <cfif isDefined("url.debug")>WHERE email = '[email protected]'</cfif>

Now, all code in your script, which depends on the users recordset, will only be referencing the "debug" version of the query.

Why follow me on Twitter?

  • I tweet about new technologies, services or libraries I find interesting
  • Yeah, sometimes I'll post a pet-peeve or rant about something trivial
  • If I discover something that made my web development life easier, I share it
  • I'll shout out any handy tip that I think might be useful to other devs

Tagged .

Updated: 2012-04-16

Phil LaNasa follow us in feedly