Tiny Change In ColdFusion Coding Methodology

Posted August 24, 2007 at 4:26 PM

Tags: ColdFusion

I have decided that it is time to make a slight change in the way I code my ColdFusion code. For the longest time, I have written certain ColdFusion tag attributes in upper case. Here are some examples:

  • CFFile Action (ex. <cffile action="UPLOAD" />)
  • CFHttp Method (ex. <cfhttp method="GET" />
  • CFHttpParam Type (ex. <cfhttpparam type="CGI" />)
  • CFImage (ex. <cfimage action="READ" />)

Those are just a few that pop into mind at this moment. I am sure there are other places where I am doing this. I am not sure why I got into this habit, but I know that it is totally inconsistent. Why do some ColdFusion tag attributes have to be upper case while most do not? They don't! It was a poor programming choice and it's time to remedy the situation.

The exception to the rule (sort of) is going to be the ColdFusion query data types:

  • CF_SQL_INTEGER
  • CF_SQL_VARCHAR
  • ... etc....

I feel that these are OK as being uppercase because they feel more like constants than they do variables... of course, I may look up tomorrow and realize that there is no need to have ANY exceptions. After all, I already lowercase all my CGI variables (ex. CGI.http_user_agent), why keep my database types uppercase?

Exactly! Good point!

Ok, stream of consciousness... I will start making my database types lowercase as well. No more inconsistencies! No more poor programming (well, poorer than it has to be). From now on, all tag attribute values will be lowercase (unless they are variable names, in which case they should match the case of the original variable declaration).

Now, I know what some of you might be thinking: Why would I even waste my time caring about this... To which I would respond, Waste my time trying to write the most consistent code possible?.... Why aren't YOU wasting your time thinking about stuff like this :)

Post Comment  |  Ask Ben  |  Permalink  |  Other Searches  |  Print Page




Learning ColdFusion 9 - ColdFusion 9 tutorials, samples, examples, demos

Reader Comments

Aug 24, 2007 at 5:09 PM // reply »
20 Comments

99% of my code is lowercase.

i uppercase acronyms (CGI, URL, etc), and comparison operators (<cfif foo IS "bar"> ... </cfif>).

i don't know why i do the latter. it just feels good and i cant' stop :)


Aug 24, 2007 at 5:11 PM // reply »
6,516 Comments

@Charlie,

Yeah, I uppercase all my scopes (SESSION, APPLICATION, FORM, etc) and all operators (AND, OR, NOT, etc).

I think the key is that it "feels good" to you. Again, I am sure I will get some flack for this, but code should have a feeling. There should be some emotion that goes into this stuff. This is our careers - not just a job.


Aug 24, 2007 at 5:23 PM // reply »
95 Comments

why uppercase anything at all? I use camelCase for my variables names when they are made up of two words (such as "userName") but everything else (tags and attributes) is lower case. I also apply this to sql when writing database queries or stored procedures.


Aug 24, 2007 at 5:26 PM // reply »
6,516 Comments

@Boyan,

I like the way uppercased things look. I uppercase my CF tag names, but lowercase my HTML tags (for visual difference). Same with SQL directives and scopes... more visual queues in the code the less I have to think.


Aug 24, 2007 at 6:18 PM // reply »
92 Comments

Now I see the benefit of this if you are using a non color coding editor but those days are long gone. Unless you are using Notepad no need to write different case for tags. I keep it consistent and keep everything lowercase. As Charlie said I do uppercase my operators. I keep all variables, database column names, etc. in camelCase. It's easier to type and to be honest with you its a lot easier on the eyes. This comes from someone who would capitalize everything, ex. Variables.FirstName. After awhile of seeing my code against others I just didn't find that as easy on the eye so I code now like this: variables.firstName. I've noticed I type a lot faster that way since its more intuitive.


Aug 24, 2007 at 7:17 PM // reply »
17 Comments

I pretty much lowercase everything as well. Even multi-word variable names and functions, unless the words next to each other have the same end/start letters, then I'll camel case the whole thing:
i.e. "listtoarray" becomes "listToArray"

