Saturday, July 19, 2014

CFScript vs CFTag

I started out by only coding CFML in tags, being self-taught I had to go by what people were using to show how to do basic things, as I progressed I learned how to expand on that knowledge, but kept working in tags because, well, that's what I was used to.

I've looked into CFScript in the past, but didn't really start practicing until more recently (A few months ago), writing new CFCs in script and taking the opportunity to practice my cfscript-fu while updating old code.

I saw Adam Camerons post about him helping someone convert old tag-based code into cfscript, and it made me think (And ask) "Why is cfscript better?"

After many messages between me and Adam Cameron, and between me an Sean Corfield (Both are programmers I highly recommend following on blogs and twitter), I'm *still* not sure what's so great about cfscript compared to cftags.

Ps. I hate twitter for discussions.

Neither Adam nor Sean can, in my not-always-so-humble-opinion tell me in simple terms what's so great about cfscript.

It seems to boil down to personal choice (Unless you ask Sean, who will tell you what an evil man you are for using tags. Not a direct quote.)

Check out Adams blogpost about script vs tags, it's an interesting read and he has a different take on it than I do.

I'm always looking to improve my skillset, because programming is awesomely fun   :)

I'm now coding in both tags and script, mostly writing new CFCs in cfscript, because it means I'm learning new stuff, while adding useful skills to my skillset, learning cfscript was natural to do because it's used all over the place, and a lot of shops and companies use it to a varying extent.

Overall, I don't know of any inherent benefits to using cfscript, while it sometimes *feels* like it's executing faster than tagbased code, that's not exactly empirical proof, I've yet to find any *real and proven* benefits to cfscript in terms of performance.

It's been debated that it's better to use cfscript because it's closer to other languages, since CFML is the only tag-based language around.

Personally I don't find it very beneficial to know a language similar to a new one, and I still think of cftags and cfscript as just two different syntax-sets to the same language.

Sean thinks it's harder for someone to learn any other real language, coming from CFML tags, and noted it as a reason for not hiring someone.

I agree, but only if the person *only* knows CFML tags and nothing else..

But I don't know any web developer who don't also speak at least JS, so right there that argument fall, unless he's ever looked to hire someone who *only* speaks CFML, and literally nothing else.

From what I know there is nothing available in CFScript that isn't available in CFTags, and vice versa, there isn't any performance gain to either.

It seems that many people feel that tags are too close to html, being inside of <>, and should thus not be anywhere near business logic

I do find it amusing that CFML = ColdFusion Markup Language, which is only sortof true after the introduction of CFScript.

I'm not "defending" the use of tags, again I code in both, I just wanted to see if anyone could give me actual, specific reasons why cfscript is better than tags, and so far... I haven't seen it.

I'm filing this under "Personal preference", maybe some day I'll have that Aha-moment when working with script and write a post about it.

