4

I know the result is the same but is there any real difference? Maybe speed or something?

component {

 remote function getMath(){ 

    math = 2 + 2;   

    return math;
  }

}

or

<cfcomponent>

  <cfscript>

    remote function getMath(){  

        math = 2 + 2;   

        return math;
    }

  </cfscript>   

</cfcomponent>

or

<cfcomponent>

  <cffunction name="getMath" access="remote">

      <cfscript>

            math = 2 + 2;   

            return math;

      </cfscript>   

  </cffunction>             

</cfcomponent>
James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Sequenzia
  • 2,333
  • 9
  • 40
  • 59
  • This is such a confusing aspect for newcomers to the language. `cfscript` started off half-baked and if still not 100% there. We still use the tag-based syntax as it's 100% complete, I don't want to be wrapping CFCs around tag functionality as I know that at some point in the future that will be redundant after `cfscript` catches up with the tag-based syntax. – Ciaran Archer Jan 09 '12 at 09:31
  • 1
    @Ciaran Archer, I switched all my dev work to full script components a few months ago I've never looked back. I can't remember the last time I used a tag in a component, but it was probably to write a wrapper function. While CFScript is still lacking in some areas, I have not come up against many situations where it prevented me from doing my work. – Mohamad Jan 09 '12 at 13:12

4 Answers4

5

Not especially.

Version 3, full tags, will be backwards compatible with ColdFusion 8 and the open source versions of ColdFusion server eg. Railo or OpenBD.

Version 2 is neither something or nothing.

Version 1 is the full ColdFusion 9 script version.

I would recommend that you choose between the first and last versions and stick to it. Version 2 is not backwards compatible to coldfusion 8 and is neither tag nor script. Coding like this will get messy quickly.

Stephen Moretti
  • 2,442
  • 1
  • 18
  • 29
  • Thanks for the information. I want to start writing all of my components in cfscript but I know there is still some limitations to cfscript. I also want to keep everything uniform within my app so option 3 is probably the best option. I just was not sure if there was any downside to it. Thanks again. – Sequenzia Jan 08 '12 at 22:00
  • 1
    Many coldfusion bloggers say different things about which of cfscript and cfml performs best. I'm writing my components in cfscript like your version 1. Because of my more java-like background, I find the cfscript components more readable then the tag-based ones. The downside is that I have to write cfscript wrappers for tags that don't have a cfscript equivalent like . So note that not all tags have a cfscript equal. – jan Jan 09 '12 at 09:38
2

If you plan on writing everything in script, then example 1 is the way to go.

You can do anything in script that you wish, and if something is missing you can write a cfc that will implement the missing functionality and then invoke it with the new syntax.

If your starting fresh with a new codebase i'd be trying to avoid any tags all together, thus option 1.

Dale Fraser
  • 4,623
  • 7
  • 39
  • 76
2

In terms of execution speed, they all compile to the same byte code, so should be identical.

In terms of number of characters typed (excluding line breaks/tabs):

eg 1: 64

eg 2: 100

eg 3: 129

If you are running Adobe CF9, go with option 1. It's much more succinct. You can pretty much do everything in <cfscript> these days.

If you want to check the compiled byte code for each, switch on saving .class files in your cf admin and view the files in the /Classes dir with a decompiler. eg. JD-Gui

Mike Causer
  • 8,196
  • 2
  • 43
  • 63
1

The cfscript is probably a bit faster, and more consistent with other languages while the approach is simpler (hides complexity more) and more like .

CF started as a based language and has evolved to include a complete scripting style alternative to the approach.

Differences are a question of developer style.

jamesTheProgrammer
  • 1,747
  • 4
  • 22
  • 34