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:
- ... 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 :)
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 :)
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.
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.
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.
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.
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.
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.
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.
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.
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.
HoW aBoUt AlTeRnAtInG cAsE? iT mAkEs YoUr CoDe RuN fAsTeR iF yOu HaVe An Ac PoWeR sUpPlY! ;-)
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.
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...
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.
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="firstname.lastname@example.org" to="email@example.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.
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.
Hello mate,check this,it is just another post on Coldfusion,recently i found many people are talking about cold fusion.