Is there a difference between these ColdFusion components?

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

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> 
+4
source share
4 answers

Not particularly.

Version 3 full tags will be backward compatible with ColdFusion 8 and open source versions of ColdFusion, for example. Railo or OpenBD.

Version 2 is neither one nor the other.

Version 1 is the full version of the ColdFusion 9 script.

I would recommend that you choose between the first and latest versions and stick to it. Version 2 is not backward compatible with coldfusion 8 and is neither a tag nor a script. Such coding will be quickly confused.

+5
source

If you plan to write everything in a script, then Example 1 is the way to go.

You can do anything in the script you want, and if something is missing, you can write cfc, which will implement the missing functionality, and then call it using the new syntax.

If your source code starts with a new code base, I would try to avoid all the tags, so option 1.

+2
source

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

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

e.g. 1: 64

e.g. 2: 100

e.g. 3: 129

If you are using Adobe CF9, go with option 1. This is much more concise. Currently, you can do everything in <cfscript> .

If you want to check the compiled bytecode for each, enable saving .class files in your cf-admin and view the files in the / Classes directory using the decompiler. eg. Jd-gui

+2
source

Cfscript is probably a little faster and more compatible with other languages, while the approach is simpler (more hides complexity) and more.

CF began as a language based and developed to include a complete scripting style alternative to the approach.

Differences are a matter of developer style.

+1
source

Source: https://habr.com/ru/post/1389946/


All Articles