Sequenzia
Sequenzia

Reputation: 2381

Is there any difference between these ColdFusion components?

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>

Upvotes: 4

Views: 709

Answers (4)

jamesTheProgrammer
jamesTheProgrammer

Reputation: 1777

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.

Upvotes: 1

Mike Causer
Mike Causer

Reputation: 8314

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

Upvotes: 2

Stephen Moretti
Stephen Moretti

Reputation: 2438

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.

Upvotes: 5

Dale Fraser
Dale Fraser

Reputation: 4758

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.

Upvotes: 2

Related Questions