The Magic of 1

Yesterday I was doing some training and my student asked me to explain the logic behind this code:

<cfif 1> <cfdump var="#dharma#"> </cfif>

It was something so obvious to me that it never occurred to me that it may be confusing, and looking at it with a fresh eye I can definitely see it doesn't make much sense. Here is the method behind my madness...

Laziness. We've all had cases where we are working on a page and we need to quickly add some debug code to a page. Typically we just type it in like so:

<cfdump var="#dharma#">

Then if we want to hide it, but we know we aren't quite done yet, we replace it with this:

<!--- <cfdump var="#dharma#"> --->

So now to go back and forth we can add and remove the CFML comments. Well I'm lazy. I pride myself on my laziness. I don't want to have to add/remove CFML comments. Plus I tend to typo that particular set of code. So I will often use the cfif 1 code instead. When I want to hide it, I switch to:

<cfif 0> <cfdump var="#dharma#"> </cfif>

In case folks don't get what the 1 and 0 means, they are shorthand for true and false. ColdFusion considers any non-zero number to be true.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA