Skip to main content
Known Participant
February 9, 2009
Question

Benefits of CFSCRIPT

  • February 9, 2009
  • 4 replies
  • 1237 views
I've only been developing in CF for about a year and a half. I haven't understood the purpose of CFSCRIPT. What are the benefits other than shorthand code?

Thanks,
Paul
    This topic has been closed for replies.

    4 replies

    Inspiring
    February 10, 2009
    > One specific advantage is if you are doing switch/case logic, with script you
    > can assign two sets of commands to the same value without having to type them
    > twice.

    Eh?

    <cfparam name="URL.word" default="">

    <cfswitch expression="#URL.word#">
    <cfcase value="ocelot,pangolin">
    Either an ocelot or a pangolin is fine<br />
    </cfcase>
    <cfcase value="marmoset">
    A marmoset is almost as good as a pangolin or an ocelot<br />
    </cfcase>
    <cfdefaultcase>
    Not interested<br />
    </cfdefaultcase>
    </cfswitch>

    <cfscript>
    switch (URL.word){

    case "ocelot":
    case "pangolin": {
    writeOutput("Either an ocelot or a pangolin is fine<br />");
    break;
    }

    case "marmoset": {
    writeOutput("A marmoset is almost as good as a pangolin or an ocelot<br
    />");
    break;
    }

    default: {
    writeOutput("Not interested<br />");
    }
    }
    </cfscript>

    --
    Adam
    Legend
    February 10, 2009
    One BIG disadvantage I have found is syntax errors. Using standard CF tags, the line and column of the offending statement will be displayed (provided you have error reporting turned on). With CFSCRIPT, you basically get a message that the block is invalid -- not helpful at all when coding or modifying a large block.
    Known Participant
    February 10, 2009
    Ok good, I'm glad that I'm not really missing out on anything. I couldn't tell of anything that was better in my general observation, but I've seen it used a lot. Thanks for all the input.

    Paul
    Inspiring
    February 10, 2009
    Easier to type, easier to read.

    One specific advantage is if you are doing switch/case logic, with script you can assign two sets of commands to the same value without having to type them twice.

    Some things are easier with tags though. looping through a list comes to mind.
    Inspiring
    February 9, 2009
    paulferree wrote:
    > What are the benefits other than shorthand code?

    That is the big one that is left.

    Back in the C++ days of ColdFusion, i.e. before ColdFusion MX in 2002,
    large blocks of cfscript code could be faster then the same amount of
    tag based CFML.

    Since the conversion to a Java based application with MX aka ColdFusion
    6, it all will render down to the same byte code so this difference is
    minuscule at best.

    That basically leaves style choice. Many developers find the cfscript
    syntax cleaner and easier to read, many do not. So the choice is yours.
    Unfortunately for the cfscript crowd there has always been processes
    that could only be done with tags, such as <cfquery...> to name one. My
    understanding is that the currently in beta testing CF 9 or Centaur
    [ http://labs.adobe.com/wiki/index.php/Centaur is hoping to close this
    gap so that anything that can be done with tags can be done with script.