CFML Beginners Must Read
I have been digging through a bunch of old code for review and I would like to share some findings with you. If you are a beginner or fairly new to the CFML world this will be some good information to know. One of the very first things I notice when doing code reviews is the misuse of pound signs.
When a CMFL server encounters pound signs inside of a cfoutput tag body it will check to see if the text is either a variable or a function. If it is either it will replace the text with the result of a the variable or function. In this example we see a variable msg being set and then evaluated in the cfoutput tag body. The result on screen is Hello World.
If you try and output the variable msg and it has not yet been set you will get an error.
The real reason for this article comes into play when you are trying to evaluate a variable is some logic. Let's say I am working on an e-commerce application and I want to check the URL to see if the id of a product is a numeric Id greater than zero. I think we have all done something similar to this before.
What if you wanted wanted to check the users session to find out if the user was purchasing from USA or Canada. Again this is nothing new we could just do something like this.
The problem comes in time and time again that new CFML programmers want to wrap pound signs around these variables when using them in logical conditions. The main problem I always see is usually in some cfif statement. Taking our 2 examples from before this is usually what I will come across.
This is one of the first signs to me that you are a novice CFML programmer. This is not a bad thing so don't think I am trying to belittle you or anything it is just something you learn with experience. My plan with this article is to get you ahead of the curve a little quicker.
