I am reposting this from my blog ("ColdFusion 11: cfclient ports a lot of CFML functions to JS") at the suggestion of Adobe support:
I have edited this in places to remove language that will be deemed inappropriate by the censors here. Changes I have made are in [square brackets]. The forums software here has broken some of the styling, but so be it. There are comments back against the original article - linked to above - which are worth reading too.
A few days ago I wrote my first
<cfclient> hello world (or in my case "G'day World") example. I'm not compiling it to a mobile app as I'm not really testing the ColdFusion Builder app packagings stuff (I simply don't care about that), I'm only interested in how
<cfclient> performs / works in the context of a tag in the CFML language. See this article for more on that: "ColdFusion 11:
<cfclient> in the context of the CFML language, not the tooling".
One thing I noticed in my "G'day World" code, is that to output those 11 bytes on the screen,
<cfclient> loads around 128kB of data, in the form of various tracts of line code and external libraries. Describing this as "egregious" is an understatement.
One of the libraries particularly caught my interest, as it's called "cffunctions.js", and - as the name suggests - contains a port of alla lot of CFML's built-in functions to JS.
My first observation is its inclusion is completely unnecessary as I'm not using any functions in my code, and it would be reasonable to think that the
<cfclient> CFML to JS compiler might notice that and save people a download. Secondly... it's a single, monolithic 106kB file. Let's have a look at it:
Observations I will make:
- as I said above: including this file when it's not necessary seems wrong.
- Every single function is just slapped into one huge file. This to me seems equivalent to having a CFC called AllMyCode.cfc, containing... everything, including kitchen sinks and family pets.
- Connected to that: the functions are all declared straight in the global scope, which seems a bit "pollute-y" to me. I can't help but think they ought to be grouped together in a CF namespace, within that some sort of type-centric namespace like
- A lot of the code seems rather "longhand", eg:
someVar = SomeVar+1instead of perhaps
someVar++; using an indexed
for()loop to loop over arrays etc.
- The file's not minified: this would almost halve its size. I dunno if this is such a consideration these days with responses being GZipped?
Is there anything else you've spotted?
I might sound a bit nit-picky here (hey: it would not be the first time, and someone needs to ask these questions), but equally if I want someone writing a wizard to write my JS for me, then I want to know that person actually knows what they're doing. And if I can raise code-quality questions... I suspect the answer is I don't want this person writing my JS for me.
But I completely accept that perhaps there's not an issue to answer here... this article is more soliciting other - more expert - people's opinions.
What do you think?