This is the second installment of a 6 part series. All sections will help to introduce you to some basic programming concepts that will all carry through and help you as you learn ColdFusion. If you are looking for any of the other installments to this series, you can get to them below.
- What is Programming?
- Proper Syntax
- Variables and Data Types
- Conditional Processing
- Arrays and Structures
- Modular Code
All programming languages use source code to create a set of instructions. Source code must follow a proper syntax to be read correctly by the application that is processing (reading) it. Let’s go take a look and see what Wiki has to say about it.
In computer science, the syntax of a computer language is the set of rules that defines the combinations of symbols that are considered to be a correctly structured document or fragment in that language. This applies both to programming languages, where the document represents source code, and markup languages, where the document represents data.
Bleh! Way to complicated and uninteresting. When it comes to ColdFusion, proper syntax is referring to the correct usage and format of code. Programming languages are designed to take your input, process it and give you back a result. However, if you tell the application something it doesn’t understand, it can’t give you back the result you want and instead will most likely throw a nasty error your way.
Let’s take my hat example from the previous section. I have a hat and it’s red. There are several ways you could technically tell ColdFusion that the hat is red. But the way ColdFusion understands is by using one of the following syntax:
<cfset thishat = “red”> OR <cfscript> thishat = “red”; </script>
Now, if you’re wondering how we can use two different ways to tell ColdFusion that the hat is red, you’re in for a treat! ColdFusion will let you write your source code in its original tag based format or in the more programmer friendly format using more familiar coding practices. If you are new to programming in general you probably won’t see the advantage right away. So if you aren’t sure what that means, that will come later, I promise.
So what happens if we don’t use the proper syntax when talking to ColdFusion? Let’s throw ColdFusion some wrongly formatted syntax and see what it returns.
<cfset thishat = "red>
As you can see I left out the closing quote around the word “red”. This confuses ColdFusion and it doesn’t quite know what to do with it, so since it can’t be processed, it sends you a message that there is a problem. Sometimes it’s even nice enough to tell you what it didn’t understand about the issue like it has done here.
Think of programming languages as a snobby grammar nazi that will have nothing to do with you if you don’t speak his language and with proper grammar.
In summary, proper syntax is simply the right way to talk to the ColdFusion server so that it understands what you are telling it to do. Get ready for the next installment where we will learn about variables and data types.