Using cfscript to write methods in CFC

Using cfscript to write methods in CFC

Post by yoh200 » Fri, 11 Feb 2005 09:20:19



Hi,
 what is the advantage of writing methods in component using cfscript e.g:

 <cfcomponent hint="Comp">
 <script>
    function test (a, b) {
      return a*b;
    }
 </script>
 </cfcomponent>

 and:
 <cfcomponent hint="Comp">

    <cffunction name="test">
      <cfargument name="a" type="integer">
      <cfargument name="b" type="integer">

      <cfreturn
    </cffunction>
 </script>
 </cfcomponent>

 </script>

 
 
 

Using cfscript to write methods in CFC

Post by yoh200 » Fri, 11 Feb 2005 09:34:38


Hi,
 what is the advantage(performance wise) of writing methods in component using
cfscript e.g:

 <cfcomponent hint="Example1">
 <script>
    function test (a, b) {
      c = a*b;
      return c;
    }
 </script>
 </cfcomponent>

 and:

 <cfcomponent hint="Example2">
    <cffunction name="test">
      <cfargument name="a" type="integer">
      <cfargument name="b" type="integer">
       <cfset c = a*b>
      <cfreturn c>
    </cffunction>
 </cfcomponent>

 and caller page (make sure it works):
 <cfscript>
        objExample1 = CreateObject("Component", "Example1");
        objExample2 = CreateObject("Component", "Example2");
 </cfscript>

 Using cffunction and cfargument clearly better for defining the datatype of a
and b which is integer where in cfscript: input params a, b in this case are
treated as variant (?) or something else in coldfusion rather than a as
integer, b as integer.
 Writing with cfscript sometime is easier without tags involved.
 Any idea of these two ways? the best way to do it specially in huge method
with lots of logic and input params involved.
 Or any comments?

 Thanks

 
 
 

Using cfscript to write methods in CFC

Post by Fug » Fri, 11 Feb 2005 12:02:41


When I was first introduced to ColdFusion (4.5/5), I was told that CFSCRIPT
offered better performance that tag code.

 With 6+, as everything gets compiled to java byte code anyway, I havn't
noticed any real performance difference between tag and script code. The most
noticable performance gains were through improving the logic of the code, and
in more efficient use of data structures and database calls.

 My advice is to use what suits the purpose - if the code is logic heavy, and
it would be easier to write in scripts than tags, then do so. If you are more
comfortable with tags, then do it that way.

 
 
 

Using cfscript to write methods in CFC

Post by Mike Nime » Sat, 12 Feb 2005 00:32:55


Writing the functions as tags allow you to do more. Using tags, you can
control the access privileges and you can define the individual arguments.

---nimer


Quote:> Hi,
> what is the advantage(performance wise) of writing methods in component
> using
> cfscript e.g:

> <cfcomponent hint="Example1">
> <script>
>    function test (a, b) {
>      c = a*b;
>      return c;
>    }
> </script>
> </cfcomponent>

> and:

> <cfcomponent hint="Example2">
>    <cffunction name="test">
>      <cfargument name="a" type="integer">
>      <cfargument name="b" type="integer">
>       <cfset c = a*b>
>      <cfreturn c>
>    </cffunction>
> </cfcomponent>

> and caller page (make sure it works):
> <cfscript>
>  objExample1 = CreateObject("Component", "Example1");
>  objExample2 = CreateObject("Component", "Example2");
> </cfscript>

> Using cffunction and cfargument clearly better for defining the datatype
> of a
> and b which is integer where in cfscript: input params a, b in this case
> are
> treated as variant (?) or something else in coldfusion rather than a as
> integer, b as integer.
> Writing with cfscript sometime is easier without tags involved.
> Any idea of these two ways? the best way to do it specially in huge method
> with lots of logic and input params involved.
> Or any comments?

> Thanks