9 comments:

  1. A note to readers: I cover all this in my own article (linked-to above).

    I didn't set out to describe what's so great about CFScript because it's a specious position to take from the outset. But this is perhaps why I did not explain it to Marcus's satisfaction: that I never attempted to.

    --
    Adam

    ReplyDelete
    Replies
    1. Could be, but you wrote a really neat blogpost as a result, with lots of good info, so it's a win in my book.

      I always find it interesting to see other peoples viewpoints, it helps give perspective to my own.

      Delete
  2. I too am more comfortable with tags, as I am also pretty much self-taught. But I've been making the effort to write CFCs in script. I don't think there's that much of a difference in performance between tag-based code and script code. The real benefit is that script code is generally more readable and concise. Since the ratio of reading existing code to writing/revising code is something like 10:1, code written in script saves time and mental energy.

    ReplyDelete
  3. It pretty much is personal preference. You can build the exact same application in CFML or CFScript and noone would know. The more I've used script though the more I like it. It has less "noise" to type and doesn't seem as clumsy on the screen for reading. It just feels more lightweight and I love stuff like fo( var in vars) loops, etc.

    I think a lot of the knee-jerk reaction you get from the staunch script people in the community are that they are a little embarrassed by tags because no other language does it and people make fun of CF for it. So, there is an argument to be made that if we all started using script (Most non-CF devs don't even know it _exists_) then we'll all be taken a bit more seriously and attract other "script" programmers.

    So, it's sort of two-fold. The preference of what you want to type, and the image of CF that is portrayed that may or may not hurt the platform based on what it causes other people to think. Personally, script is one of the first things I tell people about CF-- not because it really matters, but because I know their first response will be "ewww, tags! No thanks!"

    ReplyDelete
    Replies
    1. One of the things that gets me about the whole Tags vs Script is that it's a one-to-one conversion, it's literally the same language in two implementations, it's not like one does a lot more or a lot better, just different.

      Yeah I got the feeling that there are people who go with script just because it "feels" like a more "real" language without all the <> but to me that's just syntax.

      Delete
  4. I second what Brad said. There really is no significant performance difference between tags and script. Its really down to personal choice in most cases, so don't worry too much about the knee jerk reactions to using tags right now.

    However I will add the caveat that you can't use function expressions in tag based ColdFusion cfml. You can in railo, but I don't think it makes for very readable code.

    At the moment I use tags exclusively but that is mostly because we are still working off an old codebase which we are focused on making Railo compatible. Once we are on Railo I see us slowly making the switch to script.

    ReplyDelete
  5. I still prefer writing DAO in cfml because of the beauty of cfquery over new Query() in CF10, but executeQuery() may win my over in CF11.

    Other than that, cfscript is just better because there are less typing of cfset, and closure is only available in cfscript.

    ReplyDelete
  6. Marcus, this is always an interesting debate. Haing grown up back in the days with CFML when there was only tags, I can say that being self taught as well, doesn't change what Adam stated when it comes to career prospects.

    Now I am not going to back either here, as I already have my preferred way of doing it, as with most of everyone else here as well.

    But JSP (Java Server Pages) or something like that, was the same a ASP and ASP.Net, when in those days mixing tags and syntax was the norm. Since then that has evolved into the language it is today, although I still don't use the ASP.Net side of it any more even its MVC side is much superior and in somewhat much different in the way it used to work as well.

    ColdFusion has matured and continues to mature over time, some of the best projects I have worked on have been purely 100% script, except when it comes to views in my Applications where I use tags.

    The point I think we need to take away from this, which one is actually more productive. From my point of view and I would almost say that others would agree here, in that the brain can decipher things faster when there is separation, cfscript does this and it boils down to understanding the basic of ECMA script, which ColdFusion and Javascript are modeled from.

    This also allows one to pickup the language even faster, getting to grips with mixing the tags and script is a huge issue at times, especially in the older versions of ColdFusion.

    But when you have defined code blocks, mixed in with HTML tags, it is far easier for the brain to see there is a clear two code blocks here. If you have to debug and find problems in templates with a mixture of CFML tags and HTML tags. You could be getting a headache at times trying to find the problem, which script can have as well. But at least when you see two different styles you brain would be reading the CFML code if there is a problem there, rather than have to deal with both the CFML and HTML.

    But as stated by some, it is personal preference and what works for you. Just be prepared to pass over jobs if you don't or wont move over to learning and using cfscript.

    As with ASP.Net and ColdFusion 18 years is a very long time, changes have to be made and we can't live in the past all the time. Hell if ColdFusion didn't move on, we would still only every have tags that interacted with a DB after all why would I want anything else if this is a DB Language.... Now 18 years later that DB language has matured into a beautiful and easy language to learn script or no script.

    ReplyDelete
  7. Is one better than the other? If its a matter of personal preference then no. If its a matter of simplicity then again no. Is one faster than the other - doubtful unless you're using CF5 or older or if someone runs a whole series of speed tests using jMeter (for the load simulation), then cf tags are as fast as CFScript or vice versa.

    so my take on the whole thing is MEH. Its still a matter personal preference, unless someone can show proof one way or anther.

    ReplyDelete