Except for some reason, I still like to use a capital "A" on application variables. Maybe it's a holdover from Application.cfm/cfc. It just looks weird to me "application.myvar", like it's not authoritative enough.

I started doing it after looking at Ray Camden's code in BlogCFC and seeing that he mostly uses all lowercase, and I just like how it looks that way. Also, it's faster to type in all lowercase.


Aug 24, 2007 at 8:07 PM // reply »
177 Comments

For the most part, I'm a Hungarian Notation/Camelhumps for functions and such. All my CF tags are lower case. My select statements are upper except for the columns, table names and where close (e.g.: SELECT blah FROM blahtable WHERE blah = 1 AND blah = 2).

Lately I've been trying to figure out if I should abandon cfscript or stick with it. I have nasty habit of mixing both in a single page / cfc / whatever.


Aug 25, 2007 at 12:07 AM // reply »
7 Comments

Just a note that you should ALWAYS be coding your HTML in lower case. That's part of the xHTML standard. Tags and attributes in lowercase, all values quoted, all tags closed (or self-closed) correctly.

Please continue.


Aug 25, 2007 at 12:23 AM // reply »
2 Comments

I use lowercase for everying except for SQL statements. I use all caps for command words in SQL (ie, SELECT id FROM foo WHERE bar IS NULL) probably because a lot of sql clients don't have syntax highlighting.

I don't tend to use camelCase though, I use underscores. I just prefer seeing user_id to userId or UserId. It is an extra character, but it is quick to identify visually.


Aug 25, 2007 at 5:03 AM // reply »
5 Comments

I upper case conditionals (AND, OR) and SQL reserved words when in SQL (SELECT, UPDATE), and cgi variables (cgi.AUTH_TYPE).

ColdFusion functions are PascalCase, and UDFs (and cffunction names) are camelCase.

Filenames are lowercase, except for Application.cfc (I no longer use Application.cfm/OnRequestEnd.cfm), and except for components, which are PascalCase.

tags and attributes are lower case.

Note: I believe it may be faster for most people to read lower/pascal/camel cases than it is for them to read UPPER CASE.


Aug 25, 2007 at 6:06 AM // reply »
15 Comments

HoW aBoUt AlTeRnAtInG cAsE? iT mAkEs YoUr CoDe RuN fAsTeR iF yOu HaVe An Ac PoWeR sUpPlY! ;-)


Aug 25, 2007 at 8:47 AM // reply »
6,516 Comments

Clearly we all have slightly different styles and other than Andy's point about XHTML compliance, there is nothing that forces us to do anything. The important thing is that you are consistent with your coding methodology. I was NOT being consistent and therefore, it was just poor choices. I will now try to be more consistent.

As far as the concerns the uppercase values are harder to read, in my code, I rarely have to read the upper case. Because the uppercase provides a visual difference, all I need to see is AP or SE or FO and my brain automatically realizes that it is APPLICATION, SESSION, or FORM (etc) and skips over it. The uppercase allows me to read the code faster because it actually allows me to skip a lot of the code using these types of visual clues.

If all of my code was camel case, (IN MY OPINION) it would be harder to read because there would be more words that I would have to evaluate as I read them.

That's what works for me - not saying it has to work for others. The KEY here is to just be consistent.


Aug 26, 2007 at 12:17 AM // reply »
97 Comments

I guess I find uppercase OPERATORS very odd-looking because I've worked for years with languages that are case sensitive with keywords for operators - so I was forced to have lowercase operators.

When my team at (then) Macromedia drew up the ColdFusion MX Coding Guidelines, we were mostly C++ and Java developers and so, for all of us, case sensitivity was a way of life and uppercase anything was just plain ugly :)

Now I'm working on a lot of code that long-term CFers have written, most with no background in other languages, and it's interesting to see how very different CFers' styles tend to be from other languages...


Aug 26, 2007 at 11:11 AM // reply »
6,516 Comments

I was originally just a computer science major in school, so I learned Q-Basic, C, C++, and a bit of Java. Granted I didn't do that stuff very long, but I don't feel like I took all that many queues from those languages when I went to HTML / Javascript / CF. Of course, had I been doing it for longer, I probably would have.

