len(x) better or x NEQ "" better in CFML?
I'm with Scott on this one:
<cfif len(trim(x))>
When you assign a database element to a variable, that has a "Null" value, or a single space, it will pass just the length test, the trim fixes that.
I only use just that if I'm in my own code and I'm positive that my variables have been declared. Often I'm abroad in another programmers problem however, so my test would look like:
<cfif isdefined('x') AND len(trim(x)) gt 0>
As for readability, it's not the prettiest, but it's the most thorough.
Personally, I typically use:
len( trim( x ) )
I use:
if(len("String"));
I think the code is much cleaner and as they like to say "expressive". With this syntax what you are saying with the code is "if this string has a length" do this where with the opposite your code is "saying if the length of the string is a blank string do this".
I also use ColdFusions loose boolean values for lots of things like in addition:
if(a + b){
...
}