Over the years, I have tried to copy other people's styles, but something about things they did just never felt right. The formatting that I have come up with on my own just feels right (TO ME). I think it is getting very consistent and is chock full of Visual markers that allow me to understand the code at a glance.


Nov 13, 2007 at 6:47 PM // reply »
4 Comments

I love this post! Great to read about everyone's coding style preferences.

For the longest time I have always written my CF tags in uppercase, but params in lowercase.

E.G <CFMAIL from="me@me.com" to="you@you.com" subject="test">Hello you</CFMAIL>

I only did this because a developer I learnt from all those years ago did the same. However, recently I have become aware of the fantastic Coldfusion community and how many developers like to follow the Macromedia coding guidelines. While I don't agree with *everything* in them I do now appreciate that CF tags should really be in lowercase.

I must admit that whenever I saw CF code in lowercase it just looked, well, messy! Strange how we get used to the style we develop in. I have recently starting training myself to code in lowercase and I must admit it does feel better - quicker to type and almost more professional (though I know that it mainly mental).

I also *love* camelcase. It's just nice to have a methodology for naming variables. I used to be so inconsistent in how I named variables, mainly because I didn't really have a method to rely on.

I still code up SQL statements in uppercase though. They just don't look right all in lowercase and I really do find them harder to read.

E.G

SELECT * FROM Content
WHERE PageTitle = 'Test'

I have to say that I don't agree with taking CF function names and camelcasing them though. I believe you should specify the functions in the case the CF documentation specifies.

Therefore ListToArray() should be written that way, not: listToArray().

Again though, it really is personal preference at the end of the day.


Jan 9, 2008 at 3:58 AM // reply »
4 Comments

Hello mate,check this,it is just another post on Coldfusion,recently i found many people are talking about cold fusion.

Click here: http://www.forta.com/blog/index.cfm/2007/4/27/On-Posting-Job-Listings


Post Comment  |  Ask Ben

Recent Blog Comments
Nov 21, 2009 at 11:03 AM
Groovy Operator Overloading Does Not Work In The ColdFusion Context
Hi Ben, Thanks for this informative post. Now I am reading ur old posts too ... read »
Nov 21, 2009 at 10:56 AM
HostMySite.com Has The Best ColdFusion Hosting
@Mehul, Yes very nice people, however several downtimes per day which was not acceptable. Hence we had to move out. I am glad you are having good luck with them so far. ... read »
Nov 20, 2009 at 11:32 PM
Five Months Without Hungarian Notation And I'm Loving It
I've used headless camel case for years for not only ColdFusion variables, but also SQL tables and fields... pretty much everything involving code. I also subscribe to the "don't abbreviate and clea ... read »
Nov 20, 2009 at 11:00 PM
Five Months Without Hungarian Notation And I'm Loving It
@Marcel, Yeah, I always err on the side of longer but more readable variable names. As for the camel casing of CF methods and the headless camel casing of custom items, I get around this by always ... read »
Nov 20, 2009 at 10:56 PM
Five Months Without Hungarian Notation And I'm Loving It
I use the following and love it: my.namespace.MyComponents.functionMethodsOrUDF() CONSTANT_VALUES_OR_PROPERTIES One thing I always try is to CamelCaseBuiltInColdFusionFunctions() so others can tell ... read »
Nov 20, 2009 at 5:38 PM
Learning ColdFusion 8: CFImage Part I - Reading And Writing Images
Hi Ben, Great article. I've been looking around to see if ColdFusion image engine can programatically create the following "wrap around" effect: http://www.creativepro.com/article/photoshop-s-she ... read »
Nov 20, 2009 at 5:35 PM
Maintaining ColdFusion Sessions Across SMS Text Message Requests Without Cookies
@Dave: I talked to Gert he suggested: <cfhttp method="get" url="http://{some cf website}" result="stuff" addtoken="yes" /> Note the addition of cfhttp attribute addtoken. That should persist y ... read »